1 //===- llvm/Assembly/PrintModulePass.h - Printing Pass ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_ASSEMBLY_PRINTMODULEPASS_H
19 #define LLVM_ASSEMBLY_PRINTMODULEPASS_H
21 #include "llvm/Pass.h"
22 #include "llvm/Module.h"
27 class PrintModulePass : public ModulePass {
28 std::ostream *Out; // ostream to print on
29 bool DeleteStream; // Delete the ostream in our dtor?
31 PrintModulePass() : Out(&std::cerr), DeleteStream(false) {}
32 PrintModulePass(std::ostream *o, bool DS = false)
33 : Out(o), DeleteStream(DS) {
37 if (DeleteStream) delete Out;
40 bool runOnModule(Module &M) {
41 (*Out) << M << std::flush;
45 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
50 class PrintFunctionPass : public FunctionPass {
51 std::string Banner; // String to print before each function
52 std::ostream *Out; // ostream to print on
53 bool DeleteStream; // Delete the ostream in our dtor?
55 PrintFunctionPass() : Banner(""), Out(&std::cerr), DeleteStream(false) {}
56 PrintFunctionPass(const std::string &B, std::ostream *o = &std::cout,
58 : Banner(B), Out(o), DeleteStream(DS) {
61 inline ~PrintFunctionPass() {
62 if (DeleteStream) delete Out;
65 // runOnFunction - This pass just prints a banner followed by the function as
68 bool runOnFunction(Function &F) {
69 (*Out) << Banner << (Value&)F;
73 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
78 } // End llvm namespace