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

Brian Gaeke gaeke at cs.uiuc.edu
Mon May 17 16:26:02 PDT 2004


Changes in directory reopt/tools/ttftest:

Makefile added (r1.1)
ttftest.cpp added (r1.1)

---
Log message:

Add ttftest (TraceToFunction tester) program


---
Diffs of the changes:  (+114 -0)

Index: reopt/tools/ttftest/Makefile
diff -c /dev/null reopt/tools/ttftest/Makefile:1.1
*** /dev/null	Mon May 17 16:25:35 2004
--- reopt/tools/ttftest/Makefile	Mon May 17 16:25:25 2004
***************
*** 0 ****
--- 1,9 ----
+ LEVEL = ../..
+ TOOLNAME = ttftest
+ USEDLIBS = tracetofunction
+ LLVMLIBS = vmcore bcreader analysis.a transformutils.a support.a
+ 
+ TOOLLINKOPTS = $(PLATFORMLIBDL)
+ 
+ include $(LEVEL)/Makefile.common
+ 


Index: reopt/tools/ttftest/ttftest.cpp
diff -c /dev/null reopt/tools/ttftest/ttftest.cpp:1.1
*** /dev/null	Mon May 17 16:25:35 2004
--- reopt/tools/ttftest/ttftest.cpp	Mon May 17 16:25:25 2004
***************
*** 0 ****
--- 1,105 ----
+ //===- ttftest.cpp - Test TraceToFunction transformation ------------------===//
+ // 
+ //                     The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for
+ // details.
+ // 
+ //===----------------------------------------------------------------------===//
+ //
+ // A simple program for testing TraceToFunction. This reads in a trace
+ // from a file, converts it to a function, and tries to verify the
+ // function.
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ #include "llvm/Analysis/Trace.h"
+ #include "llvm/Analysis/Verifier.h"
+ #include "llvm/Bytecode/Reader.h"
+ #include "reopt/TraceToFunction.h"
+ #include "llvm/Module.h"
+ #include <iostream>
+ #include <iterator>
+ #include <fstream>
+ #include <cerrno>
+ using namespace llvm;
+ 
+ /// getBasicBlockByNum - Returns the basic block in F whose index is
+ /// bbNum.
+ ///
+ BasicBlock *getBasicBlockByNum (Function *F, int bbNum) {
+   Function::iterator block = F->begin();
+   std::advance (block, bbNum);
+   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,
+                           std::string *ErrorStr) {
+   std::ifstream in (filename);
+   if (!in.good()) {
+     if (ErrorStr)
+       *ErrorStr = std::string("Can't open '") + filename + "': "
+                 + strerror(errno);
+     return 0;
+   }
+   char functionName[160];
+   in.getline(functionName, 160, '\n');
+   Function *F = M->getNamedFunction (functionName);
+   if (!F) {
+     if (ErrorStr)
+       *ErrorStr = std::string("Function '") + functionName
+                 + "' not found in module";
+     return 0;
+   }
+   std::cerr << "Function name: '" << functionName << "'\n" << "Basic blocks: ";
+   std::vector<BasicBlock *> vBB;
+   do {
+     int basicBlockNum;
+     in >> basicBlockNum;
+     if (!in.eof ()) {
+       std::cerr << basicBlockNum << " ";
+       vBB.push_back (getBasicBlockByNum (F, basicBlockNum));
+     }
+   } while (!in.eof ());
+   std::cerr << "\n";
+   return new Trace (vBB);
+ }
+ 
+ int main (int argc, char **argv) {
+   const char *bytecodeFileName = argv[1];
+   const char *traceFileName = argv[2];
+ 
+   // Read bytecode file
+   std::string err;
+   Module *M = ParseBytecodeFile(bytecodeFileName, &err);
+   if (!M) {
+     std::cerr << "Error reading bytecode: " << err << "\n";
+     exit (1);
+   }
+ 
+   // Read trace file
+   std::vector<BasicBlock *> vBB;
+   Trace *T = ReadTraceFromFile (M, traceFileName, &err);
+   if (!T) {
+     std::cerr << "Error reading trace: " << err << "\n";
+     exit (1);
+   }
+ 
+   // Run TraceToFunction on the Trace
+   TraceFunction *TF = TraceFunction::get (*T);
+   std::cerr << *TF->TraceFn << "\n\n";
+ 
+   // Run Verifier on the resulting TraceFunction
+   if (verifyFunction (*TF->TraceFn, PrintMessageAction)) {
+     std::cerr << "Verifier fails.\n";
+     exit (1);
+   } else {
+     std::cerr << "Verifier passes.\n";
+     exit (0);
+   }
+ }





More information about the llvm-commits mailing list