e211e8bdae62a065e0180bb2ea081bad4fd7dbe2
[oota-llvm.git] / include / llvm / Assembly / PrintModulePass.h
1 //===- llvm/Assembly/PrintModulePass.h - Printing Pass ----------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines two passes to print out a module.  The PrintModulePass pass
11 // simply prints out the entire module when it is executed.  The
12 // PrintFunctionPass class is designed to be pipelined with other
13 // FunctionPass's, and prints out the functions of the class as they are
14 // processed.
15 //
16 //===----------------------------------------------------------------------===//
17
18 #ifndef LLVM_ASSEMBLY_PRINTMODULEPASS_H
19 #define LLVM_ASSEMBLY_PRINTMODULEPASS_H
20
21 #include "llvm/Pass.h"
22 #include "llvm/Module.h"
23
24 class PrintModulePass : public Pass {
25   std::ostream *Out;      // ostream to print on
26   bool DeleteStream;      // Delete the ostream in our dtor?
27 public:
28   PrintModulePass() : Out(&std::cerr), DeleteStream(false) {}
29   PrintModulePass(std::ostream *o, bool DS = false)
30     : Out(o), DeleteStream(DS) {
31   }
32
33   ~PrintModulePass() {
34     if (DeleteStream) delete Out;
35   }
36   
37   bool run(Module &M) {
38     (*Out) << M << std::flush;
39     return false;
40   }
41
42   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
43     AU.setPreservesAll();
44   }
45 };
46
47 class PrintFunctionPass : public FunctionPass {
48   std::string Banner;     // String to print before each function
49   std::ostream *Out;      // ostream to print on
50   bool DeleteStream;      // Delete the ostream in our dtor?
51 public:
52   PrintFunctionPass() : Banner(""), Out(&std::cerr), DeleteStream(false) {}
53   PrintFunctionPass(const std::string &B, std::ostream *o = &std::cout,
54                     bool DS = false)
55     : Banner(B), Out(o), DeleteStream(DS) {
56   }
57
58   inline ~PrintFunctionPass() {
59     if (DeleteStream) delete Out;
60   }
61   
62   // runOnFunction - This pass just prints a banner followed by the function as
63   // it's processed.
64   //
65   bool runOnFunction(Function &F) {
66     (*Out) << Banner << (Value&)F;
67     return false;
68   }
69   
70   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
71     AU.setPreservesAll();
72   }
73 };
74
75 #endif