| 1 |
From a73fe8ac18d3ca81fa7a8d8c404cd7e0faf92ddc Mon Sep 17 00:00:00 2001 |
| 2 |
From: mephi42 <[email protected]> |
| 3 |
Date: Tue, 7 Aug 2018 17:59:43 +0200 |
| 4 |
Subject: [PATCH 3/7] capstone: generate *GenInstrInfo.inc |
| 5 |
|
| 6 |
--- |
| 7 |
utils/TableGen/InstrInfoEmitter.cpp | 49 ++++++++++++++++++++++++++--- |
| 8 |
1 file changed, 44 insertions(+), 5 deletions(-) |
| 9 |
|
| 10 |
diff --git a/utils/TableGen/InstrInfoEmitter.cpp b/utils/TableGen/InstrInfoEmitter.cpp |
| 11 |
index 0aff1aa6f94..2f3a2729262 100644 |
| 12 |
--- a/utils/TableGen/InstrInfoEmitter.cpp |
| 13 |
+++ b/utils/TableGen/InstrInfoEmitter.cpp |
| 14 |
@@ -92,6 +92,7 @@ private: |
| 15 |
|
| 16 |
} // end anonymous namespace |
| 17 |
|
| 18 |
+#ifndef CAPSTONE |
| 19 |
static void PrintDefList(const std::vector<Record*> &Uses, |
| 20 |
unsigned Num, raw_ostream &OS) { |
| 21 |
OS << "static const MCPhysReg ImplicitList" << Num << "[] = { "; |
| 22 |
@@ -99,6 +100,7 @@ static void PrintDefList(const std::vector<Record*> &Uses, |
| 23 |
OS << getQualifiedName(U) << ", "; |
| 24 |
OS << "0 };\n"; |
| 25 |
} |
| 26 |
+#endif |
| 27 |
|
| 28 |
//===----------------------------------------------------------------------===// |
| 29 |
// Operand Info Emission. |
| 30 |
@@ -426,8 +428,17 @@ void InstrInfoEmitter::emitTIIHelperMethods(raw_ostream &OS) { |
| 31 |
// run - Emit the main instruction description records for the target... |
| 32 |
void InstrInfoEmitter::run(raw_ostream &OS) { |
| 33 |
emitSourceFileHeader("Target Instruction Enum Values and Descriptors", OS); |
| 34 |
+ |
| 35 |
+#ifdef CAPSTONE |
| 36 |
+ OS << "/* Capstone Disassembly Engine */\n" |
| 37 |
+ "/* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */\n" |
| 38 |
+ "\n" |
| 39 |
+ "\n"; |
| 40 |
+#endif |
| 41 |
+ |
| 42 |
emitEnums(OS); |
| 43 |
|
| 44 |
+#ifndef CAPSTONE |
| 45 |
OS << "#ifdef GET_INSTRINFO_MC_DESC\n"; |
| 46 |
OS << "#undef GET_INSTRINFO_MC_DESC\n"; |
| 47 |
|
| 48 |
@@ -545,6 +556,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) { |
| 49 |
emitOperandTypesEnum(OS, Target); |
| 50 |
|
| 51 |
emitMCIIHelperMethods(OS); |
| 52 |
+#endif |
| 53 |
} |
| 54 |
|
| 55 |
void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num, |
| 56 |
@@ -659,7 +671,9 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) { |
| 57 |
OS << "#ifdef GET_INSTRINFO_ENUM\n"; |
| 58 |
OS << "#undef GET_INSTRINFO_ENUM\n"; |
| 59 |
|
| 60 |
+#ifndef CAPSTONE |
| 61 |
OS << "namespace llvm {\n\n"; |
| 62 |
+#endif |
| 63 |
|
| 64 |
CodeGenTarget Target(Records); |
| 65 |
|
| 66 |
@@ -669,17 +683,39 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) { |
| 67 |
if (Namespace.empty()) |
| 68 |
PrintFatalError("No instructions defined!"); |
| 69 |
|
| 70 |
+#ifndef CAPSTONE |
| 71 |
OS << "namespace " << Namespace << " {\n"; |
| 72 |
- OS << " enum {\n"; |
| 73 |
+#endif |
| 74 |
+#ifdef CAPSTONE |
| 75 |
+ OS << "\n" |
| 76 |
+#else |
| 77 |
+ OS << " " |
| 78 |
+#endif |
| 79 |
+ << "enum {\n"; |
| 80 |
unsigned Num = 0; |
| 81 |
for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) |
| 82 |
- OS << " " << Inst->TheDef->getName() << "\t= " << Num++ << ",\n"; |
| 83 |
- OS << " INSTRUCTION_LIST_END = " << Num << "\n"; |
| 84 |
+ OS << " " |
| 85 |
+#ifdef CAPSTONE |
| 86 |
+ << Target.getName() << "_" |
| 87 |
+#endif |
| 88 |
+ << Inst->TheDef->getName() << "\t= " << Num++ << ",\n"; |
| 89 |
+ OS << " " |
| 90 |
+#ifdef CAPSTONE |
| 91 |
+ << Target.getName() << "_" |
| 92 |
+#endif |
| 93 |
+ << "INSTRUCTION_LIST_END = " << Num << "\n"; |
| 94 |
OS << " };\n\n"; |
| 95 |
+#ifndef CAPSTONE |
| 96 |
OS << "} // end " << Namespace << " namespace\n"; |
| 97 |
OS << "} // end llvm namespace\n"; |
| 98 |
- OS << "#endif // GET_INSTRINFO_ENUM\n\n"; |
| 99 |
- |
| 100 |
+#endif |
| 101 |
+ OS << "#endif // GET_INSTRINFO_ENUM\n" |
| 102 |
+#ifndef CAPSTONE |
| 103 |
+ << "\n" |
| 104 |
+#endif |
| 105 |
+ ; |
| 106 |
+ |
| 107 |
+#ifndef CAPSTONE |
| 108 |
OS << "#ifdef GET_INSTRINFO_SCHED_ENUM\n"; |
| 109 |
OS << "#undef GET_INSTRINFO_SCHED_ENUM\n"; |
| 110 |
OS << "namespace llvm {\n\n"; |
| 111 |
@@ -696,13 +732,16 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) { |
| 112 |
OS << "} // end llvm namespace\n"; |
| 113 |
|
| 114 |
OS << "#endif // GET_INSTRINFO_SCHED_ENUM\n\n"; |
| 115 |
+#endif |
| 116 |
} |
| 117 |
|
| 118 |
namespace llvm { |
| 119 |
|
| 120 |
void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) { |
| 121 |
InstrInfoEmitter(RK).run(OS); |
| 122 |
+#ifndef CAPSTONE |
| 123 |
EmitMapTable(RK, OS); |
| 124 |
+#endif |
| 125 |
} |
| 126 |
|
| 127 |
} // end llvm namespace |
| 128 |
-- |
| 129 |
2.19.1 |
| 130 |
|