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/Passes.h"
16 #include "llvm/CodeGen/MachineFunction.h"
17 #include "llvm/CodeGen/MachineFunctionPass.h"
18 #include "llvm/IR/Module.h"
19 #include "llvm/Support/Debug.h"
20 #include "llvm/Support/raw_ostream.h"
21 #include "llvm/Support/YAMLTraits.h"
28 /// This struct serializes the LLVM IR module.
29 template <> struct BlockScalarTraits<Module> {
30 static void output(const Module &Mod, void *Ctxt, raw_ostream &OS) {
31 Mod.print(OS, nullptr);
33 static StringRef input(StringRef Str, void *Ctxt, Module &Mod) {
34 llvm_unreachable("LLVM Module is supposed to be parsed separately");
39 } // end namespace yaml
40 } // end namespace llvm
44 /// This pass prints out the LLVM IR to an output stream using the MIR
45 /// serialization format.
46 struct MIRPrintingPass : public MachineFunctionPass {
50 MIRPrintingPass() : MachineFunctionPass(ID), OS(dbgs()) {}
51 MIRPrintingPass(raw_ostream &OS) : MachineFunctionPass(ID), OS(OS) {}
53 const char *getPassName() const override { return "MIR Printing Pass"; }
55 void getAnalysisUsage(AnalysisUsage &AU) const override {
57 MachineFunctionPass::getAnalysisUsage(AU);
60 virtual bool runOnMachineFunction(MachineFunction &MF) override {
61 // TODO: Print out the machine function.
65 virtual bool doFinalization(Module &M) override {
72 char MIRPrintingPass::ID = 0;
74 } // end anonymous namespace
76 char &llvm::MIRPrintingPassID = MIRPrintingPass::ID;
77 INITIALIZE_PASS(MIRPrintingPass, "mir-printer", "MIR Printer", false, false)
81 MachineFunctionPass *createPrintMIRPass(raw_ostream &OS) {
82 return new MIRPrintingPass(OS);
85 } // end namespace llvm