Resubmit r237708 (MIR Serialization: print and parse LLVM IR using MIR format).
[oota-llvm.git] / lib / CodeGen / MIR / MIRPrintingPass.cpp
1 //===- MIRPrintingPass.cpp - Pass that prints out using the MIR format ----===//
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 // This file implements a pass that prints out the LLVM module using the MIR
11 // serialization format.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "MIRPrinter.h"
16 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/CodeGen/MachineFunction.h"
18 #include "llvm/CodeGen/MachineFunctionPass.h"
19 #include "llvm/Support/Debug.h"
20 #include "llvm/Support/raw_ostream.h"
21
22 using namespace llvm;
23
24 namespace {
25
26 /// This pass prints out the LLVM IR to an output stream using the MIR
27 /// serialization format.
28 struct MIRPrintingPass : public MachineFunctionPass {
29   static char ID;
30   raw_ostream &OS;
31
32   MIRPrintingPass() : MachineFunctionPass(ID), OS(dbgs()) {}
33   MIRPrintingPass(raw_ostream &OS) : MachineFunctionPass(ID), OS(OS) {}
34
35   const char *getPassName() const override { return "MIR Printing Pass"; }
36
37   void getAnalysisUsage(AnalysisUsage &AU) const override {
38     AU.setPreservesAll();
39     MachineFunctionPass::getAnalysisUsage(AU);
40   }
41
42   virtual bool runOnMachineFunction(MachineFunction &MF) override {
43     // TODO: Print out the machine function.
44     return false;
45   }
46
47   virtual bool doFinalization(Module &M) override {
48     printMIR(OS, M);
49     return false;
50   }
51 };
52
53 char MIRPrintingPass::ID = 0;
54
55 } // end anonymous namespace
56
57 char &llvm::MIRPrintingPassID = MIRPrintingPass::ID;
58 INITIALIZE_PASS(MIRPrintingPass, "mir-printer", "MIR Printer", false, false)
59
60 namespace llvm {
61
62 MachineFunctionPass *createPrintMIRPass(raw_ostream &OS) {
63   return new MIRPrintingPass(OS);
64 }
65
66 } // end namespace llvm