1 //===- MIRPrinter.cpp - MIR serialization format printer ------------------===//
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 the class that prints out the LLVM IR and machine
11 // functions using the MIR serialization format.
13 //===----------------------------------------------------------------------===//
15 #include "MIRPrinter.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/CodeGen/MachineFunction.h"
18 #include "llvm/CodeGen/MIRYamlMapping.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/Support/MemoryBuffer.h"
21 #include "llvm/Support/raw_ostream.h"
22 #include "llvm/Support/YAMLTraits.h"
28 /// This class prints out the machine functions using the MIR serialization
34 MIRPrinter(raw_ostream &OS) : OS(OS) {}
36 void print(const MachineFunction &MF);
39 } // end anonymous namespace
44 /// This struct serializes the LLVM IR module.
45 template <> struct BlockScalarTraits<Module> {
46 static void output(const Module &Mod, void *Ctxt, raw_ostream &OS) {
47 Mod.print(OS, nullptr);
49 static StringRef input(StringRef Str, void *Ctxt, Module &Mod) {
50 llvm_unreachable("LLVM Module is supposed to be parsed separately");
55 } // end namespace yaml
56 } // end namespace llvm
58 void MIRPrinter::print(const MachineFunction &MF) {
59 yaml::MachineFunction YamlMF;
60 YamlMF.Name = MF.getName();
61 YamlMF.Alignment = MF.getAlignment();
62 YamlMF.ExposesReturnsTwice = MF.exposesReturnsTwice();
63 YamlMF.HasInlineAsm = MF.hasInlineAsm();
68 void llvm::printMIR(raw_ostream &OS, const Module &M) {
70 Out << const_cast<Module &>(M);
73 void llvm::printMIR(raw_ostream &OS, const MachineFunction &MF) {
74 MIRPrinter Printer(OS);