2015-06-09 19:06:30 +00:00
|
|
|
//===- MIRPrintingPass.cpp - Pass that prints out using the MIR format ----===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements a pass that prints out the LLVM module using the MIR
|
|
|
|
// serialization format.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-06-21 13:59:01 +00:00
|
|
|
#include "MIRPrinter.h"
|
2015-06-09 19:06:30 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MIRYamlMapping.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/// This pass prints out the LLVM IR to an output stream using the MIR
|
|
|
|
/// serialization format.
|
|
|
|
struct MIRPrintingPass : public MachineFunctionPass {
|
|
|
|
static char ID;
|
|
|
|
raw_ostream &OS;
|
|
|
|
std::string MachineFunctions;
|
|
|
|
|
|
|
|
MIRPrintingPass() : MachineFunctionPass(ID), OS(dbgs()) {}
|
|
|
|
MIRPrintingPass(raw_ostream &OS) : MachineFunctionPass(ID), OS(OS) {}
|
|
|
|
|
2017-01-02 19:17:04 +00:00
|
|
|
StringRef getPassName() const override { return "MIR Printing Pass"; }
|
2015-06-09 19:06:30 +00:00
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
2015-12-30 11:46:15 +00:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override {
|
2015-06-09 19:06:30 +00:00
|
|
|
std::string Str;
|
|
|
|
raw_string_ostream StrOS(Str);
|
2015-06-21 13:59:01 +00:00
|
|
|
printMIR(StrOS, MF);
|
2015-06-09 19:06:30 +00:00
|
|
|
MachineFunctions.append(StrOS.str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-30 11:46:15 +00:00
|
|
|
bool doFinalization(Module &M) override {
|
2015-06-21 13:59:01 +00:00
|
|
|
printMIR(OS, M);
|
2015-06-09 19:06:30 +00:00
|
|
|
OS << MachineFunctions;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
char MIRPrintingPass::ID = 0;
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
char &llvm::MIRPrintingPassID = MIRPrintingPass::ID;
|
|
|
|
INITIALIZE_PASS(MIRPrintingPass, "mir-printer", "MIR Printer", false, false)
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
MachineFunctionPass *createPrintMIRPass(raw_ostream &OS) {
|
|
|
|
return new MIRPrintingPass(OS);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace llvm
|