blob: dbda93e4fd9b40358320821dc559bcef4e8ce250 [file] [log] [blame]
David Greene5c8aa952010-04-02 23:17:14 +00001//===-- MachineFunctionPrinterPass.cpp ------------------------------------===//
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// MachineFunctionPrinterPass implementation.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/CodeGen/Passes.h"
15#include "llvm/CodeGen/MachineFunctionPass.h"
16#include "llvm/CodeGen/MachineFunction.h"
17#include "llvm/Support/raw_ostream.h"
Bob Wilson6e1b8122012-05-30 00:17:12 +000018#include "llvm/Support/Debug.h"
David Greene5c8aa952010-04-02 23:17:14 +000019
20using namespace llvm;
21
22namespace {
23/// MachineFunctionPrinterPass - This is a pass to dump the IR of a
24/// MachineFunction.
25///
26struct MachineFunctionPrinterPass : public MachineFunctionPass {
27 static char ID;
28
29 raw_ostream &OS;
30 const std::string Banner;
31
Bob Wilson6e1b8122012-05-30 00:17:12 +000032 MachineFunctionPrinterPass() : MachineFunctionPass(ID), OS(dbgs()) { }
David Greene5c8aa952010-04-02 23:17:14 +000033 MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner)
Owen Anderson90c579d2010-08-06 18:33:48 +000034 : MachineFunctionPass(ID), OS(os), Banner(banner) {}
David Greene5c8aa952010-04-02 23:17:14 +000035
36 const char *getPassName() const { return "MachineFunction Printer"; }
37
38 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
39 AU.setPreservesAll();
40 MachineFunctionPass::getAnalysisUsage(AU);
41 }
42
43 bool runOnMachineFunction(MachineFunction &MF) {
44 OS << "# " << Banner << ":\n";
45 MF.print(OS);
46 return false;
47 }
48};
49
50char MachineFunctionPrinterPass::ID = 0;
51}
52
Bob Wilson6e1b8122012-05-30 00:17:12 +000053char &MachineFunctionPrinterPassID = MachineFunctionPrinterPass::ID;
54INITIALIZE_PASS(MachineFunctionPrinterPass, "print-machineinstrs",
55 "Machine Function Printer", false, false)
56
David Greene5c8aa952010-04-02 23:17:14 +000057namespace llvm {
58/// Returns a newly-created MachineFunction Printer pass. The
59/// default banner is empty.
60///
61MachineFunctionPass *createMachineFunctionPrinterPass(raw_ostream &OS,
62 const std::string &Banner){
63 return new MachineFunctionPrinterPass(OS, Banner);
64}
65
66}