a03b3492e622dc176d2f8c5499ae497dba68c5a6
[oota-llvm.git] / include / llvm / Assembly / PrintModulePass.h
1 //===- llvm/Assembly/PrintModulePass.h - Printing Pass -----------*- C++ -*--=//
2 //
3 // This file defines a simple pass to print out methods of a module as they are
4 // processed.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_ASSEMBLY_PRINTMODULEPASS_H
9 #define LLVM_ASSEMBLY_PRINTMODULEPASS_H
10
11 #include "llvm/Pass.h"
12 #include "llvm/Assembly/Writer.h"
13
14 class PrintModulePass : public Pass {
15   string Banner;          // String to print before each method
16   ostream *Out;           // ostream to print on
17   bool DeleteStream;      // Delete the ostream in our dtor?
18   bool PrintPerMethod;    // Print one method at a time rather than the whole?
19 public:
20   inline PrintModulePass(const string &B, ostream *o = &cout,
21                          bool DS = false,
22                          bool printPerMethod = true)
23     : Banner(B), Out(o), DeleteStream(DS), PrintPerMethod(printPerMethod) {
24   }
25   
26   inline ~PrintModulePass() {
27     if (DeleteStream) delete Out;
28   }
29   
30   // doPerMethodWork - This pass just prints a banner followed by the method as
31   // it's processed.
32   //
33   bool doPerMethodWork(Method *M) {
34     if (PrintPerMethod)
35       (*Out) << Banner << M;
36     return false;
37   }
38
39   // doPassFinalization - Virtual method overriden by subclasses to do any post
40   // processing needed after all passes have run.
41   //
42   bool doPassFinalization(Module *M) {
43     if (! PrintPerMethod)
44       (*Out) << Banner << M;
45     return false;
46   }
47 };
48
49 #endif