Expose passinfo from BreakCriticalEdges pass so that it may be "Required" by
[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/Module.h"
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   PrintModulePass() : Out(&std::cerr), DeleteStream(false) {}
22   PrintModulePass(std::ostream *o, bool DS = false)
23     : Out(o), DeleteStream(DS) {
24   }
25
26   ~PrintModulePass() {
27     if (DeleteStream) delete Out;
28   }
29   
30   bool run(Module &M) {
31     (*Out) << M << std::flush;
32     return false;
33   }
34
35   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
36     AU.setPreservesAll();
37   }
38 };
39
40 class PrintFunctionPass : public FunctionPass {
41   std::string Banner;     // String to print before each function
42   std::ostream *Out;      // ostream to print on
43   bool DeleteStream;      // Delete the ostream in our dtor?
44 public:
45   PrintFunctionPass() : Banner(""), Out(&std::cerr), DeleteStream(false) {}
46   PrintFunctionPass(const std::string &B, std::ostream *o = &std::cout,
47                     bool DS = false)
48     : Banner(B), Out(o), DeleteStream(DS) {
49   }
50
51   inline ~PrintFunctionPass() {
52     if (DeleteStream) delete Out;
53   }
54   
55   // runOnFunction - This pass just prints a banner followed by the function as
56   // it's processed.
57   //
58   bool runOnFunction(Function &F) {
59     (*Out) << Banner << (Value&)F;
60     return false;
61   }
62   
63   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
64     AU.setPreservesAll();
65   }
66 };
67
68 #endif