1 //===-- MachineFunctionPrinterPass.cpp ------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // MachineFunctionPrinterPass implementation.
12 //===----------------------------------------------------------------------===//
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"
18 #include "llvm/Support/Debug.h"
23 /// MachineFunctionPrinterPass - This is a pass to dump the IR of a
26 struct MachineFunctionPrinterPass : public MachineFunctionPass {
30 const std::string Banner;
32 MachineFunctionPrinterPass() : MachineFunctionPass(ID), OS(dbgs()) { }
33 MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner)
34 : MachineFunctionPass(ID), OS(os), Banner(banner) {}
36 const char *getPassName() const { return "MachineFunction Printer"; }
38 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
40 MachineFunctionPass::getAnalysisUsage(AU);
43 bool runOnMachineFunction(MachineFunction &MF) {
44 OS << "# " << Banner << ":\n";
50 char MachineFunctionPrinterPass::ID = 0;
53 char &MachineFunctionPrinterPassID = MachineFunctionPrinterPass::ID;
54 INITIALIZE_PASS(MachineFunctionPrinterPass, "print-machineinstrs",
55 "Machine Function Printer", false, false)
58 /// Returns a newly-created MachineFunction Printer pass. The
59 /// default banner is empty.
61 MachineFunctionPass *createMachineFunctionPrinterPass(raw_ostream &OS,
62 const std::string &Banner){
63 return new MachineFunctionPrinterPass(OS, Banner);