Remove includes of Support/Compiler.h that are no longer needed after the
[llvm.git] / lib / VMCore / PrintModulePass.cpp
blob3d4f19df05d8a5d903bb56a17c8b4cd20939e99c
1 //===--- VMCore/PrintModulePass.cpp - Module/Function Printer -------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // PrintModulePass and PrintFunctionPass implementations.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Assembly/PrintModulePass.h"
16 #include "llvm/Function.h"
17 #include "llvm/Module.h"
18 #include "llvm/Pass.h"
19 #include "llvm/Support/raw_ostream.h"
20 using namespace llvm;
22 namespace {
24 class PrintModulePass : public ModulePass {
25 raw_ostream *Out; // raw_ostream to print on
26 bool DeleteStream; // Delete the ostream in our dtor?
27 public:
28 static char ID;
29 PrintModulePass() : ModulePass(&ID), Out(&errs()),
30 DeleteStream(false) {}
31 PrintModulePass(raw_ostream *o, bool DS)
32 : ModulePass(&ID), Out(o), DeleteStream(DS) {}
34 ~PrintModulePass() {
35 if (DeleteStream) delete Out;
38 bool runOnModule(Module &M) {
39 (*Out) << M;
40 return false;
43 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
44 AU.setPreservesAll();
48 class PrintFunctionPass : public FunctionPass {
49 std::string Banner; // String to print before each function
50 raw_ostream *Out; // raw_ostream to print on
51 bool DeleteStream; // Delete the ostream in our dtor?
52 public:
53 static char ID;
54 PrintFunctionPass() : FunctionPass(&ID), Banner(""), Out(&errs()),
55 DeleteStream(false) {}
56 PrintFunctionPass(const std::string &B, raw_ostream *o, bool DS)
57 : FunctionPass(&ID), Banner(B), Out(o), DeleteStream(DS) {}
59 inline ~PrintFunctionPass() {
60 if (DeleteStream) delete Out;
63 // runOnFunction - This pass just prints a banner followed by the
64 // function as it's processed.
66 bool runOnFunction(Function &F) {
67 (*Out) << Banner << static_cast<Value&>(F);
68 return false;
71 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
72 AU.setPreservesAll();
77 char PrintModulePass::ID = 0;
78 static RegisterPass<PrintModulePass>
79 X("print-module", "Print module to stderr");
80 char PrintFunctionPass::ID = 0;
81 static RegisterPass<PrintFunctionPass>
82 Y("print-function","Print function to stderr");
84 /// createPrintModulePass - Create and return a pass that writes the
85 /// module to the specified raw_ostream.
86 ModulePass *llvm::createPrintModulePass(llvm::raw_ostream *OS,
87 bool DeleteStream) {
88 return new PrintModulePass(OS, DeleteStream);
91 /// createPrintFunctionPass - Create and return a pass that prints
92 /// functions to the specified raw_ostream as they are processed.
93 FunctionPass *llvm::createPrintFunctionPass(const std::string &Banner,
94 llvm::raw_ostream *OS,
95 bool DeleteStream) {
96 return new PrintFunctionPass(Banner, OS, DeleteStream);