MEGAPATCH checkin.
[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 pass
4 // simply prints out the entire module when it is executed.  The
5 // PrintFunctionPass class is designed to be pipelined with other
6 // FunctionPass's, and prints out the functions of the class as they are
7 // processed.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef LLVM_ASSEMBLY_PRINTMODULEPASS_H
12 #define LLVM_ASSEMBLY_PRINTMODULEPASS_H
13
14 #include "llvm/Pass.h"
15 #include "llvm/Value.h"
16 #include <iostream>
17
18 class PrintModulePass : public Pass {
19   std::ostream *Out;      // ostream to print on
20   bool DeleteStream;      // Delete the ostream in our dtor?
21 public:
22   inline PrintModulePass(std::ostream *o = &std::cout, bool DS = false)
23     : Out(o), DeleteStream(DS) {
24   }
25
26   const char *getPassName() const { return "Module Printer"; }
27   
28   inline ~PrintModulePass() {
29     if (DeleteStream) delete Out;
30   }
31   
32   bool run(Module &M) {
33     (*Out) << (Value&)M;
34     return false;
35   }
36
37   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
38     AU.setPreservesAll();
39   }
40 };
41
42 class PrintFunctionPass : public FunctionPass {
43   std::string Banner;     // String to print before each function
44   std::ostream *Out;      // ostream to print on
45   bool DeleteStream;      // Delete the ostream in our dtor?
46 public:
47   inline PrintFunctionPass(const std::string &B, std::ostream *o = &std::cout,
48                            bool DS = false)
49     : Banner(B), Out(o), DeleteStream(DS) {
50   }
51
52   const char *getPassName() const { return "Function Printer"; }
53   
54   inline ~PrintFunctionPass() {
55     if (DeleteStream) delete Out;
56   }
57   
58   // runOnFunction - This pass just prints a banner followed by the function as
59   // it's processed.
60   //
61   bool runOnFunction(Function &F) {
62     (*Out) << Banner << (Value&)F;
63     return false;
64   }
65   
66   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
67     AU.setPreservesAll();
68   }
69 };
70
71 #endif