1 //===- MIRPrintingPass.cpp - Pass that prints out using the MIR format ----===//
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 // This file implements a pass that prints out the LLVM module using the MIR
11 // serialization format.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/CodeGen/MIRPrinter.h"
17 #include "llvm/CodeGen/MIRYamlMapping.h"
18 #include "llvm/CodeGen/MachineFunctionPass.h"
19 #include "llvm/CodeGen/Passes.h"
20 #include "llvm/Support/Debug.h"
21 #include "llvm/Support/raw_ostream.h"
27 /// This pass prints out the LLVM IR to an output stream using the MIR
28 /// serialization format.
29 struct MIRPrintingPass : public MachineFunctionPass {
32 std::string MachineFunctions;
34 MIRPrintingPass() : MachineFunctionPass(ID), OS(dbgs()) {}
35 MIRPrintingPass(raw_ostream &OS) : MachineFunctionPass(ID), OS(OS) {}
37 StringRef getPassName() const override { return "MIR Printing Pass"; }
39 void getAnalysisUsage(AnalysisUsage &AU) const override {
41 MachineFunctionPass::getAnalysisUsage(AU);
44 bool runOnMachineFunction(MachineFunction &MF) override {
46 raw_string_ostream StrOS(Str);
48 MachineFunctions.append(StrOS.str());
52 bool doFinalization(Module &M) override {
54 OS << MachineFunctions;
59 char MIRPrintingPass::ID = 0;
61 } // end anonymous namespace
63 char &llvm::MIRPrintingPassID = MIRPrintingPass::ID;
64 INITIALIZE_PASS(MIRPrintingPass, "mir-printer", "MIR Printer", false, false)
68 MachineFunctionPass *createPrintMIRPass(raw_ostream &OS) {
69 return new MIRPrintingPass(OS);
72 } // end namespace llvm