[llvm-commits] CVS: reopt/tools/ttftest/ttftest.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Wed May 19 03:45:01 PDT 2004


Changes in directory reopt/tools/ttftest:

ttftest.cpp updated: 1.2 -> 1.3

---
Log message:

Change this tool to use the CommandLine library.
Remove the (duplicated) trace-writing code from this file.
Minor edits to comments.


---
Diffs of the changes:  (+18 -29)

Index: reopt/tools/ttftest/ttftest.cpp
diff -u reopt/tools/ttftest/ttftest.cpp:1.2 reopt/tools/ttftest/ttftest.cpp:1.3
--- reopt/tools/ttftest/ttftest.cpp:1.2	Tue May 18 11:51:30 2004
+++ reopt/tools/ttftest/ttftest.cpp	Wed May 19 03:44:44 2004
@@ -19,6 +19,7 @@
 #include "llvm/Bytecode/Reader.h"
 #include "reopt/TraceToFunction.h"
 #include "llvm/Module.h"
+#include "Support/CommandLine.h"
 #include "Support/FileUtilities.h"
 #include "Support/StringExtras.h"
 #include <iostream>
@@ -27,6 +28,13 @@
 #include <cerrno>
 using namespace llvm;
 
+namespace {
+  cl::opt<std::string> TraceFile("trace",
+    cl::desc("Name of file containing trace"), cl::value_desc("traceFileName"));
+  cl::opt<std::string> BytecodeFile("bc",
+    cl::desc("Name of file containing module"), cl::value_desc("bytecodeFileName"));
+};
+
 /// getBasicBlockByNum - Returns the basic block in F whose index is
 /// bbNum.
 ///
@@ -36,14 +44,13 @@
   return block;
 }
 
-
 /// ReadTraceFromFile - Given a module, read a trace for some function
 /// in that module from the named file. Returns the Trace object, or a null
 /// pointer (and sets ErrorStr) if there was an error.
 ///
-Trace *ReadTraceFromFile (Module *M, const char *filename,
+Trace *ReadTraceFromFile (Module *M, const std::string &filename,
                           std::string *ErrorStr) {
-  std::ifstream in (filename);
+  std::ifstream in (filename.c_str ());
   if (!in.good()) {
     if (ErrorStr)
       *ErrorStr = std::string("Can't open '") + filename + "': "
@@ -73,7 +80,6 @@
   return new Trace (vBB);
 }
 
-
 /// getBasicBlockIndex - Returns the index of BB in its parent function.
 ///
 int getBasicBlockIndex (BasicBlock *BB) {
@@ -87,48 +93,31 @@
   return bbNum;
 }
 
-void WriteTraceToFile (Trace &T) {
-  std::string filename; 
-  unsigned count = 0;
-  do {
-    ++count;
-    filename = T.getFunction ()->getName () + ".trace" + utostr (count)
-             + ".txt";
-  } while (FileOpenable(filename));
-  std::ofstream out (filename.c_str ());
-  out << T.getFunction ()->getName () << "\n";
-  for (Trace::iterator i = T.begin (), e = T.end (); i != e; ++i) 
-    out << getBasicBlockIndex (*i) << " ";
-  out << "\n";
-  out.close ();
-}
-
 int main (int argc, char **argv) {
-  const char *bytecodeFileName = argv[1];
-  const char *traceFileName = argv[2];
+  // Get command line arguments.
+  cl::ParseCommandLineOptions(argc, argv, " trace-to-function tester\n");
 
-  // Read bytecode file
+  // Read bytecode file.
   std::string err;
-  Module *M = ParseBytecodeFile(bytecodeFileName, &err);
+  Module *M = ParseBytecodeFile (BytecodeFile, &err);
   if (!M) {
     std::cerr << "Error reading bytecode: " << err << "\n";
     exit (1);
   }
 
-  // Read trace file
+  // Read trace file.
   std::vector<BasicBlock *> vBB;
-  Trace *T = ReadTraceFromFile (M, traceFileName, &err);
+  Trace *T = ReadTraceFromFile (M, TraceFile, &err);
   if (!T) {
     std::cerr << "Error reading trace: " << err << "\n";
     exit (1);
   }
-  WriteTraceToFile (*T);
 
-  // Run TraceToFunction on the Trace
+  // Run TraceToFunction on the Trace.
   TraceFunction *TF = TraceFunction::get (*T);
   std::cerr << *TF->TraceFn << "\n\n";
 
-  // Run Verifier on the resulting TraceFunction
+  // Run the LLVM Verifier on the resulting TraceFunction.
   if (verifyFunction (*TF->TraceFn, PrintMessageAction)) {
     std::cerr << "Verifier fails.\n";
     exit (1);





More information about the llvm-commits mailing list