aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Assembly/PrintModulePass.h
blob: 72d8fabde042fc6c4c7ea8d0d5284b3f86ac6dd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//===- llvm/Assembly/PrintModulePass.h - Printing Pass -----------*- C++ -*--=//
//
// This file defines a simple pass to print out methods of a module as they are
// processed.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_ASSEMBLY_PRINTMODULEPASS_H
#define LLVM_ASSEMBLY_PRINTMODULEPASS_H

#include "llvm/Pass.h"
#include "llvm/Assembly/Writer.h"
#include <iostream>

class PrintModulePass : public Pass {
  std::string Banner;     // String to print before each method
  std::ostream *Out;      // ostream to print on
  bool DeleteStream;      // Delete the ostream in our dtor?
  bool PrintPerMethod;    // Print one method at a time rather than the whole?
public:
  inline PrintModulePass(const std::string &B, std::ostream *o = &std::cout,
                         bool DS = false,
                         bool printPerMethod = true)
    : Banner(B), Out(o), DeleteStream(DS), PrintPerMethod(printPerMethod) {
  }
  
  inline ~PrintModulePass() {
    if (DeleteStream) delete Out;
  }
  
  // doPerMethodWork - This pass just prints a banner followed by the method as
  // it's processed.
  //
  bool doPerMethodWork(Method *M) {
    if (PrintPerMethod)
      (*Out) << Banner << M;
    return false;
  }

  // doPassFinalization - Virtual method overriden by subclasses to do any post
  // processing needed after all passes have run.
  //
  bool doPassFinalization(Module *M) {
    if (! PrintPerMethod)
      (*Out) << Banner << M;
    return false;
  }
};

#endif