Change over to use new style pass mechanism, now passes only expose small
[oota-llvm.git] / lib / Transforms / Instrumentation / TraceValues.cpp
index c778ca8b0dfc57255c2539ce6eb5a1448f2611ca..6e4fedcfa8583a2a8da2ce9ae88bb9c9cbd603d6 100644 (file)
 #include "llvm/Method.h"
 #include "llvm/Module.h"
 #include "llvm/SymbolTable.h"
+#include "llvm/Pass.h"
 #include "llvm/Assembly/Writer.h"
 #include "Support/StringExtras.h"
 #include <sstream>
 using std::vector;
 using std::string;
 
+namespace {
+  class InsertTraceCode : public MethodPass {
+    bool TraceBasicBlockExits, TraceMethodExits;
+    Method *PrintfMeth;
+  public:
+    InsertTraceCode(bool traceBasicBlockExits, bool traceMethodExits)
+      : TraceBasicBlockExits(traceBasicBlockExits), 
+        TraceMethodExits(traceMethodExits) {}
+    
+    // Add a prototype for printf if it is not already in the program.
+    //
+    bool doInitialization(Module *M);
+    
+    //--------------------------------------------------------------------------
+    // Function InsertCodeToTraceValues
+    // 
+    // Inserts tracing code for all live values at basic block and/or method
+    // exits as specified by `traceBasicBlockExits' and `traceMethodExits'.
+    //
+    static bool doit(Method *M, bool traceBasicBlockExits,
+                     bool traceMethodExits, Method *Printf);
+    
+    // runOnMethod - This method does the work.  Always successful.
+    //
+    bool runOnMethod(Method *M) {
+      return doit(M, TraceBasicBlockExits, TraceMethodExits, PrintfMeth);
+    }
+  };
+} // end anonymous namespace
+
+
+Pass *createTraceValuesPassForMethod() {       // Just trace methods
+  return new InsertTraceCode(false, true);
+}
+
+Pass *createTraceValuesPassForBasicBlocks() {  // Trace BB's and methods
+  return new InsertTraceCode(true, true);
+}
+
+
+
+
 // Add a prototype for printf if it is not already in the program.
 //
 bool InsertTraceCode::doInitialization(Module *M) {
@@ -242,7 +285,7 @@ static inline void InsertCodeToShowMethodExit(BasicBlock *BB, Method *Printf) {
 
 bool InsertTraceCode::doit(Method *M, bool traceBasicBlockExits,
                            bool traceMethodEvents, Method *Printf) {
-  if (M->isExternal() || (!traceBasicBlockExits && !traceMethodEvents))
+  if (!traceBasicBlockExits && !traceMethodEvents)
     return false;
 
   vector<Instruction*> valuesStoredInMethod;