You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
3.7 KiB
131 lines
3.7 KiB
3 years ago
|
From a73fe8ac18d3ca81fa7a8d8c404cd7e0faf92ddc Mon Sep 17 00:00:00 2001
|
||
|
From: mephi42 <mephi42@gmail.com>
|
||
|
Date: Tue, 7 Aug 2018 17:59:43 +0200
|
||
|
Subject: [PATCH 3/7] capstone: generate *GenInstrInfo.inc
|
||
|
|
||
|
---
|
||
|
utils/TableGen/InstrInfoEmitter.cpp | 49 ++++++++++++++++++++++++++---
|
||
|
1 file changed, 44 insertions(+), 5 deletions(-)
|
||
|
|
||
|
diff --git a/utils/TableGen/InstrInfoEmitter.cpp b/utils/TableGen/InstrInfoEmitter.cpp
|
||
|
index 0aff1aa6f94..2f3a2729262 100644
|
||
|
--- a/utils/TableGen/InstrInfoEmitter.cpp
|
||
|
+++ b/utils/TableGen/InstrInfoEmitter.cpp
|
||
|
@@ -92,6 +92,7 @@ private:
|
||
|
|
||
|
} // end anonymous namespace
|
||
|
|
||
|
+#ifndef CAPSTONE
|
||
|
static void PrintDefList(const std::vector<Record*> &Uses,
|
||
|
unsigned Num, raw_ostream &OS) {
|
||
|
OS << "static const MCPhysReg ImplicitList" << Num << "[] = { ";
|
||
|
@@ -99,6 +100,7 @@ static void PrintDefList(const std::vector<Record*> &Uses,
|
||
|
OS << getQualifiedName(U) << ", ";
|
||
|
OS << "0 };\n";
|
||
|
}
|
||
|
+#endif
|
||
|
|
||
|
//===----------------------------------------------------------------------===//
|
||
|
// Operand Info Emission.
|
||
|
@@ -426,8 +428,17 @@ void InstrInfoEmitter::emitTIIHelperMethods(raw_ostream &OS) {
|
||
|
// run - Emit the main instruction description records for the target...
|
||
|
void InstrInfoEmitter::run(raw_ostream &OS) {
|
||
|
emitSourceFileHeader("Target Instruction Enum Values and Descriptors", OS);
|
||
|
+
|
||
|
+#ifdef CAPSTONE
|
||
|
+ OS << "/* Capstone Disassembly Engine */\n"
|
||
|
+ "/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015 */\n"
|
||
|
+ "\n"
|
||
|
+ "\n";
|
||
|
+#endif
|
||
|
+
|
||
|
emitEnums(OS);
|
||
|
|
||
|
+#ifndef CAPSTONE
|
||
|
OS << "#ifdef GET_INSTRINFO_MC_DESC\n";
|
||
|
OS << "#undef GET_INSTRINFO_MC_DESC\n";
|
||
|
|
||
|
@@ -545,6 +556,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
|
||
|
emitOperandTypesEnum(OS, Target);
|
||
|
|
||
|
emitMCIIHelperMethods(OS);
|
||
|
+#endif
|
||
|
}
|
||
|
|
||
|
void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num,
|
||
|
@@ -659,7 +671,9 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) {
|
||
|
OS << "#ifdef GET_INSTRINFO_ENUM\n";
|
||
|
OS << "#undef GET_INSTRINFO_ENUM\n";
|
||
|
|
||
|
+#ifndef CAPSTONE
|
||
|
OS << "namespace llvm {\n\n";
|
||
|
+#endif
|
||
|
|
||
|
CodeGenTarget Target(Records);
|
||
|
|
||
|
@@ -669,17 +683,39 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) {
|
||
|
if (Namespace.empty())
|
||
|
PrintFatalError("No instructions defined!");
|
||
|
|
||
|
+#ifndef CAPSTONE
|
||
|
OS << "namespace " << Namespace << " {\n";
|
||
|
- OS << " enum {\n";
|
||
|
+#endif
|
||
|
+#ifdef CAPSTONE
|
||
|
+ OS << "\n"
|
||
|
+#else
|
||
|
+ OS << " "
|
||
|
+#endif
|
||
|
+ << "enum {\n";
|
||
|
unsigned Num = 0;
|
||
|
for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue())
|
||
|
- OS << " " << Inst->TheDef->getName() << "\t= " << Num++ << ",\n";
|
||
|
- OS << " INSTRUCTION_LIST_END = " << Num << "\n";
|
||
|
+ OS << " "
|
||
|
+#ifdef CAPSTONE
|
||
|
+ << Target.getName() << "_"
|
||
|
+#endif
|
||
|
+ << Inst->TheDef->getName() << "\t= " << Num++ << ",\n";
|
||
|
+ OS << " "
|
||
|
+#ifdef CAPSTONE
|
||
|
+ << Target.getName() << "_"
|
||
|
+#endif
|
||
|
+ << "INSTRUCTION_LIST_END = " << Num << "\n";
|
||
|
OS << " };\n\n";
|
||
|
+#ifndef CAPSTONE
|
||
|
OS << "} // end " << Namespace << " namespace\n";
|
||
|
OS << "} // end llvm namespace\n";
|
||
|
- OS << "#endif // GET_INSTRINFO_ENUM\n\n";
|
||
|
-
|
||
|
+#endif
|
||
|
+ OS << "#endif // GET_INSTRINFO_ENUM\n"
|
||
|
+#ifndef CAPSTONE
|
||
|
+ << "\n"
|
||
|
+#endif
|
||
|
+ ;
|
||
|
+
|
||
|
+#ifndef CAPSTONE
|
||
|
OS << "#ifdef GET_INSTRINFO_SCHED_ENUM\n";
|
||
|
OS << "#undef GET_INSTRINFO_SCHED_ENUM\n";
|
||
|
OS << "namespace llvm {\n\n";
|
||
|
@@ -696,13 +732,16 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) {
|
||
|
OS << "} // end llvm namespace\n";
|
||
|
|
||
|
OS << "#endif // GET_INSTRINFO_SCHED_ENUM\n\n";
|
||
|
+#endif
|
||
|
}
|
||
|
|
||
|
namespace llvm {
|
||
|
|
||
|
void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) {
|
||
|
InstrInfoEmitter(RK).run(OS);
|
||
|
+#ifndef CAPSTONE
|
||
|
EmitMapTable(RK, OS);
|
||
|
+#endif
|
||
|
}
|
||
|
|
||
|
} // end llvm namespace
|
||
|
--
|
||
|
2.19.1
|
||
|
|