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"
24 class PrintModulePass : public Pass {
25 std::ostream *Out; // ostream to print on
26 bool DeleteStream; // Delete the ostream in our dtor?
28 PrintModulePass() : Out(&std::cerr), DeleteStream(false) {}
29 PrintModulePass(std::ostream *o, bool DS = false)
30 : Out(o), DeleteStream(DS) {
34 if (DeleteStream) delete Out;
38 (*Out) << M << std::flush;
42 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
47 class PrintFunctionPass : public FunctionPass {
48 std::string Banner; // String to print before each function
49 std::ostream *Out; // ostream to print on
50 bool DeleteStream; // Delete the ostream in our dtor?
52 PrintFunctionPass() : Banner(""), Out(&std::cerr), DeleteStream(false) {}
53 PrintFunctionPass(const std::string &B, std::ostream *o = &std::cout,
55 : Banner(B), Out(o), DeleteStream(DS) {
58 inline ~PrintFunctionPass() {
59 if (DeleteStream) delete Out;
62 // runOnFunction - This pass just prints a banner followed by the function as
65 bool runOnFunction(Function &F) {
66 (*Out) << Banner << (Value&)F;
70 virtual void getAnalysisUsage(AnalysisUsage &AU) const {