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