Changes to make print pass work!
[oota-llvm.git] / include / llvm / Assembly / PrintModulePass.h
1 //===- llvm/Assembly/PrintModulePass.h - Printing Pass -----------*- C++ -*--=//
2 //
3 // This file defines two passes to print out a module.  The PrintModulePass
4 // pass simply prints out the entire module when it is executed.  The
5 // PrintMethodPass class is designed to be pipelined with other MethodPass's,
6 // and prints out the methods of the class as they are processed.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_ASSEMBLY_PRINTMODULEPASS_H
11 #define LLVM_ASSEMBLY_PRINTMODULEPASS_H
12
13 #include "llvm/Pass.h"
14 #include "llvm/Value.h"
15 #include <iostream>
16
17 class PrintModulePass : public Pass {
18   std::ostream *Out;      // ostream to print on
19   bool DeleteStream;      // Delete the ostream in our dtor?
20 public:
21   inline PrintModulePass(std::ostream *o = &std::cout, bool DS = false)
22     : Out(o), DeleteStream(DS) {
23   }
24   
25   inline ~PrintModulePass() {
26     if (DeleteStream) delete Out;
27   }
28   
29   bool run(Module *M) {
30     (*Out) << M;
31     return false;
32   }
33 };
34
35 class PrintFunctionPass : public MethodPass {
36   std::string Banner;     // String to print before each method
37   std::ostream *Out;      // ostream to print on
38   bool DeleteStream;      // Delete the ostream in our dtor?
39 public:
40   inline PrintFunctionPass(const std::string &B, std::ostream *o = &std::cout,
41                            bool DS = false)
42     : Banner(B), Out(o), DeleteStream(DS) {
43   }
44   
45   inline ~PrintFunctionPass() {
46     if (DeleteStream) delete Out;
47   }
48   
49   // runOnMethod - This pass just prints a banner followed by the method as
50   // it's processed.
51   //
52   bool runOnMethod(Function *F) {
53     (*Out) << Banner << (Value*)F;
54     return false;
55   }
56 };
57
58 #endif