1 //===-- 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" 18 #include "llvm/Support/Debug.h" 19 20 using namespace llvm; 21 22 namespace { 23 /// MachineFunctionPrinterPass - This is a pass to dump the IR of a 24 /// MachineFunction. 25 /// 26 struct MachineFunctionPrinterPass : public MachineFunctionPass { 27 static char ID; 28 29 raw_ostream &OS; 30 const std::string Banner; 31 32 MachineFunctionPrinterPass() : MachineFunctionPass(ID), OS(dbgs()) { } 33 MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner) 34 : MachineFunctionPass(ID), OS(os), Banner(banner) {} 35 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 50 char MachineFunctionPrinterPass::ID = 0; 51 } 52 53 char &MachineFunctionPrinterPassID = MachineFunctionPrinterPass::ID; 54 INITIALIZE_PASS(MachineFunctionPrinterPass, "print-machineinstrs", 55 "Machine Function Printer", false, false) 56 57 namespace llvm { 58 /// Returns a newly-created MachineFunction Printer pass. The 59 /// default banner is empty. 60 /// 61 MachineFunctionPass *createMachineFunctionPrinterPass(raw_ostream &OS, 62 const std::string &Banner){ 63 return new MachineFunctionPrinterPass(OS, Banner); 64 } 65 66 } 67