Home | History | Annotate | Download | only in CodeGen
      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 
     19 using namespace llvm;
     20 
     21 namespace {
     22 /// MachineFunctionPrinterPass - This is a pass to dump the IR of a
     23 /// MachineFunction.
     24 ///
     25 struct MachineFunctionPrinterPass : public MachineFunctionPass {
     26   static char ID;
     27 
     28   raw_ostream &OS;
     29   const std::string Banner;
     30 
     31   MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner)
     32       : MachineFunctionPass(ID), OS(os), Banner(banner) {}
     33 
     34   const char *getPassName() const { return "MachineFunction Printer"; }
     35 
     36   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
     37     AU.setPreservesAll();
     38     MachineFunctionPass::getAnalysisUsage(AU);
     39   }
     40 
     41   bool runOnMachineFunction(MachineFunction &MF) {
     42     OS << "# " << Banner << ":\n";
     43     MF.print(OS);
     44     return false;
     45   }
     46 };
     47 
     48 char MachineFunctionPrinterPass::ID = 0;
     49 }
     50 
     51 namespace llvm {
     52 /// Returns a newly-created MachineFunction Printer pass. The
     53 /// default banner is empty.
     54 ///
     55 MachineFunctionPass *createMachineFunctionPrinterPass(raw_ostream &OS,
     56                                                       const std::string &Banner){
     57   return new MachineFunctionPrinterPass(OS, Banner);
     58 }
     59 
     60 }
     61