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