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