mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-15 22:25:31 +00:00
MIR Serialization: Serialize machine instruction names.
This commit implements initial machine instruction serialization. It serializes machine instruction names. The instructions are represented using a YAML sequence of string literals and are a part of machine basic block YAML mapping. This commit introduces a class called 'MIParser' which will be used to parse the machine instructions and operands. Reviewers: Duncan P. N. Exon Smith Differential Revision: http://reviews.llvm.org/D10481 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240295 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Support/YAMLTraits.h"
|
||||
#include "llvm/Target/TargetInstrInfo.h"
|
||||
#include "llvm/Target/TargetSubtargetInfo.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
@@ -39,6 +41,17 @@ public:
|
||||
void convert(yaml::MachineBasicBlock &YamlMBB, const MachineBasicBlock &MBB);
|
||||
};
|
||||
|
||||
/// This class prints out the machine instructions using the MIR serialization
|
||||
/// format.
|
||||
class MIPrinter {
|
||||
raw_ostream &OS;
|
||||
|
||||
public:
|
||||
MIPrinter(raw_ostream &OS) : OS(OS) {}
|
||||
|
||||
void print(const MachineInstr &MI);
|
||||
};
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
namespace llvm {
|
||||
@@ -83,6 +96,25 @@ void MIRPrinter::convert(yaml::MachineBasicBlock &YamlMBB,
|
||||
YamlMBB.Alignment = MBB.getAlignment();
|
||||
YamlMBB.AddressTaken = MBB.hasAddressTaken();
|
||||
YamlMBB.IsLandingPad = MBB.isLandingPad();
|
||||
|
||||
// Print the machine instructions.
|
||||
YamlMBB.Instructions.reserve(MBB.size());
|
||||
std::string Str;
|
||||
for (const auto &MI : MBB) {
|
||||
raw_string_ostream StrOS(Str);
|
||||
MIPrinter(StrOS).print(MI);
|
||||
YamlMBB.Instructions.push_back(StrOS.str());
|
||||
Str.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void MIPrinter::print(const MachineInstr &MI) {
|
||||
const auto &SubTarget = MI.getParent()->getParent()->getSubtarget();
|
||||
const auto *TII = SubTarget.getInstrInfo();
|
||||
assert(TII && "Expected target instruction info");
|
||||
|
||||
OS << TII->getName(MI.getOpcode());
|
||||
// TODO: Print the instruction flags, machine operands, machine mem operands.
|
||||
}
|
||||
|
||||
void llvm::printMIR(raw_ostream &OS, const Module &M) {
|
||||
|
Reference in New Issue
Block a user