More fleshing out of docs/Passes.html, plus some typo fixes and
[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 module 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 #include "llvm/Support/Streams.h"
24
25 namespace llvm {
26
27 class PrintModulePass : public ModulePass {
28   OStream *Out;           // ostream to print on
29   bool DeleteStream;      // Delete the ostream in our dtor?
30 public:
31   static char ID;
32   PrintModulePass() : ModulePass(intptr_t(&ID)), Out(&cerr), 
33                       DeleteStream(false) {}
34   PrintModulePass(OStream *o, bool DS = false)
35     : ModulePass(intptr_t(&ID)), Out(o), DeleteStream(DS) {}
36
37   ~PrintModulePass() {
38     if (DeleteStream) delete Out;
39   }
40
41   bool runOnModule(Module &M) {
42     (*Out) << M << std::flush;
43     return false;
44   }
45
46   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
47     AU.setPreservesAll();
48   }
49 };
50
51 class PrintFunctionPass : public FunctionPass {
52   std::string Banner;     // String to print before each function
53   OStream *Out;           // ostream to print on
54   bool DeleteStream;      // Delete the ostream in our dtor?
55 public:
56   static char ID;
57   PrintFunctionPass() : FunctionPass(intptr_t(&ID)), Banner(""), Out(&cerr), 
58                         DeleteStream(false) {}
59   PrintFunctionPass(const std::string &B, OStream *o = &cout,
60                     bool DS = false)
61     : FunctionPass(intptr_t(&ID)), Banner(B), Out(o), DeleteStream(DS) {}
62
63   inline ~PrintFunctionPass() {
64     if (DeleteStream) delete Out;
65   }
66
67   // runOnFunction - This pass just prints a banner followed by the function as
68   // it's processed.
69   //
70   bool runOnFunction(Function &F) {
71     (*Out) << Banner << static_cast<Value&>(F);
72     return false;
73   }
74
75   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
76     AU.setPreservesAll();
77   }
78 };
79
80 } // End llvm namespace
81
82 #endif