| 1 |
From 9f8b248761db00ff85959d51258d963d1b8e5627 Mon Sep 17 00:00:00 2001 |
| 2 |
From: fanfuqiang <[email protected]> |
| 3 |
Date: Thu, 28 Feb 2019 21:18:04 +0800 |
| 4 |
Subject: [PATCH] fix riscv registerclass array of genregisterinfo |
| 5 |
|
| 6 |
--- |
| 7 |
llvm/0001-capstone-riscv-patchs.patch | 3161 ----------------- |
| 8 |
...for-generate-RISCV-port-inc-for-CAPS.patch | 905 ----- |
| 9 |
llvm/0003-clear-old-patchs.patch | 1602 --------- |
| 10 |
3 files changed, 5668 deletions(-) |
| 11 |
delete mode 100644 llvm/0001-capstone-riscv-patchs.patch |
| 12 |
delete mode 100644 llvm/0002-update-TableGen-for-generate-RISCV-port-inc-for-CAPS.patch |
| 13 |
delete mode 100644 llvm/0003-clear-old-patchs.patch |
| 14 |
|
| 15 |
diff --git a/llvm/0001-capstone-riscv-patchs.patch b/llvm/0001-capstone-riscv-patchs.patch |
| 16 |
deleted file mode 100644 |
| 17 |
index eb3246814..000000000 |
| 18 |
--- a/llvm/0001-capstone-riscv-patchs.patch |
| 19 |
+++ /dev/null |
| 20 |
@@ -1,3161 +0,0 @@ |
| 21 |
-From 3373228170bbc2324d223bdeca761de3b4565508 Mon Sep 17 00:00:00 2001 |
| 22 |
-From: fanfuqiang <[email protected]> |
| 23 |
-Date: Sun, 17 Feb 2019 06:08:44 +0800 |
| 24 |
-Subject: [PATCH] capstone riscv patchs |
| 25 |
- |
| 26 |
---- |
| 27 |
- ...apstone-generate-GenRegisterInfo.inc.patch | 338 +++++++++++++ |
| 28 |
- ...pstone-generate-GenSubtargetInfo.inc.patch | 86 ++++ |
| 29 |
- ...3-capstone-generate-GenInstrInfo.inc.patch | 130 +++++ |
| 30 |
- ...e-generate-GenDisassemblerTables.inc.patch | 472 ++++++++++++++++++ |
| 31 |
- ...5-capstone-generate-GenAsmWriter.inc.patch | 225 +++++++++ |
| 32 |
- ...06-capstone-generate-MappingInsn.inc.patch | 174 +++++++ |
| 33 |
- ...apstone-generate-GenInsnNameMaps.inc.patch | 110 ++++ |
| 34 |
- llvm/lib/Target/RISCV/CMakeLists.txt | 2 + |
| 35 |
- llvm/utils/TableGen/AsmWriterEmitter.cpp | 103 +++- |
| 36 |
- llvm/utils/TableGen/AsmWriterInst.cpp | 4 + |
| 37 |
- llvm/utils/TableGen/DisassemblerEmitter.cpp | 12 +- |
| 38 |
- .../utils/TableGen/FixedLenDecoderEmitter.cpp | 398 ++++++++++++++- |
| 39 |
- llvm/utils/TableGen/InstrInfoEmitter.cpp | 173 ++++++- |
| 40 |
- llvm/utils/TableGen/RegisterInfoEmitter.cpp | 130 ++++- |
| 41 |
- llvm/utils/TableGen/SubtargetEmitter.cpp | 28 +- |
| 42 |
- llvm/utils/TableGen/TableGen.cpp | 12 + |
| 43 |
- llvm/utils/TableGen/TableGenBackends.h | 2 + |
| 44 |
- 17 files changed, 2349 insertions(+), 50 deletions(-) |
| 45 |
- create mode 100644 llvm/0001-capstone-generate-GenRegisterInfo.inc.patch |
| 46 |
- create mode 100644 llvm/0002-capstone-generate-GenSubtargetInfo.inc.patch |
| 47 |
- create mode 100644 llvm/0003-capstone-generate-GenInstrInfo.inc.patch |
| 48 |
- create mode 100644 llvm/0004-capstone-generate-GenDisassemblerTables.inc.patch |
| 49 |
- create mode 100644 llvm/0005-capstone-generate-GenAsmWriter.inc.patch |
| 50 |
- create mode 100644 llvm/0006-capstone-generate-MappingInsn.inc.patch |
| 51 |
- create mode 100644 llvm/0007-capstone-generate-GenInsnNameMaps.inc.patch |
| 52 |
- |
| 53 |
-diff --git a/llvm/0001-capstone-generate-GenRegisterInfo.inc.patch b/llvm/0001-capstone-generate-GenRegisterInfo.inc.patch |
| 54 |
-new file mode 100644 |
| 55 |
-index 000000000..b51aa515a |
| 56 |
---- /dev/null |
| 57 |
-+++ b/llvm/0001-capstone-generate-GenRegisterInfo.inc.patch |
| 58 |
-@@ -0,0 +1,338 @@ |
| 59 |
-+From 5d631cb16e7ba5dd0380ff1ee9dda192b1cdad18 Mon Sep 17 00:00:00 2001 |
| 60 |
-+From: mephi42 <[email protected]> |
| 61 |
-+Date: Tue, 7 Aug 2018 17:02:40 +0200 |
| 62 |
-+Subject: [PATCH 1/7] capstone: generate *GenRegisterInfo.inc |
| 63 |
-+ |
| 64 |
-+--- |
| 65 |
-+ utils/TableGen/RegisterInfoEmitter.cpp | 130 ++++++++++++++++++++++--- |
| 66 |
-+ 1 file changed, 115 insertions(+), 15 deletions(-) |
| 67 |
-+ |
| 68 |
-+diff --git a/utils/TableGen/RegisterInfoEmitter.cpp b/utils/TableGen/RegisterInfoEmitter.cpp |
| 69 |
-+index 49016cca799..6ebb7148b1b 100644 |
| 70 |
-+--- a/utils/TableGen/RegisterInfoEmitter.cpp |
| 71 |
-++++ b/utils/TableGen/RegisterInfoEmitter.cpp |
| 72 |
-+@@ -99,6 +99,12 @@ private: |
| 73 |
-+ |
| 74 |
-+ } // end anonymous namespace |
| 75 |
-+ |
| 76 |
-++#ifdef CAPSTONE |
| 77 |
-++#define NAME_PREFIX Target.getName() << "_" << |
| 78 |
-++#else |
| 79 |
-++#define NAME_PREFIX |
| 80 |
-++#endif |
| 81 |
-++ |
| 82 |
-+ // runEnums - Print out enum values for all of the registers. |
| 83 |
-+ void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 84 |
-+ CodeGenTarget &Target, CodeGenRegBank &Bank) { |
| 85 |
-+@@ -107,13 +113,22 @@ void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 86 |
-+ // Register enums are stored as uint16_t in the tables. Make sure we'll fit. |
| 87 |
-+ assert(Registers.size() <= 0xffff && "Too many regs to fit in tables"); |
| 88 |
-+ |
| 89 |
-++#ifndef CAPSTONE |
| 90 |
-+ StringRef Namespace = Registers.front().TheDef->getValueAsString("Namespace"); |
| 91 |
-++#endif |
| 92 |
-+ |
| 93 |
-+ emitSourceFileHeader("Target Register Enum Values", OS); |
| 94 |
-+ |
| 95 |
-++#ifdef CAPSTONE |
| 96 |
-++ OS << "/* Capstone Disassembly Engine */\n" |
| 97 |
-++ "/* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */\n" |
| 98 |
-++ "\n"; |
| 99 |
-++#endif |
| 100 |
-++ |
| 101 |
-+ OS << "\n#ifdef GET_REGINFO_ENUM\n"; |
| 102 |
-+ OS << "#undef GET_REGINFO_ENUM\n\n"; |
| 103 |
-+ |
| 104 |
-++#ifndef CAPSTONE |
| 105 |
-+ OS << "namespace llvm {\n\n"; |
| 106 |
-+ |
| 107 |
-+ OS << "class MCRegisterClass;\n" |
| 108 |
-+@@ -122,16 +137,20 @@ void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 109 |
-+ |
| 110 |
-+ if (!Namespace.empty()) |
| 111 |
-+ OS << "namespace " << Namespace << " {\n"; |
| 112 |
-+- OS << "enum {\n NoRegister,\n"; |
| 113 |
-++#endif |
| 114 |
-++ |
| 115 |
-++ OS << "enum {\n " << NAME_PREFIX "NoRegister,\n"; |
| 116 |
-+ |
| 117 |
-+ for (const auto &Reg : Registers) |
| 118 |
-+- OS << " " << Reg.getName() << " = " << Reg.EnumValue << ",\n"; |
| 119 |
-++ OS << " " << NAME_PREFIX Reg.getName() << " = " << Reg.EnumValue << ",\n"; |
| 120 |
-+ assert(Registers.size() == Registers.back().EnumValue && |
| 121 |
-+ "Register enum value mismatch!"); |
| 122 |
-+- OS << " NUM_TARGET_REGS \t// " << Registers.size()+1 << "\n"; |
| 123 |
-++ OS << " " << NAME_PREFIX "NUM_TARGET_REGS \t// " << Registers.size()+1 << "\n"; |
| 124 |
-+ OS << "};\n"; |
| 125 |
-++#ifndef CAPSTONE |
| 126 |
-+ if (!Namespace.empty()) |
| 127 |
-+ OS << "} // end namespace " << Namespace << "\n"; |
| 128 |
-++#endif |
| 129 |
-+ |
| 130 |
-+ const auto &RegisterClasses = Bank.getRegClasses(); |
| 131 |
-+ if (!RegisterClasses.empty()) { |
| 132 |
-+@@ -140,18 +159,29 @@ void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 133 |
-+ assert(RegisterClasses.size() <= 0xffff && |
| 134 |
-+ "Too many register classes to fit in tables"); |
| 135 |
-+ |
| 136 |
-+- OS << "\n// Register classes\n\n"; |
| 137 |
-++ OS << "\n// Register classes\n"; |
| 138 |
-++#ifndef CAPSTONE |
| 139 |
-++ OS << "\n"; |
| 140 |
-+ if (!Namespace.empty()) |
| 141 |
-+ OS << "namespace " << Namespace << " {\n"; |
| 142 |
-++#endif |
| 143 |
-+ OS << "enum {\n"; |
| 144 |
-+ for (const auto &RC : RegisterClasses) |
| 145 |
-+- OS << " " << RC.getName() << "RegClassID" |
| 146 |
-++ OS << " " << NAME_PREFIX RC.getName() << "RegClassID" |
| 147 |
-+ << " = " << RC.EnumValue << ",\n"; |
| 148 |
-+- OS << "\n };\n"; |
| 149 |
-++#ifdef CAPSTONE |
| 150 |
-++ OS |
| 151 |
-++#else |
| 152 |
-++ OS << "\n " |
| 153 |
-++#endif |
| 154 |
-++ << "};\n"; |
| 155 |
-++#ifndef CAPSTONE |
| 156 |
-+ if (!Namespace.empty()) |
| 157 |
-+ OS << "} // end namespace " << Namespace << "\n\n"; |
| 158 |
-++#endif |
| 159 |
-+ } |
| 160 |
-+ |
| 161 |
-++#ifndef CAPSTONE |
| 162 |
-+ const std::vector<Record*> &RegAltNameIndices = Target.getRegAltNameIndices(); |
| 163 |
-+ // If the only definition is the default NoRegAltName, we don't need to |
| 164 |
-+ // emit anything. |
| 165 |
-+@@ -182,8 +212,11 @@ void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 166 |
-+ if (!Namespace.empty()) |
| 167 |
-+ OS << "} // end namespace " << Namespace << "\n\n"; |
| 168 |
-+ } |
| 169 |
-++#endif |
| 170 |
-+ |
| 171 |
-++#ifndef CAPSTONE |
| 172 |
-+ OS << "} // end namespace llvm\n\n"; |
| 173 |
-++#endif |
| 174 |
-+ OS << "#endif // GET_REGINFO_ENUM\n\n"; |
| 175 |
-+ } |
| 176 |
-+ |
| 177 |
-+@@ -830,7 +863,9 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 178 |
-+ |
| 179 |
-+ const auto &Regs = RegBank.getRegisters(); |
| 180 |
-+ |
| 181 |
-++#ifndef CAPSTONE |
| 182 |
-+ auto &SubRegIndices = RegBank.getSubRegIndices(); |
| 183 |
-++#endif |
| 184 |
-+ // The lists of sub-registers and super-registers go in the same array. That |
| 185 |
-+ // allows us to share suffixes. |
| 186 |
-+ typedef std::vector<const CodeGenRegister*> RegVec; |
| 187 |
-+@@ -922,25 +957,40 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 188 |
-+ LaneMaskSeqs.layout(); |
| 189 |
-+ SubRegIdxSeqs.layout(); |
| 190 |
-+ |
| 191 |
-++#ifndef CAPSTONE |
| 192 |
-+ OS << "namespace llvm {\n\n"; |
| 193 |
-++#endif |
| 194 |
-+ |
| 195 |
-+ const std::string &TargetName = Target.getName(); |
| 196 |
-+ |
| 197 |
-+ // Emit the shared table of differential lists. |
| 198 |
-+- OS << "extern const MCPhysReg " << TargetName << "RegDiffLists[] = {\n"; |
| 199 |
-++#ifdef CAPSTONE |
| 200 |
-++ OS << "static" |
| 201 |
-++#else |
| 202 |
-++ OS << "extern" |
| 203 |
-++#endif |
| 204 |
-++ << " const MCPhysReg " << TargetName << "RegDiffLists[] = {\n"; |
| 205 |
-+ DiffSeqs.emit(OS, printDiff16); |
| 206 |
-+ OS << "};\n\n"; |
| 207 |
-+ |
| 208 |
-++#ifndef CAPSTONE |
| 209 |
-+ // Emit the shared table of regunit lane mask sequences. |
| 210 |
-+ OS << "extern const LaneBitmask " << TargetName << "LaneMaskLists[] = {\n"; |
| 211 |
-+ LaneMaskSeqs.emit(OS, printMask, "LaneBitmask::getAll()"); |
| 212 |
-+ OS << "};\n\n"; |
| 213 |
-++#endif |
| 214 |
-+ |
| 215 |
-+ // Emit the table of sub-register indexes. |
| 216 |
-+- OS << "extern const uint16_t " << TargetName << "SubRegIdxLists[] = {\n"; |
| 217 |
-++#ifdef CAPSTONE |
| 218 |
-++ OS << "static" |
| 219 |
-++#else |
| 220 |
-++ OS << "extern" |
| 221 |
-++#endif |
| 222 |
-++ << " const uint16_t " << TargetName << "SubRegIdxLists[] = {\n"; |
| 223 |
-+ SubRegIdxSeqs.emit(OS, printSubRegIndex); |
| 224 |
-+ OS << "};\n\n"; |
| 225 |
-+ |
| 226 |
-++#ifndef CAPSTONE |
| 227 |
-+ // Emit the table of sub-register index sizes. |
| 228 |
-+ OS << "extern const MCRegisterInfo::SubRegCoveredBits " |
| 229 |
-+ << TargetName << "SubRegIdxRanges[] = {\n"; |
| 230 |
-+@@ -950,14 +1000,22 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 231 |
-+ << Idx.getName() << "\n"; |
| 232 |
-+ } |
| 233 |
-+ OS << "};\n\n"; |
| 234 |
-++#endif |
| 235 |
-+ |
| 236 |
-+ // Emit the string table. |
| 237 |
-+ RegStrings.layout(); |
| 238 |
-++#ifndef CAPSTONE |
| 239 |
-+ OS << "extern const char " << TargetName << "RegStrings[] = {\n"; |
| 240 |
-+ RegStrings.emit(OS, printChar); |
| 241 |
-+ OS << "};\n\n"; |
| 242 |
-++#endif |
| 243 |
-+ |
| 244 |
-+- OS << "extern const MCRegisterDesc " << TargetName |
| 245 |
-++#ifdef CAPSTONE |
| 246 |
-++ OS << "static" |
| 247 |
-++#else |
| 248 |
-++ OS << "extern" |
| 249 |
-++#endif |
| 250 |
-++ << " const MCRegisterDesc " << TargetName |
| 251 |
-+ << "RegDesc[] = { // Descriptors\n"; |
| 252 |
-+ OS << " { " << RegStrings.get("") << ", 0, 0, 0, 0, 0 },\n"; |
| 253 |
-+ |
| 254 |
-+@@ -973,6 +1031,7 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 255 |
-+ } |
| 256 |
-+ OS << "};\n\n"; // End of register descriptors... |
| 257 |
-+ |
| 258 |
-++#ifndef CAPSTONE |
| 259 |
-+ // Emit the table of register unit roots. Each regunit has one or two root |
| 260 |
-+ // registers. |
| 261 |
-+ OS << "extern const MCPhysReg " << TargetName << "RegUnitRoots[][2] = {\n"; |
| 262 |
-+@@ -986,11 +1045,14 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 263 |
-+ OS << " },\n"; |
| 264 |
-+ } |
| 265 |
-+ OS << "};\n\n"; |
| 266 |
-++#endif |
| 267 |
-+ |
| 268 |
-+ const auto &RegisterClasses = RegBank.getRegClasses(); |
| 269 |
-+ |
| 270 |
-+ // Loop over all of the register classes... emitting each one. |
| 271 |
-++#ifndef CAPSTONE |
| 272 |
-+ OS << "namespace { // Register classes...\n"; |
| 273 |
-++#endif |
| 274 |
-+ |
| 275 |
-+ SequenceToOffsetTable<std::string> RegClassStrings; |
| 276 |
-+ |
| 277 |
-+@@ -1005,15 +1067,28 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 278 |
-+ |
| 279 |
-+ // Emit the register list now. |
| 280 |
-+ OS << " // " << Name << " Register Class...\n" |
| 281 |
-+- << " const MCPhysReg " << Name |
| 282 |
-++ << " " |
| 283 |
-++#ifdef CAPSTONE |
| 284 |
-++ << "static " |
| 285 |
-++#endif |
| 286 |
-++ << "const MCPhysReg " << Name |
| 287 |
-+ << "[] = {\n "; |
| 288 |
-+ for (Record *Reg : Order) { |
| 289 |
-+- OS << getQualifiedName(Reg) << ", "; |
| 290 |
-++#ifdef CAPSTONE |
| 291 |
-++ OS << NAME_PREFIX Reg->getName() |
| 292 |
-++#else |
| 293 |
-++ OS << getQualifiedName(Reg) |
| 294 |
-++#endif |
| 295 |
-++ << ", "; |
| 296 |
-+ } |
| 297 |
-+ OS << "\n };\n\n"; |
| 298 |
-+ |
| 299 |
-+ OS << " // " << Name << " Bit set.\n" |
| 300 |
-+- << " const uint8_t " << Name |
| 301 |
-++ << " " |
| 302 |
-++#ifdef CAPSTONE |
| 303 |
-++ << "static " |
| 304 |
-++#endif |
| 305 |
-++ << "const uint8_t " << Name |
| 306 |
-+ << "Bits[] = {\n "; |
| 307 |
-+ BitVectorEmitter BVE; |
| 308 |
-+ for (Record *Reg : Order) { |
| 309 |
-+@@ -1023,14 +1098,23 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 310 |
-+ OS << "\n };\n\n"; |
| 311 |
-+ |
| 312 |
-+ } |
| 313 |
-++#ifndef CAPSTONE |
| 314 |
-+ OS << "} // end anonymous namespace\n\n"; |
| 315 |
-++#endif |
| 316 |
-+ |
| 317 |
-+ RegClassStrings.layout(); |
| 318 |
-++#ifndef CAPSTONE |
| 319 |
-+ OS << "extern const char " << TargetName << "RegClassStrings[] = {\n"; |
| 320 |
-+ RegClassStrings.emit(OS, printChar); |
| 321 |
-+ OS << "};\n\n"; |
| 322 |
-++#endif |
| 323 |
-+ |
| 324 |
-+- OS << "extern const MCRegisterClass " << TargetName |
| 325 |
-++#ifdef CAPSTONE |
| 326 |
-++ OS << "static" |
| 327 |
-++#else |
| 328 |
-++ OS << "extern" |
| 329 |
-++#endif |
| 330 |
-++ << " const MCRegisterClass " << TargetName |
| 331 |
-+ << "MCRegisterClasses[] = {\n"; |
| 332 |
-+ |
| 333 |
-+ for (const auto &RC : RegisterClasses) { |
| 334 |
-+@@ -1041,7 +1125,12 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 335 |
-+ OS << " { " << RC.getName() << ", " << RC.getName() << "Bits, " |
| 336 |
-+ << RegClassStrings.get(RC.getName()) << ", " |
| 337 |
-+ << RC.getOrder().size() << ", sizeof(" << RC.getName() << "Bits), " |
| 338 |
-+- << RC.getQualifiedName() + "RegClassID" << ", " |
| 339 |
-++#ifdef CAPSTONE |
| 340 |
-++ << NAME_PREFIX RC.getName() |
| 341 |
-++#else |
| 342 |
-++ << RC.getQualifiedName() |
| 343 |
-++#endif |
| 344 |
-++ << "RegClassID" << ", " |
| 345 |
-+ << RegSize/8 << ", " |
| 346 |
-+ << RC.CopyCost << ", " |
| 347 |
-+ << ( RC.Allocatable ? "true" : "false" ) << " },\n"; |
| 348 |
-+@@ -1049,6 +1138,7 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 349 |
-+ |
| 350 |
-+ OS << "};\n\n"; |
| 351 |
-+ |
| 352 |
-++#ifndef CAPSTONE |
| 353 |
-+ EmitRegMappingTables(OS, Regs, false); |
| 354 |
-+ |
| 355 |
-+ // Emit Reg encoding table |
| 356 |
-+@@ -1067,7 +1157,9 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 357 |
-+ OS << " " << Value << ",\n"; |
| 358 |
-+ } |
| 359 |
-+ OS << "};\n"; // End of HW encoding table |
| 360 |
-++#endif |
| 361 |
-+ |
| 362 |
-++#ifndef CAPSTONE |
| 363 |
-+ // MCRegisterInfo initialization routine. |
| 364 |
-+ OS << "static inline void Init" << TargetName |
| 365 |
-+ << "MCRegisterInfo(MCRegisterInfo *RI, unsigned RA, " |
| 366 |
-+@@ -1088,7 +1180,12 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 367 |
-+ OS << "}\n\n"; |
| 368 |
-+ |
| 369 |
-+ OS << "} // end namespace llvm\n\n"; |
| 370 |
-+- OS << "#endif // GET_REGINFO_MC_DESC\n\n"; |
| 371 |
-++#endif |
| 372 |
-++ OS << "#endif // GET_REGINFO_MC_DESC\n" |
| 373 |
-++#ifndef CAPSTONE |
| 374 |
-++ << "\n" |
| 375 |
-++#endif |
| 376 |
-++ ; |
| 377 |
-+ } |
| 378 |
-+ |
| 379 |
-+ void |
| 380 |
-+@@ -1568,10 +1665,13 @@ RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 381 |
-+ |
| 382 |
-+ void RegisterInfoEmitter::run(raw_ostream &OS) { |
| 383 |
-+ CodeGenRegBank &RegBank = Target.getRegBank(); |
| 384 |
-++ |
| 385 |
-+ runEnums(OS, Target, RegBank); |
| 386 |
-+ runMCDesc(OS, Target, RegBank); |
| 387 |
-++#ifndef CAPSTONE |
| 388 |
-+ runTargetHeader(OS, Target, RegBank); |
| 389 |
-+ runTargetDesc(OS, Target, RegBank); |
| 390 |
-++#endif |
| 391 |
-+ |
| 392 |
-+ if (RegisterInfoDebug) |
| 393 |
-+ debugDump(errs()); |
| 394 |
-+-- |
| 395 |
-+2.19.1 |
| 396 |
-+ |
| 397 |
-diff --git a/llvm/0002-capstone-generate-GenSubtargetInfo.inc.patch b/llvm/0002-capstone-generate-GenSubtargetInfo.inc.patch |
| 398 |
-new file mode 100644 |
| 399 |
-index 000000000..56ad28256 |
| 400 |
---- /dev/null |
| 401 |
-+++ b/llvm/0002-capstone-generate-GenSubtargetInfo.inc.patch |
| 402 |
-@@ -0,0 +1,86 @@ |
| 403 |
-+From 46ca491e1bbbc9ace2a91fe6a7b112c83b9b88cc Mon Sep 17 00:00:00 2001 |
| 404 |
-+From: mephi42 <[email protected]> |
| 405 |
-+Date: Tue, 7 Aug 2018 17:42:59 +0200 |
| 406 |
-+Subject: [PATCH 2/7] capstone: generate *GenSubtargetInfo.inc |
| 407 |
-+ |
| 408 |
-+--- |
| 409 |
-+ utils/TableGen/SubtargetEmitter.cpp | 28 +++++++++++++++++++++++++++- |
| 410 |
-+ 1 file changed, 27 insertions(+), 1 deletion(-) |
| 411 |
-+ |
| 412 |
-+diff --git a/utils/TableGen/SubtargetEmitter.cpp b/utils/TableGen/SubtargetEmitter.cpp |
| 413 |
-+index c5da8d8142f..98ab3240472 100644 |
| 414 |
-+--- a/utils/TableGen/SubtargetEmitter.cpp |
| 415 |
-++++ b/utils/TableGen/SubtargetEmitter.cpp |
| 416 |
-+@@ -147,7 +147,9 @@ void SubtargetEmitter::Enumeration(raw_ostream &OS) { |
| 417 |
-+ if (N > MAX_SUBTARGET_FEATURES) |
| 418 |
-+ PrintFatalError("Too many subtarget features! Bump MAX_SUBTARGET_FEATURES."); |
| 419 |
-+ |
| 420 |
-++#ifndef CAPSTONE |
| 421 |
-+ OS << "namespace " << Target << " {\n"; |
| 422 |
-++#endif |
| 423 |
-+ |
| 424 |
-+ // Open enumeration. |
| 425 |
-+ OS << "enum {\n"; |
| 426 |
-+@@ -158,12 +160,22 @@ void SubtargetEmitter::Enumeration(raw_ostream &OS) { |
| 427 |
-+ Record *Def = DefList[i]; |
| 428 |
-+ |
| 429 |
-+ // Get and emit name |
| 430 |
-+- OS << " " << Def->getName() << " = " << i << ",\n"; |
| 431 |
-++ OS << " " |
| 432 |
-++#ifdef CAPSTONE |
| 433 |
-++ << Target << "_" |
| 434 |
-++#endif |
| 435 |
-++ << Def->getName() << " = " |
| 436 |
-++#ifdef CAPSTONE |
| 437 |
-++ << "1ULL << " |
| 438 |
-++#endif |
| 439 |
-++ << i << ",\n"; |
| 440 |
-+ } |
| 441 |
-+ |
| 442 |
-+ // Close enumeration and namespace |
| 443 |
-+ OS << "};\n"; |
| 444 |
-++#ifndef CAPSTONE |
| 445 |
-+ OS << "} // end namespace " << Target << "\n"; |
| 446 |
-++#endif |
| 447 |
-+ } |
| 448 |
-+ |
| 449 |
-+ // |
| 450 |
-+@@ -1709,14 +1721,27 @@ void SubtargetEmitter::emitGenMCSubtargetInfo(raw_ostream &OS) { |
| 451 |
-+ void SubtargetEmitter::run(raw_ostream &OS) { |
| 452 |
-+ emitSourceFileHeader("Subtarget Enumeration Source Fragment", OS); |
| 453 |
-+ |
| 454 |
-++#ifdef CAPSTONE |
| 455 |
-++ OS << "/* Capstone Disassembly Engine, http://www.capstone-engine.org */\n" |
| 456 |
-++ "/* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */\n" |
| 457 |
-++ "\n"; |
| 458 |
-++#endif |
| 459 |
-++ |
| 460 |
-+ OS << "\n#ifdef GET_SUBTARGETINFO_ENUM\n"; |
| 461 |
-+ OS << "#undef GET_SUBTARGETINFO_ENUM\n\n"; |
| 462 |
-+ |
| 463 |
-++#ifndef CAPSTONE |
| 464 |
-+ OS << "namespace llvm {\n"; |
| 465 |
-++#endif |
| 466 |
-+ Enumeration(OS); |
| 467 |
-++#ifdef CAPSTONE |
| 468 |
-++ OS << "\n"; |
| 469 |
-++#else |
| 470 |
-+ OS << "} // end namespace llvm\n\n"; |
| 471 |
-++#endif |
| 472 |
-+ OS << "#endif // GET_SUBTARGETINFO_ENUM\n\n"; |
| 473 |
-+ |
| 474 |
-++#ifndef CAPSTONE |
| 475 |
-+ OS << "\n#ifdef GET_SUBTARGETINFO_MC_DESC\n"; |
| 476 |
-+ OS << "#undef GET_SUBTARGETINFO_MC_DESC\n\n"; |
| 477 |
-+ |
| 478 |
-+@@ -1857,6 +1882,7 @@ void SubtargetEmitter::run(raw_ostream &OS) { |
| 479 |
-+ OS << "} // end namespace llvm\n\n"; |
| 480 |
-+ |
| 481 |
-+ OS << "#endif // GET_SUBTARGETINFO_CTOR\n\n"; |
| 482 |
-++#endif |
| 483 |
-+ } |
| 484 |
-+ |
| 485 |
-+ namespace llvm { |
| 486 |
-+-- |
| 487 |
-+2.19.1 |
| 488 |
-+ |
| 489 |
-diff --git a/llvm/0003-capstone-generate-GenInstrInfo.inc.patch b/llvm/0003-capstone-generate-GenInstrInfo.inc.patch |
| 490 |
-new file mode 100644 |
| 491 |
-index 000000000..2baa59fc9 |
| 492 |
---- /dev/null |
| 493 |
-+++ b/llvm/0003-capstone-generate-GenInstrInfo.inc.patch |
| 494 |
-@@ -0,0 +1,130 @@ |
| 495 |
-+From a73fe8ac18d3ca81fa7a8d8c404cd7e0faf92ddc Mon Sep 17 00:00:00 2001 |
| 496 |
-+From: mephi42 <[email protected]> |
| 497 |
-+Date: Tue, 7 Aug 2018 17:59:43 +0200 |
| 498 |
-+Subject: [PATCH 3/7] capstone: generate *GenInstrInfo.inc |
| 499 |
-+ |
| 500 |
-+--- |
| 501 |
-+ utils/TableGen/InstrInfoEmitter.cpp | 49 ++++++++++++++++++++++++++--- |
| 502 |
-+ 1 file changed, 44 insertions(+), 5 deletions(-) |
| 503 |
-+ |
| 504 |
-+diff --git a/utils/TableGen/InstrInfoEmitter.cpp b/utils/TableGen/InstrInfoEmitter.cpp |
| 505 |
-+index 0aff1aa6f94..2f3a2729262 100644 |
| 506 |
-+--- a/utils/TableGen/InstrInfoEmitter.cpp |
| 507 |
-++++ b/utils/TableGen/InstrInfoEmitter.cpp |
| 508 |
-+@@ -92,6 +92,7 @@ private: |
| 509 |
-+ |
| 510 |
-+ } // end anonymous namespace |
| 511 |
-+ |
| 512 |
-++#ifndef CAPSTONE |
| 513 |
-+ static void PrintDefList(const std::vector<Record*> &Uses, |
| 514 |
-+ unsigned Num, raw_ostream &OS) { |
| 515 |
-+ OS << "static const MCPhysReg ImplicitList" << Num << "[] = { "; |
| 516 |
-+@@ -99,6 +100,7 @@ static void PrintDefList(const std::vector<Record*> &Uses, |
| 517 |
-+ OS << getQualifiedName(U) << ", "; |
| 518 |
-+ OS << "0 };\n"; |
| 519 |
-+ } |
| 520 |
-++#endif |
| 521 |
-+ |
| 522 |
-+ //===----------------------------------------------------------------------===// |
| 523 |
-+ // Operand Info Emission. |
| 524 |
-+@@ -426,8 +428,17 @@ void InstrInfoEmitter::emitTIIHelperMethods(raw_ostream &OS) { |
| 525 |
-+ // run - Emit the main instruction description records for the target... |
| 526 |
-+ void InstrInfoEmitter::run(raw_ostream &OS) { |
| 527 |
-+ emitSourceFileHeader("Target Instruction Enum Values and Descriptors", OS); |
| 528 |
-++ |
| 529 |
-++#ifdef CAPSTONE |
| 530 |
-++ OS << "/* Capstone Disassembly Engine */\n" |
| 531 |
-++ "/* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */\n" |
| 532 |
-++ "\n" |
| 533 |
-++ "\n"; |
| 534 |
-++#endif |
| 535 |
-++ |
| 536 |
-+ emitEnums(OS); |
| 537 |
-+ |
| 538 |
-++#ifndef CAPSTONE |
| 539 |
-+ OS << "#ifdef GET_INSTRINFO_MC_DESC\n"; |
| 540 |
-+ OS << "#undef GET_INSTRINFO_MC_DESC\n"; |
| 541 |
-+ |
| 542 |
-+@@ -545,6 +556,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) { |
| 543 |
-+ emitOperandTypesEnum(OS, Target); |
| 544 |
-+ |
| 545 |
-+ emitMCIIHelperMethods(OS); |
| 546 |
-++#endif |
| 547 |
-+ } |
| 548 |
-+ |
| 549 |
-+ void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num, |
| 550 |
-+@@ -659,7 +671,9 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) { |
| 551 |
-+ OS << "#ifdef GET_INSTRINFO_ENUM\n"; |
| 552 |
-+ OS << "#undef GET_INSTRINFO_ENUM\n"; |
| 553 |
-+ |
| 554 |
-++#ifndef CAPSTONE |
| 555 |
-+ OS << "namespace llvm {\n\n"; |
| 556 |
-++#endif |
| 557 |
-+ |
| 558 |
-+ CodeGenTarget Target(Records); |
| 559 |
-+ |
| 560 |
-+@@ -669,17 +683,39 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) { |
| 561 |
-+ if (Namespace.empty()) |
| 562 |
-+ PrintFatalError("No instructions defined!"); |
| 563 |
-+ |
| 564 |
-++#ifndef CAPSTONE |
| 565 |
-+ OS << "namespace " << Namespace << " {\n"; |
| 566 |
-+- OS << " enum {\n"; |
| 567 |
-++#endif |
| 568 |
-++#ifdef CAPSTONE |
| 569 |
-++ OS << "\n" |
| 570 |
-++#else |
| 571 |
-++ OS << " " |
| 572 |
-++#endif |
| 573 |
-++ << "enum {\n"; |
| 574 |
-+ unsigned Num = 0; |
| 575 |
-+ for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) |
| 576 |
-+- OS << " " << Inst->TheDef->getName() << "\t= " << Num++ << ",\n"; |
| 577 |
-+- OS << " INSTRUCTION_LIST_END = " << Num << "\n"; |
| 578 |
-++ OS << " " |
| 579 |
-++#ifdef CAPSTONE |
| 580 |
-++ << Target.getName() << "_" |
| 581 |
-++#endif |
| 582 |
-++ << Inst->TheDef->getName() << "\t= " << Num++ << ",\n"; |
| 583 |
-++ OS << " " |
| 584 |
-++#ifdef CAPSTONE |
| 585 |
-++ << Target.getName() << "_" |
| 586 |
-++#endif |
| 587 |
-++ << "INSTRUCTION_LIST_END = " << Num << "\n"; |
| 588 |
-+ OS << " };\n\n"; |
| 589 |
-++#ifndef CAPSTONE |
| 590 |
-+ OS << "} // end " << Namespace << " namespace\n"; |
| 591 |
-+ OS << "} // end llvm namespace\n"; |
| 592 |
-+- OS << "#endif // GET_INSTRINFO_ENUM\n\n"; |
| 593 |
-+- |
| 594 |
-++#endif |
| 595 |
-++ OS << "#endif // GET_INSTRINFO_ENUM\n" |
| 596 |
-++#ifndef CAPSTONE |
| 597 |
-++ << "\n" |
| 598 |
-++#endif |
| 599 |
-++ ; |
| 600 |
-++ |
| 601 |
-++#ifndef CAPSTONE |
| 602 |
-+ OS << "#ifdef GET_INSTRINFO_SCHED_ENUM\n"; |
| 603 |
-+ OS << "#undef GET_INSTRINFO_SCHED_ENUM\n"; |
| 604 |
-+ OS << "namespace llvm {\n\n"; |
| 605 |
-+@@ -696,13 +732,16 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) { |
| 606 |
-+ OS << "} // end llvm namespace\n"; |
| 607 |
-+ |
| 608 |
-+ OS << "#endif // GET_INSTRINFO_SCHED_ENUM\n\n"; |
| 609 |
-++#endif |
| 610 |
-+ } |
| 611 |
-+ |
| 612 |
-+ namespace llvm { |
| 613 |
-+ |
| 614 |
-+ void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) { |
| 615 |
-+ InstrInfoEmitter(RK).run(OS); |
| 616 |
-++#ifndef CAPSTONE |
| 617 |
-+ EmitMapTable(RK, OS); |
| 618 |
-++#endif |
| 619 |
-+ } |
| 620 |
-+ |
| 621 |
-+ } // end llvm namespace |
| 622 |
-+-- |
| 623 |
-+2.19.1 |
| 624 |
-+ |
| 625 |
-diff --git a/llvm/0004-capstone-generate-GenDisassemblerTables.inc.patch b/llvm/0004-capstone-generate-GenDisassemblerTables.inc.patch |
| 626 |
-new file mode 100644 |
| 627 |
-index 000000000..0002b81b4 |
| 628 |
---- /dev/null |
| 629 |
-+++ b/llvm/0004-capstone-generate-GenDisassemblerTables.inc.patch |
| 630 |
-@@ -0,0 +1,472 @@ |
| 631 |
-+From 29da4c6929679b8ac4019767ab4ebcd83c9894b4 Mon Sep 17 00:00:00 2001 |
| 632 |
-+From: mephi42 <[email protected]> |
| 633 |
-+Date: Tue, 7 Aug 2018 18:20:17 +0200 |
| 634 |
-+Subject: [PATCH 4/7] capstone: generate *GenDisassemblerTables.inc |
| 635 |
-+ |
| 636 |
-+--- |
| 637 |
-+ utils/TableGen/DisassemblerEmitter.cpp | 12 +- |
| 638 |
-+ utils/TableGen/FixedLenDecoderEmitter.cpp | 248 ++++++++++++++++++++-- |
| 639 |
-+ 2 files changed, 239 insertions(+), 21 deletions(-) |
| 640 |
-+ |
| 641 |
-+diff --git a/utils/TableGen/DisassemblerEmitter.cpp b/utils/TableGen/DisassemblerEmitter.cpp |
| 642 |
-+index b99a0a973a2..2ac6d89645c 100644 |
| 643 |
-+--- a/utils/TableGen/DisassemblerEmitter.cpp |
| 644 |
-++++ b/utils/TableGen/DisassemblerEmitter.cpp |
| 645 |
-+@@ -106,6 +106,11 @@ extern void EmitFixedLenDecoder(RecordKeeper &RK, raw_ostream &OS, |
| 646 |
-+ void EmitDisassembler(RecordKeeper &Records, raw_ostream &OS) { |
| 647 |
-+ CodeGenTarget Target(Records); |
| 648 |
-+ emitSourceFileHeader(" * " + Target.getName().str() + " Disassembler", OS); |
| 649 |
-++#ifdef CAPSTONE |
| 650 |
-++ OS << "/* Capstone Disassembly Engine */\n" |
| 651 |
-++ "/* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */\n" |
| 652 |
-++ "\n"; |
| 653 |
-++#endif |
| 654 |
-+ |
| 655 |
-+ // X86 uses a custom disassembler. |
| 656 |
-+ if (Target.getName() == "X86") { |
| 657 |
-+@@ -150,7 +155,12 @@ void EmitDisassembler(RecordKeeper &Records, raw_ostream &OS) { |
| 658 |
-+ } |
| 659 |
-+ |
| 660 |
-+ EmitFixedLenDecoder(Records, OS, Target.getName(), |
| 661 |
-+- "if (", " == MCDisassembler::Fail)", |
| 662 |
-++ "if (", |
| 663 |
-++#ifdef CAPSTONE |
| 664 |
-++ " == MCDisassembler_Fail)", |
| 665 |
-++#else |
| 666 |
-++ " == MCDisassembler::Fail)", |
| 667 |
-++#endif |
| 668 |
-+ "MCDisassembler::Success", "MCDisassembler::Fail", ""); |
| 669 |
-+ } |
| 670 |
-+ |
| 671 |
-+diff --git a/utils/TableGen/FixedLenDecoderEmitter.cpp b/utils/TableGen/FixedLenDecoderEmitter.cpp |
| 672 |
-+index fcecc764d44..36845d960d8 100644 |
| 673 |
-+--- a/utils/TableGen/FixedLenDecoderEmitter.cpp |
| 674 |
-++++ b/utils/TableGen/FixedLenDecoderEmitter.cpp |
| 675 |
-+@@ -730,7 +730,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 676 |
-+ ++I; |
| 677 |
-+ unsigned Start = *I++; |
| 678 |
-+ unsigned Len = *I++; |
| 679 |
-+- OS.indent(Indentation) << "MCD::OPC_ExtractField, " << Start << ", " |
| 680 |
-++ OS.indent(Indentation) |
| 681 |
-++#ifdef CAPSTONE |
| 682 |
-++ << "MCD_OPC_ExtractField" |
| 683 |
-++#else |
| 684 |
-++ << "MCD::OPC_ExtractField" |
| 685 |
-++#endif |
| 686 |
-++ << ", " << Start << ", " |
| 687 |
-+ << Len << ", // Inst{"; |
| 688 |
-+ if (Len > 1) |
| 689 |
-+ OS << (Start + Len - 1) << "-"; |
| 690 |
-+@@ -739,7 +745,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 691 |
-+ } |
| 692 |
-+ case MCD::OPC_FilterValue: { |
| 693 |
-+ ++I; |
| 694 |
-+- OS.indent(Indentation) << "MCD::OPC_FilterValue, "; |
| 695 |
-++ OS.indent(Indentation) |
| 696 |
-++#ifdef CAPSTONE |
| 697 |
-++ << "MCD_OPC_FilterValue" |
| 698 |
-++#else |
| 699 |
-++ << "MCD::OPC_FilterValue" |
| 700 |
-++#endif |
| 701 |
-++ << ", "; |
| 702 |
-+ // The filter value is ULEB128 encoded. |
| 703 |
-+ while (*I >= 128) |
| 704 |
-+ OS << (unsigned)*I++ << ", "; |
| 705 |
-+@@ -759,7 +771,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 706 |
-+ ++I; |
| 707 |
-+ unsigned Start = *I++; |
| 708 |
-+ unsigned Len = *I++; |
| 709 |
-+- OS.indent(Indentation) << "MCD::OPC_CheckField, " << Start << ", " |
| 710 |
-++ OS.indent(Indentation) |
| 711 |
-++#ifdef CAPSTONE |
| 712 |
-++ << "MCD_OPC_CheckField" |
| 713 |
-++#else |
| 714 |
-++ << "MCD::OPC_CheckField" |
| 715 |
-++#endif |
| 716 |
-++ << ", " << Start << ", " |
| 717 |
-+ << Len << ", ";// << Val << ", " << NumToSkip << ",\n"; |
| 718 |
-+ // ULEB128 encoded field value. |
| 719 |
-+ for (; *I >= 128; ++I) |
| 720 |
-+@@ -777,7 +795,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 721 |
-+ } |
| 722 |
-+ case MCD::OPC_CheckPredicate: { |
| 723 |
-+ ++I; |
| 724 |
-+- OS.indent(Indentation) << "MCD::OPC_CheckPredicate, "; |
| 725 |
-++ OS.indent(Indentation) |
| 726 |
-++#ifdef CAPSTONE |
| 727 |
-++ << "MCD_OPC_CheckPredicate" |
| 728 |
-++#else |
| 729 |
-++ << "MCD::OPC_CheckPredicate" |
| 730 |
-++#endif |
| 731 |
-++ << ", "; |
| 732 |
-+ for (; *I >= 128; ++I) |
| 733 |
-+ OS << (unsigned)*I << ", "; |
| 734 |
-+ OS << (unsigned)*I++ << ", "; |
| 735 |
-+@@ -803,7 +827,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 736 |
-+ && "ULEB128 value too large!"); |
| 737 |
-+ // Decode the Opcode value. |
| 738 |
-+ unsigned Opc = decodeULEB128(Buffer); |
| 739 |
-+- OS.indent(Indentation) << "MCD::OPC_" << (IsTry ? "Try" : "") |
| 740 |
-++ OS.indent(Indentation) |
| 741 |
-++#ifdef CAPSTONE |
| 742 |
-++ << "MCD_OPC_" |
| 743 |
-++#else |
| 744 |
-++ << "MCD::OPC_" |
| 745 |
-++#endif |
| 746 |
-++ << (IsTry ? "Try" : "") |
| 747 |
-+ << "Decode, "; |
| 748 |
-+ for (p = Buffer; *p >= 128; ++p) |
| 749 |
-+ OS << (unsigned)*p << ", "; |
| 750 |
-+@@ -837,7 +867,12 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 751 |
-+ } |
| 752 |
-+ case MCD::OPC_SoftFail: { |
| 753 |
-+ ++I; |
| 754 |
-+- OS.indent(Indentation) << "MCD::OPC_SoftFail"; |
| 755 |
-++ OS.indent(Indentation) |
| 756 |
-++#ifdef CAPSTONE |
| 757 |
-++ << "MCD_OPC_SoftFail"; |
| 758 |
-++#else |
| 759 |
-++ << "MCD::OPC_SoftFail"; |
| 760 |
-++#endif |
| 761 |
-+ // Positive mask |
| 762 |
-+ uint64_t Value = 0; |
| 763 |
-+ unsigned Shift = 0; |
| 764 |
-+@@ -869,7 +904,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 765 |
-+ } |
| 766 |
-+ case MCD::OPC_Fail: { |
| 767 |
-+ ++I; |
| 768 |
-+- OS.indent(Indentation) << "MCD::OPC_Fail,\n"; |
| 769 |
-++ OS.indent(Indentation) |
| 770 |
-++#ifdef CAPSTONE |
| 771 |
-++ << "MCD_OPC_Fail" |
| 772 |
-++#else |
| 773 |
-++ << "MCD::OPC_Fail" |
| 774 |
-++#endif |
| 775 |
-++ << ",\n"; |
| 776 |
-+ break; |
| 777 |
-+ } |
| 778 |
-+ } |
| 779 |
-+@@ -884,23 +925,46 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 780 |
-+ void FixedLenDecoderEmitter:: |
| 781 |
-+ emitPredicateFunction(formatted_raw_ostream &OS, PredicateSet &Predicates, |
| 782 |
-+ unsigned Indentation) const { |
| 783 |
-++#ifdef CAPSTONE |
| 784 |
-++ OS.indent(Indentation) << "static bool getbool(uint64_t b)\n"; |
| 785 |
-++ OS.indent(Indentation) << "{\n"; |
| 786 |
-++ OS.indent(Indentation) << "\treturn b != 0;\n"; |
| 787 |
-++ OS.indent(Indentation) << "}\n\n"; |
| 788 |
-++#endif |
| 789 |
-++ |
| 790 |
-+ // The predicate function is just a big switch statement based on the |
| 791 |
-+ // input predicate index. |
| 792 |
-+ OS.indent(Indentation) << "static bool checkDecoderPredicate(unsigned Idx, " |
| 793 |
-++#ifdef CAPSTONE |
| 794 |
-++ << "uint64_t Bits)\n{\n"; |
| 795 |
-++#else |
| 796 |
-+ << "const FeatureBitset& Bits) {\n"; |
| 797 |
-++#endif |
| 798 |
-+ Indentation += 2; |
| 799 |
-+ if (!Predicates.empty()) { |
| 800 |
-+ OS.indent(Indentation) << "switch (Idx) {\n"; |
| 801 |
-+- OS.indent(Indentation) << "default: llvm_unreachable(\"Invalid index!\");\n"; |
| 802 |
-++ OS.indent(Indentation) << "default: " |
| 803 |
-++#ifdef CAPSTONE |
| 804 |
-++ << "// " |
| 805 |
-++#endif |
| 806 |
-++ << "llvm_unreachable(\"Invalid index!\");\n"; |
| 807 |
-+ unsigned Index = 0; |
| 808 |
-+ for (const auto &Predicate : Predicates) { |
| 809 |
-+ OS.indent(Indentation) << "case " << Index++ << ":\n"; |
| 810 |
-+- OS.indent(Indentation+2) << "return (" << Predicate << ");\n"; |
| 811 |
-++ OS.indent(Indentation+2) << "return " |
| 812 |
-++#ifdef CAPSTONE |
| 813 |
-++ << "getbool" |
| 814 |
-++#endif |
| 815 |
-++ << "(" << Predicate << ");\n"; |
| 816 |
-+ } |
| 817 |
-+ OS.indent(Indentation) << "}\n"; |
| 818 |
-+ } else { |
| 819 |
-+ // No case statement to emit |
| 820 |
-+- OS.indent(Indentation) << "llvm_unreachable(\"Invalid index!\");\n"; |
| 821 |
-++ OS.indent(Indentation) |
| 822 |
-++#ifdef CAPSTONE |
| 823 |
-++ << "// " |
| 824 |
-++#endif |
| 825 |
-++ << "llvm_unreachable(\"Invalid index!\");\n"; |
| 826 |
-+ } |
| 827 |
-+ Indentation -= 2; |
| 828 |
-+ OS.indent(Indentation) << "}\n\n"; |
| 829 |
-+@@ -911,23 +975,39 @@ emitDecoderFunction(formatted_raw_ostream &OS, DecoderSet &Decoders, |
| 830 |
-+ unsigned Indentation) const { |
| 831 |
-+ // The decoder function is just a big switch statement based on the |
| 832 |
-+ // input decoder index. |
| 833 |
-++#ifdef CAPSTONE |
| 834 |
-++#define EDF_EOL " \\\n" |
| 835 |
-++ OS.indent(Indentation) << "#define DecodeToMCInst(fname,fieldname, InsnType) \\\n"; |
| 836 |
-++ OS.indent(Indentation) << "static DecodeStatus fname(DecodeStatus S, unsigned Idx, InsnType insn, MCInst *MI, \\\n"; |
| 837 |
-++ OS.indent(Indentation) << " uint64_t Address, const void *Decoder) \\\n"; |
| 838 |
-++ OS.indent(Indentation) << "{ \\\n"; |
| 839 |
-++#else |
| 840 |
-++#define EDF_EOL "\n" |
| 841 |
-+ OS.indent(Indentation) << "template<typename InsnType>\n"; |
| 842 |
-+ OS.indent(Indentation) << "static DecodeStatus decodeToMCInst(DecodeStatus S," |
| 843 |
-+ << " unsigned Idx, InsnType insn, MCInst &MI,\n"; |
| 844 |
-+ OS.indent(Indentation) << " uint64_t " |
| 845 |
-+ << "Address, const void *Decoder, bool &DecodeComplete) {\n"; |
| 846 |
-++#endif |
| 847 |
-+ Indentation += 2; |
| 848 |
-++#ifndef CAPSTONE |
| 849 |
-+ OS.indent(Indentation) << "DecodeComplete = true;\n"; |
| 850 |
-+- OS.indent(Indentation) << "InsnType tmp;\n"; |
| 851 |
-+- OS.indent(Indentation) << "switch (Idx) {\n"; |
| 852 |
-+- OS.indent(Indentation) << "default: llvm_unreachable(\"Invalid index!\");\n"; |
| 853 |
-++#endif |
| 854 |
-++ OS.indent(Indentation) << "InsnType tmp;" EDF_EOL; |
| 855 |
-++ OS.indent(Indentation) << "switch (Idx) {" EDF_EOL; |
| 856 |
-++ OS.indent(Indentation) << "default:" |
| 857 |
-++#ifndef CAPSTONE |
| 858 |
-++ << " llvm_unreachable(\"Invalid index!\");\n"; |
| 859 |
-++#else |
| 860 |
-++ << " \\\n"; |
| 861 |
-++#endif |
| 862 |
-+ unsigned Index = 0; |
| 863 |
-+ for (const auto &Decoder : Decoders) { |
| 864 |
-+- OS.indent(Indentation) << "case " << Index++ << ":\n"; |
| 865 |
-++ OS.indent(Indentation) << "case " << Index++ << ":" EDF_EOL; |
| 866 |
-+ OS << Decoder; |
| 867 |
-+- OS.indent(Indentation+2) << "return S;\n"; |
| 868 |
-++ OS.indent(Indentation+2) << "return S;" EDF_EOL; |
| 869 |
-+ } |
| 870 |
-+- OS.indent(Indentation) << "}\n"; |
| 871 |
-++ OS.indent(Indentation) << "}" EDF_EOL; |
| 872 |
-+ Indentation -= 2; |
| 873 |
-+ OS.indent(Indentation) << "}\n\n"; |
| 874 |
-+ } |
| 875 |
-+@@ -1054,16 +1134,21 @@ void FilterChooser::emitBinaryParser(raw_ostream &o, unsigned &Indentation, |
| 876 |
-+ const std::string &Decoder = OpInfo.Decoder; |
| 877 |
-+ |
| 878 |
-+ if (OpInfo.numFields() != 1) |
| 879 |
-+- o.indent(Indentation) << "tmp = 0;\n"; |
| 880 |
-++ o.indent(Indentation) << "tmp = 0;" EDF_EOL; |
| 881 |
-+ |
| 882 |
-+ for (const EncodingField &EF : OpInfo) { |
| 883 |
-+ o.indent(Indentation) << "tmp "; |
| 884 |
-+ if (OpInfo.numFields() != 1) o << '|'; |
| 885 |
-+- o << "= fieldFromInstruction" |
| 886 |
-++ o << "= " |
| 887 |
-++#ifdef CAPSTONE |
| 888 |
-++ << "fieldname" |
| 889 |
-++#else |
| 890 |
-++ << "fieldFromInstruction" |
| 891 |
-++#endif |
| 892 |
-+ << "(insn, " << EF.Base << ", " << EF.Width << ')'; |
| 893 |
-+ if (OpInfo.numFields() != 1 || EF.Offset != 0) |
| 894 |
-+ o << " << " << EF.Offset; |
| 895 |
-+- o << ";\n"; |
| 896 |
-++ o << ";" EDF_EOL; |
| 897 |
-+ } |
| 898 |
-+ |
| 899 |
-+ if (Decoder != "") { |
| 900 |
-+@@ -1071,8 +1156,12 @@ void FilterChooser::emitBinaryParser(raw_ostream &o, unsigned &Indentation, |
| 901 |
-+ o.indent(Indentation) << Emitter->GuardPrefix << Decoder |
| 902 |
-+ << "(MI, tmp, Address, Decoder)" |
| 903 |
-+ << Emitter->GuardPostfix |
| 904 |
-++#ifdef CAPSTONE |
| 905 |
-++ << " return MCDisassembler_Fail; \\\n"; |
| 906 |
-++#else |
| 907 |
-+ << " { " << (OpHasCompleteDecoder ? "" : "DecodeComplete = false; ") |
| 908 |
-+ << "return MCDisassembler::Fail; }\n"; |
| 909 |
-++#endif |
| 910 |
-+ } else { |
| 911 |
-+ OpHasCompleteDecoder = true; |
| 912 |
-+ o.indent(Indentation) << "MI.addOperand(MCOperand::createImm(tmp));\n"; |
| 913 |
-+@@ -1091,7 +1180,13 @@ void FilterChooser::emitDecoder(raw_ostream &OS, unsigned Indentation, |
| 914 |
-+ << "(MI, insn, Address, Decoder)" |
| 915 |
-+ << Emitter->GuardPostfix |
| 916 |
-+ << " { " << (HasCompleteDecoder ? "" : "DecodeComplete = false; ") |
| 917 |
-+- << "return MCDisassembler::Fail; }\n"; |
| 918 |
-++ << "return " |
| 919 |
-++#ifdef CAPSTONE |
| 920 |
-++ << "MCDisassembler_Fail" |
| 921 |
-++#else |
| 922 |
-++ << "MCDisassembler::Fail" |
| 923 |
-++#endif |
| 924 |
-++ << "; }\n"; |
| 925 |
-+ break; |
| 926 |
-+ } |
| 927 |
-+ |
| 928 |
-+@@ -1129,10 +1224,19 @@ unsigned FilterChooser::getDecoderIndex(DecoderSet &Decoders, |
| 929 |
-+ static void emitSinglePredicateMatch(raw_ostream &o, StringRef str, |
| 930 |
-+ const std::string &PredicateNamespace) { |
| 931 |
-+ if (str[0] == '!') |
| 932 |
-++#ifdef CAPSTONE |
| 933 |
-++ o << "~(Bits & " << PredicateNamespace << "_" |
| 934 |
-++ << str.slice(1,str.size()) << ")"; |
| 935 |
-++#else |
| 936 |
-+ o << "!Bits[" << PredicateNamespace << "::" |
| 937 |
-+ << str.slice(1,str.size()) << "]"; |
| 938 |
-++#endif |
| 939 |
-+ else |
| 940 |
-++#ifdef CAPSTONE |
| 941 |
-++ o << "(Bits & " << PredicateNamespace << "_" << str << ")"; |
| 942 |
-++#else |
| 943 |
-+ o << "Bits[" << PredicateNamespace << "::" << str << "]"; |
| 944 |
-++#endif |
| 945 |
-+ } |
| 946 |
-+ |
| 947 |
-+ bool FilterChooser::emitPredicateMatch(raw_ostream &o, unsigned &Indentation, |
| 948 |
-+@@ -2047,6 +2151,17 @@ static bool populateInstruction(CodeGenTarget &Target, |
| 949 |
-+ // fieldFromInstruction(). |
| 950 |
-+ static void emitFieldFromInstruction(formatted_raw_ostream &OS) { |
| 951 |
-+ OS << "// Helper function for extracting fields from encoded instructions.\n" |
| 952 |
-++#ifdef CAPSTONE |
| 953 |
-++ << "#define FieldFromInstruction(fname, InsnType) \\\n" |
| 954 |
-++ << "static InsnType fname(InsnType insn, unsigned startBit, unsigned numBits) \\\n" |
| 955 |
-++ << "{ \\\n" |
| 956 |
-++ << " InsnType fieldMask; \\\n" |
| 957 |
-++ << " if (numBits == sizeof(InsnType)*8) \\\n" |
| 958 |
-++ << " fieldMask = (InsnType)(-1LL); \\\n" |
| 959 |
-++ << " else \\\n" |
| 960 |
-++ << " fieldMask = (((InsnType)1 << numBits) - 1) << startBit; \\\n" |
| 961 |
-++ << " return (insn & fieldMask) >> startBit; \\\n" |
| 962 |
-++#else |
| 963 |
-+ << "template<typename InsnType>\n" |
| 964 |
-+ << "static InsnType fieldFromInstruction(InsnType insn, unsigned startBit,\n" |
| 965 |
-+ << " unsigned numBits) {\n" |
| 966 |
-+@@ -2058,12 +2173,92 @@ static void emitFieldFromInstruction(formatted_raw_ostream &OS) { |
| 967 |
-+ << " else\n" |
| 968 |
-+ << " fieldMask = (((InsnType)1 << numBits) - 1) << startBit;\n" |
| 969 |
-+ << " return (insn & fieldMask) >> startBit;\n" |
| 970 |
-++#endif |
| 971 |
-+ << "}\n\n"; |
| 972 |
-+ } |
| 973 |
-+ |
| 974 |
-+ // emitDecodeInstruction - Emit the templated helper function |
| 975 |
-+ // decodeInstruction(). |
| 976 |
-+ static void emitDecodeInstruction(formatted_raw_ostream &OS) { |
| 977 |
-++#ifdef CAPSTONE |
| 978 |
-++ OS << "#define DecodeInstruction(fname, fieldname, decoder, InsnType) \\\n" |
| 979 |
-++ << "static DecodeStatus fname(const uint8_t DecodeTable[], MCInst *MI, \\\n" |
| 980 |
-++ << " InsnType insn, uint64_t Address, const MCRegisterInfo *MRI, int feature) \\\n" |
| 981 |
-++ << "{ \\\n" |
| 982 |
-++ << " uint64_t Bits = getFeatureBits(feature); \\\n" |
| 983 |
-++ << " const uint8_t *Ptr = DecodeTable; \\\n" |
| 984 |
-++ << " uint32_t CurFieldValue = 0, ExpectedValue; \\\n" |
| 985 |
-++ << " DecodeStatus S = MCDisassembler_Success; \\\n" |
| 986 |
-++ << " unsigned Start, Len, NumToSkip, PIdx, Opc, DecodeIdx; \\\n" |
| 987 |
-++ << " InsnType Val, FieldValue, PositiveMask, NegativeMask; \\\n" |
| 988 |
-++ << " bool Pred, Fail; \\\n" |
| 989 |
-++ << " for (;;) { \\\n" |
| 990 |
-++ << " switch (*Ptr) { \\\n" |
| 991 |
-++ << " default: \\\n" |
| 992 |
-++ << " return MCDisassembler_Fail; \\\n" |
| 993 |
-++ << " case MCD_OPC_ExtractField: { \\\n" |
| 994 |
-++ << " Start = *++Ptr; \\\n" |
| 995 |
-++ << " Len = *++Ptr; \\\n" |
| 996 |
-++ << " ++Ptr; \\\n" |
| 997 |
-++ << " CurFieldValue = (uint32_t)fieldname(insn, Start, Len); \\\n" |
| 998 |
-++ << " break; \\\n" |
| 999 |
-++ << " } \\\n" |
| 1000 |
-++ << " case MCD_OPC_FilterValue: { \\\n" |
| 1001 |
-++ << " Val = (InsnType)decodeULEB128(++Ptr, &Len); \\\n" |
| 1002 |
-++ << " Ptr += Len; \\\n" |
| 1003 |
-++ << " NumToSkip = *Ptr++; \\\n" |
| 1004 |
-++ << " NumToSkip |= (*Ptr++) << 8; \\\n" |
| 1005 |
-++ << " if (Val != CurFieldValue) \\\n" |
| 1006 |
-++ << " Ptr += NumToSkip; \\\n" |
| 1007 |
-++ << " break; \\\n" |
| 1008 |
-++ << " } \\\n" |
| 1009 |
-++ << " case MCD_OPC_CheckField: { \\\n" |
| 1010 |
-++ << " Start = *++Ptr; \\\n" |
| 1011 |
-++ << " Len = *++Ptr; \\\n" |
| 1012 |
-++ << " FieldValue = fieldname(insn, Start, Len); \\\n" |
| 1013 |
-++ << " ExpectedValue = (uint32_t)decodeULEB128(++Ptr, &Len); \\\n" |
| 1014 |
-++ << " Ptr += Len; \\\n" |
| 1015 |
-++ << " NumToSkip = *Ptr++; \\\n" |
| 1016 |
-++ << " NumToSkip |= (*Ptr++) << 8; \\\n" |
| 1017 |
-++ << " if (ExpectedValue != FieldValue) \\\n" |
| 1018 |
-++ << " Ptr += NumToSkip; \\\n" |
| 1019 |
-++ << " break; \\\n" |
| 1020 |
-++ << " } \\\n" |
| 1021 |
-++ << " case MCD_OPC_CheckPredicate: { \\\n" |
| 1022 |
-++ << " PIdx = (uint32_t)decodeULEB128(++Ptr, &Len); \\\n" |
| 1023 |
-++ << " Ptr += Len; \\\n" |
| 1024 |
-++ << " NumToSkip = *Ptr++; \\\n" |
| 1025 |
-++ << " NumToSkip |= (*Ptr++) << 8; \\\n" |
| 1026 |
-++ << " Pred = checkDecoderPredicate(PIdx, Bits); \\\n" |
| 1027 |
-++ << " if (!Pred) \\\n" |
| 1028 |
-++ << " Ptr += NumToSkip; \\\n" |
| 1029 |
-++ << " (void)Pred; \\\n" |
| 1030 |
-++ << " break; \\\n" |
| 1031 |
-++ << " } \\\n" |
| 1032 |
-++ << " case MCD_OPC_Decode: { \\\n" |
| 1033 |
-++ << " Opc = (unsigned)decodeULEB128(++Ptr, &Len); \\\n" |
| 1034 |
-++ << " Ptr += Len; \\\n" |
| 1035 |
-++ << " DecodeIdx = (unsigned)decodeULEB128(Ptr, &Len); \\\n" |
| 1036 |
-++ << " Ptr += Len; \\\n" |
| 1037 |
-++ << " MCInst_setOpcode(MI, Opc); \\\n" |
| 1038 |
-++ << " return decoder(S, DecodeIdx, insn, MI, Address, MRI); \\\n" |
| 1039 |
-++ << " } \\\n" |
| 1040 |
-++ << " case MCD_OPC_SoftFail: { \\\n" |
| 1041 |
-++ << " PositiveMask = (InsnType)decodeULEB128(++Ptr, &Len); \\\n" |
| 1042 |
-++ << " Ptr += Len; \\\n" |
| 1043 |
-++ << " NegativeMask = (InsnType)decodeULEB128(Ptr, &Len); \\\n" |
| 1044 |
-++ << " Ptr += Len; \\\n" |
| 1045 |
-++ << " Fail = (insn & PositiveMask) || (~insn & NegativeMask); \\\n" |
| 1046 |
-++ << " if (Fail) \\\n" |
| 1047 |
-++ << " S = MCDisassembler_SoftFail; \\\n" |
| 1048 |
-++ << " break; \\\n" |
| 1049 |
-++ << " } \\\n" |
| 1050 |
-++ << " case MCD_OPC_Fail: { \\\n" |
| 1051 |
-++ << " return MCDisassembler_Fail; \\\n" |
| 1052 |
-++ << " } \\\n" |
| 1053 |
-++ << " } \\\n" |
| 1054 |
-++ << " } \\\n" |
| 1055 |
-++#else |
| 1056 |
-+ OS << "template<typename InsnType>\n" |
| 1057 |
-+ << "static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], " |
| 1058 |
-+ "MCInst &MI,\n" |
| 1059 |
-+@@ -2240,12 +2435,18 @@ static void emitDecodeInstruction(formatted_raw_ostream &OS) { |
| 1060 |
-+ << " }\n" |
| 1061 |
-+ << " llvm_unreachable(\"bogosity detected in disassembler state " |
| 1062 |
-+ "machine!\");\n" |
| 1063 |
-++#endif |
| 1064 |
-+ << "}\n\n"; |
| 1065 |
-+ } |
| 1066 |
-+ |
| 1067 |
-+ // Emits disassembler code for instruction decoding. |
| 1068 |
-+ void FixedLenDecoderEmitter::run(raw_ostream &o) { |
| 1069 |
-+ formatted_raw_ostream OS(o); |
| 1070 |
-++#ifdef CAPSTONE |
| 1071 |
-++ OS << "#include \"../../MCInst.h\"\n"; |
| 1072 |
-++ OS << "#include \"../../LEB128.h\"\n"; |
| 1073 |
-++ OS << "\n"; |
| 1074 |
-++#else |
| 1075 |
-+ OS << "#include \"llvm/MC/MCInst.h\"\n"; |
| 1076 |
-+ OS << "#include \"llvm/Support/Debug.h\"\n"; |
| 1077 |
-+ OS << "#include \"llvm/Support/DataTypes.h\"\n"; |
| 1078 |
-+@@ -2254,6 +2455,7 @@ void FixedLenDecoderEmitter::run(raw_ostream &o) { |
| 1079 |
-+ OS << "#include <assert.h>\n"; |
| 1080 |
-+ OS << '\n'; |
| 1081 |
-+ OS << "namespace llvm {\n\n"; |
| 1082 |
-++#endif |
| 1083 |
-+ |
| 1084 |
-+ emitFieldFromInstruction(OS); |
| 1085 |
-+ |
| 1086 |
-+@@ -2322,7 +2524,13 @@ void FixedLenDecoderEmitter::run(raw_ostream &o) { |
| 1087 |
-+ // Emit the main entry point for the decoder, decodeInstruction(). |
| 1088 |
-+ emitDecodeInstruction(OS); |
| 1089 |
-+ |
| 1090 |
-++#ifdef CAPSTONE |
| 1091 |
-++ OS << "FieldFromInstruction(fieldFromInstruction, uint64_t)\n"; |
| 1092 |
-++ OS << "DecodeToMCInst(decodeToMCInst, fieldFromInstruction, uint64_t)\n"; |
| 1093 |
-++ OS << "DecodeInstruction(decodeInstruction, fieldFromInstruction, decodeToMCInst, uint64_t)\n"; |
| 1094 |
-++#else |
| 1095 |
-+ OS << "\n} // End llvm namespace\n"; |
| 1096 |
-++#endif |
| 1097 |
-+ } |
| 1098 |
-+ |
| 1099 |
-+ namespace llvm { |
| 1100 |
-+-- |
| 1101 |
-+2.19.1 |
| 1102 |
-+ |
| 1103 |
-diff --git a/llvm/0005-capstone-generate-GenAsmWriter.inc.patch b/llvm/0005-capstone-generate-GenAsmWriter.inc.patch |
| 1104 |
-new file mode 100644 |
| 1105 |
-index 000000000..cd1353eb7 |
| 1106 |
---- /dev/null |
| 1107 |
-+++ b/llvm/0005-capstone-generate-GenAsmWriter.inc.patch |
| 1108 |
-@@ -0,0 +1,225 @@ |
| 1109 |
-+From 5569e48b9cb34a33910e1e850fbfabc999f016a2 Mon Sep 17 00:00:00 2001 |
| 1110 |
-+From: mephi42 <[email protected]> |
| 1111 |
-+Date: Tue, 7 Aug 2018 20:00:08 +0200 |
| 1112 |
-+Subject: [PATCH 5/7] capstone: generate *GenAsmWriter.inc |
| 1113 |
-+ |
| 1114 |
-+--- |
| 1115 |
-+ utils/TableGen/AsmWriterEmitter.cpp | 89 +++++++++++++++++++++++++++-- |
| 1116 |
-+ utils/TableGen/AsmWriterInst.cpp | 4 ++ |
| 1117 |
-+ 2 files changed, 87 insertions(+), 6 deletions(-) |
| 1118 |
-+ |
| 1119 |
-+diff --git a/utils/TableGen/AsmWriterEmitter.cpp b/utils/TableGen/AsmWriterEmitter.cpp |
| 1120 |
-+index 3c4c9c8e5c6..133800d217c 100644 |
| 1121 |
-+--- a/utils/TableGen/AsmWriterEmitter.cpp |
| 1122 |
-++++ b/utils/TableGen/AsmWriterEmitter.cpp |
| 1123 |
-+@@ -272,16 +272,22 @@ static void UnescapeString(std::string &Str) { |
| 1124 |
-+ /// clearing the Instructions vector. |
| 1125 |
-+ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { |
| 1126 |
-+ Record *AsmWriter = Target.getAsmWriter(); |
| 1127 |
-++#ifndef CAPSTONE |
| 1128 |
-+ StringRef ClassName = AsmWriter->getValueAsString("AsmWriterClassName"); |
| 1129 |
-++#endif |
| 1130 |
-+ bool PassSubtarget = AsmWriter->getValueAsInt("PassSubtarget"); |
| 1131 |
-+ |
| 1132 |
-+ O << |
| 1133 |
-+ "/// printInstruction - This method is automatically generated by tablegen\n" |
| 1134 |
-+ "/// from the instruction set description.\n" |
| 1135 |
-++#ifdef CAPSTONE |
| 1136 |
-++ "static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)\n{\n"; |
| 1137 |
-++#else |
| 1138 |
-+ "void " << Target.getName() << ClassName |
| 1139 |
-+ << "::printInstruction(const MCInst *MI, " |
| 1140 |
-+ << (PassSubtarget ? "const MCSubtargetInfo &STI, " : "") |
| 1141 |
-+ << "raw_ostream &O) {\n"; |
| 1142 |
-++#endif |
| 1143 |
-+ |
| 1144 |
-+ // Build an aggregate string, and build a table of offsets into it. |
| 1145 |
-+ SequenceToOffsetTable<std::string> StringTable; |
| 1146 |
-+@@ -379,9 +385,16 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { |
| 1147 |
-+ } |
| 1148 |
-+ |
| 1149 |
-+ // Emit the string table itself. |
| 1150 |
-++#ifdef CAPSTONE |
| 1151 |
-++ O << "#ifndef CAPSTONE_DIET\n"; |
| 1152 |
-++#endif |
| 1153 |
-+ O << " static const char AsmStrs[] = {\n"; |
| 1154 |
-+ StringTable.emit(O, printChar); |
| 1155 |
-+- O << " };\n\n"; |
| 1156 |
-++ O << " };\n" |
| 1157 |
-++#ifdef CAPSTONE |
| 1158 |
-++ << "#endif\n" |
| 1159 |
-++#endif |
| 1160 |
-++ << "\n"; |
| 1161 |
-+ |
| 1162 |
-+ // Emit the lookup tables in pieces to minimize wasted bytes. |
| 1163 |
-+ unsigned BytesNeeded = ((OpcodeInfoBits - BitsLeft) + 7) / 8; |
| 1164 |
-+@@ -409,21 +422,45 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { |
| 1165 |
-+ // If the total bits is more than 32-bits we need to use a 64-bit type. |
| 1166 |
-+ if (BitsLeft < (OpcodeInfoBits - 32)) |
| 1167 |
-+ BitsOS << "(uint64_t)"; |
| 1168 |
-+- BitsOS << "OpInfo" << Table << "[MI->getOpcode()] << " << Shift << ";\n"; |
| 1169 |
-++ BitsOS << "OpInfo" << Table << "[" |
| 1170 |
-++#ifdef CAPSTONE |
| 1171 |
-++ << "MCInst_getOpcode(MI)" |
| 1172 |
-++#else |
| 1173 |
-++ << "MI->getOpcode()" |
| 1174 |
-++#endif |
| 1175 |
-++ << "] << " << Shift << ";\n"; |
| 1176 |
-+ // Prepare the shift for the next iteration and increment the table count. |
| 1177 |
-+ Shift += TableSize; |
| 1178 |
-+ ++Table; |
| 1179 |
-+ } |
| 1180 |
-+ |
| 1181 |
-+ // Emit the initial tab character. |
| 1182 |
-++#ifndef CAPSTONE |
| 1183 |
-+ O << " O << \"\\t\";\n\n"; |
| 1184 |
-++#endif |
| 1185 |
-+ |
| 1186 |
-+ O << " // Emit the opcode for the instruction.\n"; |
| 1187 |
-+ O << BitsString; |
| 1188 |
-+ |
| 1189 |
-+ // Emit the starting string. |
| 1190 |
-+- O << " assert(Bits != 0 && \"Cannot print this instruction.\");\n" |
| 1191 |
-+- << " O << AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << ")-1;\n\n"; |
| 1192 |
-++ O << " " |
| 1193 |
-++#ifdef CAPSTONE |
| 1194 |
-++ << "// " |
| 1195 |
-++#endif |
| 1196 |
-++ << "assert(Bits != 0 && \"Cannot print this instruction.\");\n" |
| 1197 |
-++#ifdef CAPSTONE |
| 1198 |
-++ << "#ifndef CAPSTONE_DIET\n" |
| 1199 |
-++ << " SStream_concat0(O, " |
| 1200 |
-++#else |
| 1201 |
-++ << " O << " |
| 1202 |
-++#endif |
| 1203 |
-++ << "AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << ")-1" |
| 1204 |
-++#ifdef CAPSTONE |
| 1205 |
-++ << ");\n" |
| 1206 |
-++ << "#endif\n\n"; |
| 1207 |
-++#else |
| 1208 |
-++ << ");\n\n"; |
| 1209 |
-++#endif |
| 1210 |
-+ |
| 1211 |
-+ // Output the table driven operand information. |
| 1212 |
-+ BitsLeft = OpcodeInfoBits-AsmStrBits; |
| 1213 |
-+@@ -455,7 +492,11 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { |
| 1214 |
-+ O << " switch ((Bits >> " |
| 1215 |
-+ << (OpcodeInfoBits-BitsLeft) << ") & " |
| 1216 |
-+ << ((1 << NumBits)-1) << ") {\n" |
| 1217 |
-+- << " default: llvm_unreachable(\"Invalid command number.\");\n"; |
| 1218 |
-++ << " default: " |
| 1219 |
-++#ifdef CAPSTONE |
| 1220 |
-++ << "// " |
| 1221 |
-++#endif |
| 1222 |
-++ << "llvm_unreachable(\"Invalid command number.\");\n"; |
| 1223 |
-+ |
| 1224 |
-+ // Print out all the cases. |
| 1225 |
-+ for (unsigned j = 0, e = Commands.size(); j != e; ++j) { |
| 1226 |
-+@@ -536,6 +577,9 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName, |
| 1227 |
-+ } |
| 1228 |
-+ |
| 1229 |
-+ StringTable.layout(); |
| 1230 |
-++#ifdef CAPSTONE |
| 1231 |
-++ O << "#ifndef CAPSTONE_DIET\n"; |
| 1232 |
-++#endif |
| 1233 |
-+ O << " static const char AsmStrs" << AltName << "[] = {\n"; |
| 1234 |
-+ StringTable.emit(O, printChar); |
| 1235 |
-+ O << " };\n\n"; |
| 1236 |
-+@@ -552,8 +596,10 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName, |
| 1237 |
-+ } |
| 1238 |
-+ |
| 1239 |
-+ void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) { |
| 1240 |
-++#ifndef CAPSTONE |
| 1241 |
-+ Record *AsmWriter = Target.getAsmWriter(); |
| 1242 |
-+ StringRef ClassName = AsmWriter->getValueAsString("AsmWriterClassName"); |
| 1243 |
-++#endif |
| 1244 |
-+ const auto &Registers = Target.getRegBank().getRegisters(); |
| 1245 |
-+ const std::vector<Record*> &AltNameIndices = Target.getRegAltNameIndices(); |
| 1246 |
-+ bool hasAltNames = AltNameIndices.size() > 1; |
| 1247 |
-+@@ -563,12 +609,20 @@ void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) { |
| 1248 |
-+ "\n\n/// getRegisterName - This method is automatically generated by tblgen\n" |
| 1249 |
-+ "/// from the register set description. This returns the assembler name\n" |
| 1250 |
-+ "/// for the specified register.\n" |
| 1251 |
-++#ifdef CAPSTONE |
| 1252 |
-++ "static const char *getRegisterName(unsigned RegNo)\n{\n"; |
| 1253 |
-++#else |
| 1254 |
-+ "const char *" << Target.getName() << ClassName << "::"; |
| 1255 |
-+ if (hasAltNames) |
| 1256 |
-+ O << "\ngetRegisterName(unsigned RegNo, unsigned AltIdx) {\n"; |
| 1257 |
-+ else |
| 1258 |
-+ O << "getRegisterName(unsigned RegNo) {\n"; |
| 1259 |
-+- O << " assert(RegNo && RegNo < " << (Registers.size()+1) |
| 1260 |
-++#endif |
| 1261 |
-++ O << " " |
| 1262 |
-++#ifdef CAPSTONE |
| 1263 |
-++ << "// " |
| 1264 |
-++#endif |
| 1265 |
-++ << "assert(RegNo && RegNo < " << (Registers.size()+1) |
| 1266 |
-+ << " && \"Invalid register number!\");\n" |
| 1267 |
-+ << "\n"; |
| 1268 |
-+ |
| 1269 |
-+@@ -595,10 +649,22 @@ void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) { |
| 1270 |
-+ } |
| 1271 |
-+ O << " }\n"; |
| 1272 |
-+ } else { |
| 1273 |
-++#ifdef CAPSTONE |
| 1274 |
-++ O << " //int i;\n" |
| 1275 |
-++ << " //for (i = 0; i < sizeof(RegAsmOffset); i++)\n" |
| 1276 |
-++ << " // printf(\"%s = %u\\n\", AsmStrs+RegAsmOffset[i], i + 1);\n" |
| 1277 |
-++ << " //printf(\"*************************\\n\");\n" |
| 1278 |
-++#else |
| 1279 |
-+ O << " assert (*(AsmStrs+RegAsmOffset[RegNo-1]) &&\n" |
| 1280 |
-+ << " \"Invalid alt name index for register!\");\n" |
| 1281 |
-++#endif |
| 1282 |
-+ << " return AsmStrs+RegAsmOffset[RegNo-1];\n"; |
| 1283 |
-+ } |
| 1284 |
-++#ifdef CAPSTONE |
| 1285 |
-++ O << "#else\n" |
| 1286 |
-++ << " return NULL;\n" |
| 1287 |
-++ << "#endif\n"; |
| 1288 |
-++#endif |
| 1289 |
-+ O << "}\n"; |
| 1290 |
-+ } |
| 1291 |
-+ |
| 1292 |
-+@@ -1135,9 +1201,20 @@ AsmWriterEmitter::AsmWriterEmitter(RecordKeeper &R) : Records(R), Target(R) { |
| 1293 |
-+ } |
| 1294 |
-+ |
| 1295 |
-+ void AsmWriterEmitter::run(raw_ostream &O) { |
| 1296 |
-++#ifdef CAPSTONE |
| 1297 |
-++ O << "/* Capstone Disassembly Engine */\n" |
| 1298 |
-++ "/* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */\n" |
| 1299 |
-++ "\n" |
| 1300 |
-++ "#include <stdio.h>\t// debug\n" |
| 1301 |
-++ "#include <capstone/platform.h>\n" |
| 1302 |
-++ "\n" |
| 1303 |
-++ "\n"; |
| 1304 |
-++#endif |
| 1305 |
-+ EmitPrintInstruction(O); |
| 1306 |
-+ EmitGetRegisterName(O); |
| 1307 |
-++#ifndef CAPSTONE |
| 1308 |
-+ EmitPrintAliasInstruction(O); |
| 1309 |
-++#endif |
| 1310 |
-+ } |
| 1311 |
-+ |
| 1312 |
-+ namespace llvm { |
| 1313 |
-+diff --git a/utils/TableGen/AsmWriterInst.cpp b/utils/TableGen/AsmWriterInst.cpp |
| 1314 |
-+index 2c19e5d663d..6fa751e50df 100644 |
| 1315 |
-+--- a/utils/TableGen/AsmWriterInst.cpp |
| 1316 |
-++++ b/utils/TableGen/AsmWriterInst.cpp |
| 1317 |
-+@@ -28,9 +28,13 @@ static bool isIdentChar(char C) { |
| 1318 |
-+ |
| 1319 |
-+ std::string AsmWriterOperand::getCode(bool PassSubtarget) const { |
| 1320 |
-+ if (OperandType == isLiteralTextOperand) { |
| 1321 |
-++#ifdef CAPSTONE |
| 1322 |
-++ return "SStream_concat0(O, \"" + Str + "\");"; |
| 1323 |
-++#else |
| 1324 |
-+ if (Str.size() == 1) |
| 1325 |
-+ return "O << '" + Str + "';"; |
| 1326 |
-+ return "O << \"" + Str + "\";"; |
| 1327 |
-++#endif |
| 1328 |
-+ } |
| 1329 |
-+ |
| 1330 |
-+ if (OperandType == isLiteralStatementOperand) |
| 1331 |
-+-- |
| 1332 |
-+2.19.1 |
| 1333 |
-+ |
| 1334 |
-diff --git a/llvm/0006-capstone-generate-MappingInsn.inc.patch b/llvm/0006-capstone-generate-MappingInsn.inc.patch |
| 1335 |
-new file mode 100644 |
| 1336 |
-index 000000000..7ee22d787 |
| 1337 |
---- /dev/null |
| 1338 |
-+++ b/llvm/0006-capstone-generate-MappingInsn.inc.patch |
| 1339 |
-@@ -0,0 +1,174 @@ |
| 1340 |
-+From 7a436110ef15c803dc8524af2fb5612bcacbb126 Mon Sep 17 00:00:00 2001 |
| 1341 |
-+From: mephi42 <[email protected]> |
| 1342 |
-+Date: Tue, 7 Aug 2018 20:55:32 +0200 |
| 1343 |
-+Subject: [PATCH 6/7] capstone: generate *MappingInsn.inc |
| 1344 |
-+ |
| 1345 |
-+--- |
| 1346 |
-+ lib/Target/SystemZ/CMakeLists.txt | 1 + |
| 1347 |
-+ utils/TableGen/InstrInfoEmitter.cpp | 95 +++++++++++++++++++++++++++++ |
| 1348 |
-+ utils/TableGen/TableGen.cpp | 6 ++ |
| 1349 |
-+ utils/TableGen/TableGenBackends.h | 1 + |
| 1350 |
-+ 4 files changed, 103 insertions(+) |
| 1351 |
-+ |
| 1352 |
-+diff --git a/lib/Target/SystemZ/CMakeLists.txt b/lib/Target/SystemZ/CMakeLists.txt |
| 1353 |
-+index f83b4242fb4..4b5d9c4a3b2 100644 |
| 1354 |
-+--- a/lib/Target/SystemZ/CMakeLists.txt |
| 1355 |
-++++ b/lib/Target/SystemZ/CMakeLists.txt |
| 1356 |
-+@@ -6,6 +6,7 @@ tablegen(LLVM SystemZGenCallingConv.inc -gen-callingconv) |
| 1357 |
-+ tablegen(LLVM SystemZGenDAGISel.inc -gen-dag-isel) |
| 1358 |
-+ tablegen(LLVM SystemZGenDisassemblerTables.inc -gen-disassembler) |
| 1359 |
-+ tablegen(LLVM SystemZGenInstrInfo.inc -gen-instr-info) |
| 1360 |
-++tablegen(LLVM SystemZMappingInsn.inc -mapping-insn) |
| 1361 |
-+ tablegen(LLVM SystemZGenMCCodeEmitter.inc -gen-emitter) |
| 1362 |
-+ tablegen(LLVM SystemZGenRegisterInfo.inc -gen-register-info) |
| 1363 |
-+ tablegen(LLVM SystemZGenSubtargetInfo.inc -gen-subtarget) |
| 1364 |
-+diff --git a/utils/TableGen/InstrInfoEmitter.cpp b/utils/TableGen/InstrInfoEmitter.cpp |
| 1365 |
-+index 2f3a2729262..14ab1ea8a72 100644 |
| 1366 |
-+--- a/utils/TableGen/InstrInfoEmitter.cpp |
| 1367 |
-++++ b/utils/TableGen/InstrInfoEmitter.cpp |
| 1368 |
-+@@ -744,4 +744,99 @@ void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) { |
| 1369 |
-+ #endif |
| 1370 |
-+ } |
| 1371 |
-+ |
| 1372 |
-++#ifdef CAPSTONE |
| 1373 |
-++std::string GetPublicName(const CodeGenInstruction *Inst) { |
| 1374 |
-++ std::string Name = Inst->TheDef->getName(); |
| 1375 |
-++ // Apply backward compatibility fixups. |
| 1376 |
-++ // BRNLE -> BNLER. |
| 1377 |
-++ if (Name.length() >= 5 && Name.substr(0, 5) == "BRAsm") { |
| 1378 |
-++ Name = "B" + Name.substr(5, Name.length() - 5) + "R"; |
| 1379 |
-++ } |
| 1380 |
-++ // SSKEOpt -> SSKE. |
| 1381 |
-++ while (Name.length() >= 3 && Name.substr(Name.length() - 3, 3) == "Opt") { |
| 1382 |
-++ Name = Name.substr(0, Name.length() - 3); |
| 1383 |
-++ } |
| 1384 |
-++ // BRCLAsm -> BRCL. |
| 1385 |
-++ while (true) { |
| 1386 |
-++ size_t pos = Name.find("Asm"); |
| 1387 |
-++ if (pos == std::string::npos) { |
| 1388 |
-++ break; |
| 1389 |
-++ } |
| 1390 |
-++ Name = Name.substr(0, pos) + Name.substr(pos + 3); |
| 1391 |
-++ } |
| 1392 |
-++ // CPSDRxx -> CPSDR. |
| 1393 |
-++ if (Name.length() >= 2) { |
| 1394 |
-++ std::string Suffix2 = Name.substr(Name.length() - 2, 2); |
| 1395 |
-++ if (Suffix2 == "dd" || Suffix2 == "ds" || |
| 1396 |
-++ Suffix2 == "sd" || Suffix2 == "ss") { |
| 1397 |
-++ Name = Name.substr(0, Name.length() - 2); |
| 1398 |
-++ } |
| 1399 |
-++ } |
| 1400 |
-++ return "SYSZ_INS_" + Name; |
| 1401 |
-++} |
| 1402 |
-++ |
| 1403 |
-++std::string GetRegisterName(Record *Reg) { |
| 1404 |
-++ std::string Name = Reg->getName(); |
| 1405 |
-++ for (char& c : Name) { |
| 1406 |
-++ c = toupper(c); |
| 1407 |
-++ } |
| 1408 |
-++ // R0L, R0D -> R0. |
| 1409 |
-++ if (Name.length() >= 3 && |
| 1410 |
-++ Name[Name.length() - 3] == 'R' && |
| 1411 |
-++ (Name[Name.length() - 1] == 'L' || |
| 1412 |
-++ Name[Name.length() - 1] == 'D')) { |
| 1413 |
-++ Name = Name.substr(0, Name.length() - 3) + Name[Name.length() - 2]; |
| 1414 |
-++ } |
| 1415 |
-++ return "SYSZ_REG_" + Name; |
| 1416 |
-++} |
| 1417 |
-++ |
| 1418 |
-++std::string GetGroupName(Record *Pred) { |
| 1419 |
-++ std::string Name = Pred->getName(); |
| 1420 |
-++ for (char& c : Name) { |
| 1421 |
-++ c = toupper(c); |
| 1422 |
-++ } |
| 1423 |
-++ if (Name.length() >= 7 && Name.substr(0, 7) == "FEATURE") { |
| 1424 |
-++ Name = Name.substr(7); |
| 1425 |
-++ } |
| 1426 |
-++ return "SYSZ_GRP_" + Name; |
| 1427 |
-++} |
| 1428 |
-++ |
| 1429 |
-++void EmitMappingInsn(RecordKeeper &RK, raw_ostream &OS) { |
| 1430 |
-++ OS << "// This is auto-gen data for Capstone engine (www.capstone-engine.org)\n" |
| 1431 |
-++ "// By Nguyen Anh Quynh <[email protected]>\n" |
| 1432 |
-++ "\n"; |
| 1433 |
-++ CodeGenTarget Target(RK); |
| 1434 |
-++ for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) { |
| 1435 |
-++ if (Inst->TheDef->getValueAsBit("isPseudo") || |
| 1436 |
-++ Inst->TheDef->getValueAsBit("isCodeGenOnly")) { |
| 1437 |
-++ continue; |
| 1438 |
-++ } |
| 1439 |
-++ OS << "{\n" |
| 1440 |
-++ << "\t" << Target.getName() << "_" << Inst->TheDef->getName() << ", " |
| 1441 |
-++ << GetPublicName(Inst) << ",\n" |
| 1442 |
-++ << "#ifndef CAPSTONE_DIET\n" |
| 1443 |
-++ << "\t{ "; |
| 1444 |
-++ for (Record *Use : Inst->TheDef->getValueAsListOfDefs("Uses")) { |
| 1445 |
-++ OS << GetRegisterName(Use) << ", "; |
| 1446 |
-++ } |
| 1447 |
-++ OS << "0 }, { "; |
| 1448 |
-++ for (Record *Def : Inst->TheDef->getValueAsListOfDefs("Defs")) { |
| 1449 |
-++ OS << GetRegisterName(Def) << ", "; |
| 1450 |
-++ } |
| 1451 |
-++ OS << "0 }, { "; |
| 1452 |
-++ ListInit *Predicates = Inst->TheDef->getValueAsListInit("Predicates"); |
| 1453 |
-++ for (unsigned i = 0; i < Predicates->size(); ++i) { |
| 1454 |
-++ OS << GetGroupName(Predicates->getElementAsRecord(i)) << ", "; |
| 1455 |
-++ } |
| 1456 |
-++ OS << "0 }, " |
| 1457 |
-++ << Inst->TheDef->getValueAsBit("isBranch") |
| 1458 |
-++ << ", " |
| 1459 |
-++ << Inst->TheDef->getValueAsBit("isIndirectBranch") |
| 1460 |
-++ << "\n" |
| 1461 |
-++ << "#endif\n" |
| 1462 |
-++ << "},\n"; |
| 1463 |
-++ } |
| 1464 |
-++} |
| 1465 |
-++#endif |
| 1466 |
-++ |
| 1467 |
-+ } // end llvm namespace |
| 1468 |
-+diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp |
| 1469 |
-+index cf1404d8769..bbb4e860536 100644 |
| 1470 |
-+--- a/utils/TableGen/TableGen.cpp |
| 1471 |
-++++ b/utils/TableGen/TableGen.cpp |
| 1472 |
-+@@ -27,6 +27,7 @@ enum ActionType { |
| 1473 |
-+ GenEmitter, |
| 1474 |
-+ GenRegisterInfo, |
| 1475 |
-+ GenInstrInfo, |
| 1476 |
-++ MappingInsn, |
| 1477 |
-+ GenInstrDocs, |
| 1478 |
-+ GenAsmWriter, |
| 1479 |
-+ GenAsmMatcher, |
| 1480 |
-+@@ -65,6 +66,8 @@ namespace { |
| 1481 |
-+ "Generate registers and register classes info"), |
| 1482 |
-+ clEnumValN(GenInstrInfo, "gen-instr-info", |
| 1483 |
-+ "Generate instruction descriptions"), |
| 1484 |
-++ clEnumValN(MappingInsn, "mapping-insn", |
| 1485 |
-++ ""), |
| 1486 |
-+ clEnumValN(GenInstrDocs, "gen-instr-docs", |
| 1487 |
-+ "Generate instruction documentation"), |
| 1488 |
-+ clEnumValN(GenCallingConv, "gen-callingconv", |
| 1489 |
-+@@ -135,6 +138,9 @@ bool LLVMTableGenMain(raw_ostream &OS, RecordKeeper &Records) { |
| 1490 |
-+ case GenInstrInfo: |
| 1491 |
-+ EmitInstrInfo(Records, OS); |
| 1492 |
-+ break; |
| 1493 |
-++ case MappingInsn: |
| 1494 |
-++ EmitMappingInsn(Records, OS); |
| 1495 |
-++ break; |
| 1496 |
-+ case GenInstrDocs: |
| 1497 |
-+ EmitInstrDocs(Records, OS); |
| 1498 |
-+ break; |
| 1499 |
-+diff --git a/utils/TableGen/TableGenBackends.h b/utils/TableGen/TableGenBackends.h |
| 1500 |
-+index 1329a6d833f..a41e46b1db0 100644 |
| 1501 |
-+--- a/utils/TableGen/TableGenBackends.h |
| 1502 |
-++++ b/utils/TableGen/TableGenBackends.h |
| 1503 |
-+@@ -75,6 +75,7 @@ void EmitDFAPacketizer(RecordKeeper &RK, raw_ostream &OS); |
| 1504 |
-+ void EmitDisassembler(RecordKeeper &RK, raw_ostream &OS); |
| 1505 |
-+ void EmitFastISel(RecordKeeper &RK, raw_ostream &OS); |
| 1506 |
-+ void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS); |
| 1507 |
-++void EmitMappingInsn(RecordKeeper &RK, raw_ostream &OS); |
| 1508 |
-+ void EmitInstrDocs(RecordKeeper &RK, raw_ostream &OS); |
| 1509 |
-+ void EmitPseudoLowering(RecordKeeper &RK, raw_ostream &OS); |
| 1510 |
-+ void EmitCompressInst(RecordKeeper &RK, raw_ostream &OS); |
| 1511 |
-+-- |
| 1512 |
-+2.19.1 |
| 1513 |
-+ |
| 1514 |
-diff --git a/llvm/0007-capstone-generate-GenInsnNameMaps.inc.patch b/llvm/0007-capstone-generate-GenInsnNameMaps.inc.patch |
| 1515 |
-new file mode 100644 |
| 1516 |
-index 000000000..019540d65 |
| 1517 |
---- /dev/null |
| 1518 |
-+++ b/llvm/0007-capstone-generate-GenInsnNameMaps.inc.patch |
| 1519 |
-@@ -0,0 +1,110 @@ |
| 1520 |
-+From b42f9f2014ec49a22077b6610863d9341a74e142 Mon Sep 17 00:00:00 2001 |
| 1521 |
-+From: mephi42 <[email protected]> |
| 1522 |
-+Date: Fri, 17 Aug 2018 11:07:39 +0200 |
| 1523 |
-+Subject: [PATCH 7/7] capstone: generate *GenInsnNameMaps.inc |
| 1524 |
-+ |
| 1525 |
-+--- |
| 1526 |
-+ lib/Target/SystemZ/CMakeLists.txt | 1 + |
| 1527 |
-+ utils/TableGen/InstrInfoEmitter.cpp | 29 +++++++++++++++++++++++++++++ |
| 1528 |
-+ utils/TableGen/TableGen.cpp | 6 ++++++ |
| 1529 |
-+ utils/TableGen/TableGenBackends.h | 1 + |
| 1530 |
-+ 4 files changed, 37 insertions(+) |
| 1531 |
-+ |
| 1532 |
-+diff --git a/lib/Target/SystemZ/CMakeLists.txt b/lib/Target/SystemZ/CMakeLists.txt |
| 1533 |
-+index 4b5d9c4a3b2..2c64e0a94b8 100644 |
| 1534 |
-+--- a/lib/Target/SystemZ/CMakeLists.txt |
| 1535 |
-++++ b/lib/Target/SystemZ/CMakeLists.txt |
| 1536 |
-+@@ -7,6 +7,7 @@ tablegen(LLVM SystemZGenDAGISel.inc -gen-dag-isel) |
| 1537 |
-+ tablegen(LLVM SystemZGenDisassemblerTables.inc -gen-disassembler) |
| 1538 |
-+ tablegen(LLVM SystemZGenInstrInfo.inc -gen-instr-info) |
| 1539 |
-+ tablegen(LLVM SystemZMappingInsn.inc -mapping-insn) |
| 1540 |
-++tablegen(LLVM SystemZGenInsnNameMaps.inc -gen-insn-name-maps) |
| 1541 |
-+ tablegen(LLVM SystemZGenMCCodeEmitter.inc -gen-emitter) |
| 1542 |
-+ tablegen(LLVM SystemZGenRegisterInfo.inc -gen-register-info) |
| 1543 |
-+ tablegen(LLVM SystemZGenSubtargetInfo.inc -gen-subtarget) |
| 1544 |
-+diff --git a/utils/TableGen/InstrInfoEmitter.cpp b/utils/TableGen/InstrInfoEmitter.cpp |
| 1545 |
-+index 14ab1ea8a72..ccf8170ca62 100644 |
| 1546 |
-+--- a/utils/TableGen/InstrInfoEmitter.cpp |
| 1547 |
-++++ b/utils/TableGen/InstrInfoEmitter.cpp |
| 1548 |
-+@@ -837,6 +837,35 @@ void EmitMappingInsn(RecordKeeper &RK, raw_ostream &OS) { |
| 1549 |
-+ << "},\n"; |
| 1550 |
-+ } |
| 1551 |
-+ } |
| 1552 |
-++ |
| 1553 |
-++std::string GetMnemonic(const CodeGenInstruction *Inst) { |
| 1554 |
-++ std::string Mnemonic = Inst->AsmString; |
| 1555 |
-++ |
| 1556 |
-++ for (size_t i = 0; i < Mnemonic.length(); i++) { |
| 1557 |
-++ if (Mnemonic[i] == '\t') { |
| 1558 |
-++ return Mnemonic.substr(0, i); |
| 1559 |
-++ } |
| 1560 |
-++ } |
| 1561 |
-++ return Mnemonic; |
| 1562 |
-++} |
| 1563 |
-++ |
| 1564 |
-++void EmitInsnNameMaps(RecordKeeper &RK, raw_ostream &OS) { |
| 1565 |
-++ OS << "// This is auto-gen data for Capstone engine (www.capstone-engine.org)\n" |
| 1566 |
-++ "// By Nguyen Anh Quynh <[email protected]>\n" |
| 1567 |
-++ "\n"; |
| 1568 |
-++ CodeGenTarget Target(RK); |
| 1569 |
-++ std::map<std::string, std::string> M; |
| 1570 |
-++ for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) { |
| 1571 |
-++ if (Inst->TheDef->getValueAsBit("isPseudo") || |
| 1572 |
-++ Inst->TheDef->getValueAsBit("isCodeGenOnly")) { |
| 1573 |
-++ continue; |
| 1574 |
-++ } |
| 1575 |
-++ M[GetPublicName(Inst)] = GetMnemonic(Inst); |
| 1576 |
-++ } |
| 1577 |
-++ for (auto &P : M) { |
| 1578 |
-++ OS << "\t{ " << P.first << ", \"" << P.second << "\" },\n"; |
| 1579 |
-++ } |
| 1580 |
-++} |
| 1581 |
-+ #endif |
| 1582 |
-+ |
| 1583 |
-+ } // end llvm namespace |
| 1584 |
-+diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp |
| 1585 |
-+index bbb4e860536..27c6603de5a 100644 |
| 1586 |
-+--- a/utils/TableGen/TableGen.cpp |
| 1587 |
-++++ b/utils/TableGen/TableGen.cpp |
| 1588 |
-+@@ -28,6 +28,7 @@ enum ActionType { |
| 1589 |
-+ GenRegisterInfo, |
| 1590 |
-+ GenInstrInfo, |
| 1591 |
-+ MappingInsn, |
| 1592 |
-++ GenInsnNameMaps, |
| 1593 |
-+ GenInstrDocs, |
| 1594 |
-+ GenAsmWriter, |
| 1595 |
-+ GenAsmMatcher, |
| 1596 |
-+@@ -68,6 +69,8 @@ namespace { |
| 1597 |
-+ "Generate instruction descriptions"), |
| 1598 |
-+ clEnumValN(MappingInsn, "mapping-insn", |
| 1599 |
-+ ""), |
| 1600 |
-++ clEnumValN(GenInsnNameMaps, "gen-insn-name-maps", |
| 1601 |
-++ ""), |
| 1602 |
-+ clEnumValN(GenInstrDocs, "gen-instr-docs", |
| 1603 |
-+ "Generate instruction documentation"), |
| 1604 |
-+ clEnumValN(GenCallingConv, "gen-callingconv", |
| 1605 |
-+@@ -141,6 +144,9 @@ bool LLVMTableGenMain(raw_ostream &OS, RecordKeeper &Records) { |
| 1606 |
-+ case MappingInsn: |
| 1607 |
-+ EmitMappingInsn(Records, OS); |
| 1608 |
-+ break; |
| 1609 |
-++ case GenInsnNameMaps: |
| 1610 |
-++ EmitInsnNameMaps(Records, OS); |
| 1611 |
-++ break; |
| 1612 |
-+ case GenInstrDocs: |
| 1613 |
-+ EmitInstrDocs(Records, OS); |
| 1614 |
-+ break; |
| 1615 |
-+diff --git a/utils/TableGen/TableGenBackends.h b/utils/TableGen/TableGenBackends.h |
| 1616 |
-+index a41e46b1db0..5656e5be849 100644 |
| 1617 |
-+--- a/utils/TableGen/TableGenBackends.h |
| 1618 |
-++++ b/utils/TableGen/TableGenBackends.h |
| 1619 |
-+@@ -76,6 +76,7 @@ void EmitDisassembler(RecordKeeper &RK, raw_ostream &OS); |
| 1620 |
-+ void EmitFastISel(RecordKeeper &RK, raw_ostream &OS); |
| 1621 |
-+ void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS); |
| 1622 |
-+ void EmitMappingInsn(RecordKeeper &RK, raw_ostream &OS); |
| 1623 |
-++void EmitInsnNameMaps(RecordKeeper &RK, raw_ostream &OS); |
| 1624 |
-+ void EmitInstrDocs(RecordKeeper &RK, raw_ostream &OS); |
| 1625 |
-+ void EmitPseudoLowering(RecordKeeper &RK, raw_ostream &OS); |
| 1626 |
-+ void EmitCompressInst(RecordKeeper &RK, raw_ostream &OS); |
| 1627 |
-+-- |
| 1628 |
-+2.19.1 |
| 1629 |
-+ |
| 1630 |
-diff --git a/llvm/lib/Target/RISCV/CMakeLists.txt b/llvm/lib/Target/RISCV/CMakeLists.txt |
| 1631 |
-index 07c32cb31..1821f4b01 100644 |
| 1632 |
---- a/llvm/lib/Target/RISCV/CMakeLists.txt |
| 1633 |
-+++ b/llvm/lib/Target/RISCV/CMakeLists.txt |
| 1634 |
-@@ -6,6 +6,8 @@ tablegen(LLVM RISCVGenCompressInstEmitter.inc -gen-compress-inst-emitter) |
| 1635 |
- tablegen(LLVM RISCVGenDAGISel.inc -gen-dag-isel) |
| 1636 |
- tablegen(LLVM RISCVGenDisassemblerTables.inc -gen-disassembler) |
| 1637 |
- tablegen(LLVM RISCVGenInstrInfo.inc -gen-instr-info) |
| 1638 |
-+tablegen(LLVM RISCVGenMappingInsn.inc -gen-mapping-insn) |
| 1639 |
-+tablegen(LLVM RISCVGenInsnNameMaps.inc -gen-insn-name-maps) |
| 1640 |
- tablegen(LLVM RISCVGenMCCodeEmitter.inc -gen-emitter) |
| 1641 |
- tablegen(LLVM RISCVGenMCPseudoLowering.inc -gen-pseudo-lowering) |
| 1642 |
- tablegen(LLVM RISCVGenRegisterInfo.inc -gen-register-info) |
| 1643 |
-diff --git a/llvm/utils/TableGen/AsmWriterEmitter.cpp b/llvm/utils/TableGen/AsmWriterEmitter.cpp |
| 1644 |
-index 24e16f9c4..c24dc6052 100644 |
| 1645 |
---- a/llvm/utils/TableGen/AsmWriterEmitter.cpp |
| 1646 |
-+++ b/llvm/utils/TableGen/AsmWriterEmitter.cpp |
| 1647 |
-@@ -271,16 +271,22 @@ static void UnescapeString(std::string &Str) { |
| 1648 |
- /// clearing the Instructions vector. |
| 1649 |
- void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { |
| 1650 |
- Record *AsmWriter = Target.getAsmWriter(); |
| 1651 |
-+#ifndef CAPSTONE |
| 1652 |
- StringRef ClassName = AsmWriter->getValueAsString("AsmWriterClassName"); |
| 1653 |
-+#endif |
| 1654 |
- bool PassSubtarget = AsmWriter->getValueAsInt("PassSubtarget"); |
| 1655 |
- |
| 1656 |
- O << |
| 1657 |
- "/// printInstruction - This method is automatically generated by tablegen\n" |
| 1658 |
- "/// from the instruction set description.\n" |
| 1659 |
-+#ifdef CAPSTONE |
| 1660 |
-+ "static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)\n{\n"; |
| 1661 |
-+#else |
| 1662 |
- "void " << Target.getName() << ClassName |
| 1663 |
- << "::printInstruction(const MCInst *MI, " |
| 1664 |
- << (PassSubtarget ? "const MCSubtargetInfo &STI, " : "") |
| 1665 |
- << "raw_ostream &O) {\n"; |
| 1666 |
-+#endif |
| 1667 |
- |
| 1668 |
- // Build an aggregate string, and build a table of offsets into it. |
| 1669 |
- SequenceToOffsetTable<std::string> StringTable; |
| 1670 |
-@@ -378,9 +384,16 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { |
| 1671 |
- } |
| 1672 |
- |
| 1673 |
- // Emit the string table itself. |
| 1674 |
-+#ifdef CAPSTONE |
| 1675 |
-+ O << "#ifndef CAPSTONE_DIET\n"; |
| 1676 |
-+#endif |
| 1677 |
- O << " static const char AsmStrs[] = {\n"; |
| 1678 |
- StringTable.emit(O, printChar); |
| 1679 |
-- O << " };\n\n"; |
| 1680 |
-+ O << " };\n" |
| 1681 |
-+#ifdef CAPSTONE |
| 1682 |
-+ << "#endif\n" |
| 1683 |
-+#endif |
| 1684 |
-+ << "\n"; |
| 1685 |
- |
| 1686 |
- // Emit the lookup tables in pieces to minimize wasted bytes. |
| 1687 |
- unsigned BytesNeeded = ((OpcodeInfoBits - BitsLeft) + 7) / 8; |
| 1688 |
-@@ -408,21 +421,45 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { |
| 1689 |
- // If the total bits is more than 32-bits we need to use a 64-bit type. |
| 1690 |
- if (BitsLeft < (OpcodeInfoBits - 32)) |
| 1691 |
- BitsOS << "(uint64_t)"; |
| 1692 |
-- BitsOS << "OpInfo" << Table << "[MI->getOpcode()] << " << Shift << ";\n"; |
| 1693 |
-+ BitsOS << "OpInfo" << Table << "[" |
| 1694 |
-+#ifdef CAPSTONE |
| 1695 |
-+ << "MCInst_getOpcode(MI)" |
| 1696 |
-+#else |
| 1697 |
-+ << "MI->getOpcode()" |
| 1698 |
-+#endif |
| 1699 |
-+ << "] << " << Shift << ";\n"; |
| 1700 |
- // Prepare the shift for the next iteration and increment the table count. |
| 1701 |
- Shift += TableSize; |
| 1702 |
- ++Table; |
| 1703 |
- } |
| 1704 |
- |
| 1705 |
- // Emit the initial tab character. |
| 1706 |
-+#ifndef CAPSTONE |
| 1707 |
- O << " O << \"\\t\";\n\n"; |
| 1708 |
-+#endif |
| 1709 |
- |
| 1710 |
- O << " // Emit the opcode for the instruction.\n"; |
| 1711 |
- O << BitsString; |
| 1712 |
- |
| 1713 |
- // Emit the starting string. |
| 1714 |
-- O << " assert(Bits != 0 && \"Cannot print this instruction.\");\n" |
| 1715 |
-- << " O << AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << ")-1;\n\n"; |
| 1716 |
-+ O << " " |
| 1717 |
-+#ifdef CAPSTONE |
| 1718 |
-+ << "// " |
| 1719 |
-+#endif |
| 1720 |
-+ << "assert(Bits != 0 && \"Cannot print this instruction.\");\n" |
| 1721 |
-+#ifdef CAPSTONE |
| 1722 |
-+ << "#ifndef CAPSTONE_DIET\n" |
| 1723 |
-+ << " SStream_concat0(O, " |
| 1724 |
-+#else |
| 1725 |
-+ << " O << " |
| 1726 |
-+#endif |
| 1727 |
-+ << "AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << ")-1" |
| 1728 |
-+#ifdef CAPSTONE |
| 1729 |
-+ << ");\n" |
| 1730 |
-+ << "#endif\n\n"; |
| 1731 |
-+#else |
| 1732 |
-+ << ");\n\n"; |
| 1733 |
-+#endif |
| 1734 |
- |
| 1735 |
- // Output the table driven operand information. |
| 1736 |
- BitsLeft = OpcodeInfoBits-AsmStrBits; |
| 1737 |
-@@ -454,7 +491,11 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { |
| 1738 |
- O << " switch ((Bits >> " |
| 1739 |
- << (OpcodeInfoBits-BitsLeft) << ") & " |
| 1740 |
- << ((1 << NumBits)-1) << ") {\n" |
| 1741 |
-- << " default: llvm_unreachable(\"Invalid command number.\");\n"; |
| 1742 |
-+ << " default: " |
| 1743 |
-+#ifdef CAPSTONE |
| 1744 |
-+ << "assert(0);\n" |
| 1745 |
-+#endif |
| 1746 |
-+ << "llvm_unreachable(\"Invalid command number.\");\n"; |
| 1747 |
- |
| 1748 |
- // Print out all the cases. |
| 1749 |
- for (unsigned j = 0, e = Commands.size(); j != e; ++j) { |
| 1750 |
-@@ -535,6 +576,9 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName, |
| 1751 |
- } |
| 1752 |
- |
| 1753 |
- StringTable.layout(); |
| 1754 |
-+#ifdef CAPSTONE |
| 1755 |
-+ O << "#ifndef CAPSTONE_DIET\n"; |
| 1756 |
-+#endif |
| 1757 |
- O << " static const char AsmStrs" << AltName << "[] = {\n"; |
| 1758 |
- StringTable.emit(O, printChar); |
| 1759 |
- O << " };\n\n"; |
| 1760 |
-@@ -551,8 +595,10 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName, |
| 1761 |
- } |
| 1762 |
- |
| 1763 |
- void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) { |
| 1764 |
-+#ifndef CAPSTONE |
| 1765 |
- Record *AsmWriter = Target.getAsmWriter(); |
| 1766 |
- StringRef ClassName = AsmWriter->getValueAsString("AsmWriterClassName"); |
| 1767 |
-+#endif |
| 1768 |
- const auto &Registers = Target.getRegBank().getRegisters(); |
| 1769 |
- const std::vector<Record*> &AltNameIndices = Target.getRegAltNameIndices(); |
| 1770 |
- bool hasAltNames = AltNameIndices.size() > 1; |
| 1771 |
-@@ -562,12 +608,22 @@ void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) { |
| 1772 |
- "\n\n/// getRegisterName - This method is automatically generated by tblgen\n" |
| 1773 |
- "/// from the register set description. This returns the assembler name\n" |
| 1774 |
- "/// for the specified register.\n" |
| 1775 |
-+#ifdef CAPSTONE |
| 1776 |
-+ //"static const char *getRegisterName(unsigned RegNo)\n{\n"; |
| 1777 |
-+ "static const char *"; |
| 1778 |
-+ if (hasAltNames) |
| 1779 |
-+ O << "\ngetRegisterName(unsigned RegNo, unsigned AltIdx)\n{\n"; |
| 1780 |
-+ else |
| 1781 |
-+ O << "\ngetRegisterName(unsigned RegNo)\n{\n"; |
| 1782 |
-+#else |
| 1783 |
- "const char *" << Target.getName() << ClassName << "::"; |
| 1784 |
- if (hasAltNames) |
| 1785 |
- O << "\ngetRegisterName(unsigned RegNo, unsigned AltIdx) {\n"; |
| 1786 |
- else |
| 1787 |
- O << "getRegisterName(unsigned RegNo) {\n"; |
| 1788 |
-- O << " assert(RegNo && RegNo < " << (Registers.size()+1) |
| 1789 |
-+#endif |
| 1790 |
-+ O << " " |
| 1791 |
-+ << "assert(RegNo && RegNo < " << (Registers.size()+1) |
| 1792 |
- << " && \"Invalid register number!\");\n" |
| 1793 |
- << "\n"; |
| 1794 |
- |
| 1795 |
-@@ -579,12 +635,21 @@ void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) { |
| 1796 |
- |
| 1797 |
- if (hasAltNames) { |
| 1798 |
- O << " switch(AltIdx) {\n" |
| 1799 |
-+#ifdef CAPSTONE |
| 1800 |
-+ << " default: assert(0);\n"; |
| 1801 |
-+#else |
| 1802 |
- << " default: llvm_unreachable(\"Invalid register alt name index!\");\n"; |
| 1803 |
-+#endif |
| 1804 |
- for (const Record *R : AltNameIndices) { |
| 1805 |
- StringRef AltName = R->getName(); |
| 1806 |
- O << " case "; |
| 1807 |
- if (!Namespace.empty()) |
| 1808 |
-- O << Namespace << "::"; |
| 1809 |
-+ O << Namespace |
| 1810 |
-+#ifndef CAPSTONE |
| 1811 |
-+ << "::"; |
| 1812 |
-+#else |
| 1813 |
-+ << "_"; |
| 1814 |
-+#endif |
| 1815 |
- O << AltName << ":\n" |
| 1816 |
- << " assert(*(AsmStrs" << AltName << "+RegAsmOffset" << AltName |
| 1817 |
- << "[RegNo-1]) &&\n" |
| 1818 |
-@@ -594,10 +659,22 @@ void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) { |
| 1819 |
- } |
| 1820 |
- O << " }\n"; |
| 1821 |
- } else { |
| 1822 |
-+#ifdef CAPSTONE |
| 1823 |
-+ O << " //int i;\n" |
| 1824 |
-+ << " //for (i = 0; i < sizeof(RegAsmOffset); i++)\n" |
| 1825 |
-+ << " // printf(\"%s = %u\\n\", AsmStrs+RegAsmOffset[i], i + 1);\n" |
| 1826 |
-+ << " //printf(\"*************************\\n\");\n" |
| 1827 |
-+#else |
| 1828 |
- O << " assert (*(AsmStrs+RegAsmOffset[RegNo-1]) &&\n" |
| 1829 |
- << " \"Invalid alt name index for register!\");\n" |
| 1830 |
-+#endif |
| 1831 |
- << " return AsmStrs+RegAsmOffset[RegNo-1];\n"; |
| 1832 |
- } |
| 1833 |
-+#ifdef CAPSTONE |
| 1834 |
-+ O << "#else\n" |
| 1835 |
-+ << " return NULL;\n" |
| 1836 |
-+ << "#endif\n"; |
| 1837 |
-+#endif |
| 1838 |
- O << "}\n"; |
| 1839 |
- } |
| 1840 |
- |
| 1841 |
-@@ -1139,9 +1216,21 @@ AsmWriterEmitter::AsmWriterEmitter(RecordKeeper &R) : Records(R), Target(R) { |
| 1842 |
- } |
| 1843 |
- |
| 1844 |
- void AsmWriterEmitter::run(raw_ostream &O) { |
| 1845 |
-+#ifdef CAPSTONE |
| 1846 |
-+ O << "/* Capstone Disassembly Engine */\n" |
| 1847 |
-+ "/* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */\n" |
| 1848 |
-+ "\n" |
| 1849 |
-+ "#include <stdio.h>\t// debug\n" |
| 1850 |
-+ "#include <capstone/platform.h>\n" |
| 1851 |
-+ "#include <assert.h>\n" |
| 1852 |
-+ "\n" |
| 1853 |
-+ "\n"; |
| 1854 |
-+#endif |
| 1855 |
- EmitPrintInstruction(O); |
| 1856 |
- EmitGetRegisterName(O); |
| 1857 |
-+#ifndef CAPSTONE |
| 1858 |
- EmitPrintAliasInstruction(O); |
| 1859 |
-+#endif |
| 1860 |
- } |
| 1861 |
- |
| 1862 |
- namespace llvm { |
| 1863 |
-diff --git a/llvm/utils/TableGen/AsmWriterInst.cpp b/llvm/utils/TableGen/AsmWriterInst.cpp |
| 1864 |
-index d065a4209..7266d1eda 100644 |
| 1865 |
---- a/llvm/utils/TableGen/AsmWriterInst.cpp |
| 1866 |
-+++ b/llvm/utils/TableGen/AsmWriterInst.cpp |
| 1867 |
-@@ -27,9 +27,13 @@ static bool isIdentChar(char C) { |
| 1868 |
- |
| 1869 |
- std::string AsmWriterOperand::getCode(bool PassSubtarget) const { |
| 1870 |
- if (OperandType == isLiteralTextOperand) { |
| 1871 |
-+#ifdef CAPSTONE |
| 1872 |
-+ return "SStream_concat0(O, \"" + Str + "\");"; |
| 1873 |
-+#else |
| 1874 |
- if (Str.size() == 1) |
| 1875 |
- return "O << '" + Str + "';"; |
| 1876 |
- return "O << \"" + Str + "\";"; |
| 1877 |
-+#endif |
| 1878 |
- } |
| 1879 |
- |
| 1880 |
- if (OperandType == isLiteralStatementOperand) |
| 1881 |
-diff --git a/llvm/utils/TableGen/DisassemblerEmitter.cpp b/llvm/utils/TableGen/DisassemblerEmitter.cpp |
| 1882 |
-index 9e75c7fba..1bc0cfa0d 100644 |
| 1883 |
---- a/llvm/utils/TableGen/DisassemblerEmitter.cpp |
| 1884 |
-+++ b/llvm/utils/TableGen/DisassemblerEmitter.cpp |
| 1885 |
-@@ -105,6 +105,11 @@ extern void EmitFixedLenDecoder(RecordKeeper &RK, raw_ostream &OS, |
| 1886 |
- void EmitDisassembler(RecordKeeper &Records, raw_ostream &OS) { |
| 1887 |
- CodeGenTarget Target(Records); |
| 1888 |
- emitSourceFileHeader(" * " + Target.getName().str() + " Disassembler", OS); |
| 1889 |
-+#ifdef CAPSTONE |
| 1890 |
-+ OS << "/* Capstone Disassembly Engine */\n" |
| 1891 |
-+ "/* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */\n" |
| 1892 |
-+ "\n"; |
| 1893 |
-+#endif |
| 1894 |
- |
| 1895 |
- // X86 uses a custom disassembler. |
| 1896 |
- if (Target.getName() == "X86") { |
| 1897 |
-@@ -149,7 +154,12 @@ void EmitDisassembler(RecordKeeper &Records, raw_ostream &OS) { |
| 1898 |
- } |
| 1899 |
- |
| 1900 |
- EmitFixedLenDecoder(Records, OS, Target.getName(), |
| 1901 |
-- "if (", " == MCDisassembler::Fail)", |
| 1902 |
-+ "if (", |
| 1903 |
-+#ifdef CAPSTONE |
| 1904 |
-+ " == MCDisassembler_Fail)", |
| 1905 |
-+#else |
| 1906 |
-+ " == MCDisassembler::Fail)", |
| 1907 |
-+#endif |
| 1908 |
- "MCDisassembler::Success", "MCDisassembler::Fail", ""); |
| 1909 |
- } |
| 1910 |
- |
| 1911 |
-diff --git a/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp b/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp |
| 1912 |
-index ea28e06cc..3db428dfa 100644 |
| 1913 |
---- a/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp |
| 1914 |
-+++ b/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp |
| 1915 |
-@@ -741,7 +741,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 1916 |
- ++I; |
| 1917 |
- unsigned Start = *I++; |
| 1918 |
- unsigned Len = *I++; |
| 1919 |
-- OS.indent(Indentation) << "MCD::OPC_ExtractField, " << Start << ", " |
| 1920 |
-+ OS.indent(Indentation) |
| 1921 |
-+#ifdef CAPSTONE |
| 1922 |
-+ << "MCD_OPC_ExtractField" |
| 1923 |
-+#else |
| 1924 |
-+ << "MCD::OPC_ExtractField" |
| 1925 |
-+#endif |
| 1926 |
-+ << ", " << Start << ", " |
| 1927 |
- << Len << ", // Inst{"; |
| 1928 |
- if (Len > 1) |
| 1929 |
- OS << (Start + Len - 1) << "-"; |
| 1930 |
-@@ -750,7 +756,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 1931 |
- } |
| 1932 |
- case MCD::OPC_FilterValue: { |
| 1933 |
- ++I; |
| 1934 |
-- OS.indent(Indentation) << "MCD::OPC_FilterValue, "; |
| 1935 |
-+ OS.indent(Indentation) |
| 1936 |
-+#ifdef CAPSTONE |
| 1937 |
-+ << "MCD_OPC_FilterValue" |
| 1938 |
-+#else |
| 1939 |
-+ << "MCD::OPC_FilterValue" |
| 1940 |
-+#endif |
| 1941 |
-+ << ", "; |
| 1942 |
- // The filter value is ULEB128 encoded. |
| 1943 |
- while (*I >= 128) |
| 1944 |
- OS << (unsigned)*I++ << ", "; |
| 1945 |
-@@ -773,7 +785,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 1946 |
- ++I; |
| 1947 |
- unsigned Start = *I++; |
| 1948 |
- unsigned Len = *I++; |
| 1949 |
-- OS.indent(Indentation) << "MCD::OPC_CheckField, " << Start << ", " |
| 1950 |
-+ OS.indent(Indentation) |
| 1951 |
-+#ifdef CAPSTONE |
| 1952 |
-+ << "MCD_OPC_CheckField" |
| 1953 |
-+#else |
| 1954 |
-+ << "MCD::OPC_CheckField" |
| 1955 |
-+#endif |
| 1956 |
-+ << ", " << Start << ", " |
| 1957 |
- << Len << ", ";// << Val << ", " << NumToSkip << ",\n"; |
| 1958 |
- // ULEB128 encoded field value. |
| 1959 |
- for (; *I >= 128; ++I) |
| 1960 |
-@@ -794,7 +812,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 1961 |
- } |
| 1962 |
- case MCD::OPC_CheckPredicate: { |
| 1963 |
- ++I; |
| 1964 |
-- OS.indent(Indentation) << "MCD::OPC_CheckPredicate, "; |
| 1965 |
-+ OS.indent(Indentation) |
| 1966 |
-+#ifdef CAPSTONE |
| 1967 |
-+ << "MCD_OPC_CheckPredicate" |
| 1968 |
-+#else |
| 1969 |
-+ << "MCD::OPC_CheckPredicate" |
| 1970 |
-+#endif |
| 1971 |
-+ << ", "; |
| 1972 |
- for (; *I >= 128; ++I) |
| 1973 |
- OS << (unsigned)*I << ", "; |
| 1974 |
- OS << (unsigned)*I++ << ", "; |
| 1975 |
-@@ -823,7 +847,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 1976 |
- && "ULEB128 value too large!"); |
| 1977 |
- // Decode the Opcode value. |
| 1978 |
- unsigned Opc = decodeULEB128(Buffer); |
| 1979 |
-- OS.indent(Indentation) << "MCD::OPC_" << (IsTry ? "Try" : "") |
| 1980 |
-+ OS.indent(Indentation) |
| 1981 |
-+#ifdef CAPSTONE |
| 1982 |
-+ << "MCD_OPC_" |
| 1983 |
-+#else |
| 1984 |
-+ << "MCD::OPC_" |
| 1985 |
-+#endif |
| 1986 |
-+ << (IsTry ? "Try" : "") |
| 1987 |
- << "Decode, "; |
| 1988 |
- for (p = Buffer; *p >= 128; ++p) |
| 1989 |
- OS << (unsigned)*p << ", "; |
| 1990 |
-@@ -858,7 +888,12 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 1991 |
- } |
| 1992 |
- case MCD::OPC_SoftFail: { |
| 1993 |
- ++I; |
| 1994 |
-- OS.indent(Indentation) << "MCD::OPC_SoftFail"; |
| 1995 |
-+ OS.indent(Indentation) |
| 1996 |
-+#ifdef CAPSTONE |
| 1997 |
-+ << "MCD_OPC_SoftFail"; |
| 1998 |
-+#else |
| 1999 |
-+ << "MCD::OPC_SoftFail"; |
| 2000 |
-+#endif |
| 2001 |
- // Positive mask |
| 2002 |
- uint64_t Value = 0; |
| 2003 |
- unsigned Shift = 0; |
| 2004 |
-@@ -890,7 +925,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 2005 |
- } |
| 2006 |
- case MCD::OPC_Fail: { |
| 2007 |
- ++I; |
| 2008 |
-- OS.indent(Indentation) << "MCD::OPC_Fail,\n"; |
| 2009 |
-+ OS.indent(Indentation) |
| 2010 |
-+#ifdef CAPSTONE |
| 2011 |
-+ << "MCD_OPC_Fail" |
| 2012 |
-+#else |
| 2013 |
-+ << "MCD::OPC_Fail" |
| 2014 |
-+#endif |
| 2015 |
-+ << ",\n"; |
| 2016 |
- break; |
| 2017 |
- } |
| 2018 |
- } |
| 2019 |
-@@ -905,23 +946,46 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 2020 |
- void FixedLenDecoderEmitter:: |
| 2021 |
- emitPredicateFunction(formatted_raw_ostream &OS, PredicateSet &Predicates, |
| 2022 |
- unsigned Indentation) const { |
| 2023 |
-+#ifdef CAPSTONE |
| 2024 |
-+ OS.indent(Indentation) << "static bool getbool(uint64_t b)\n"; |
| 2025 |
-+ OS.indent(Indentation) << "{\n"; |
| 2026 |
-+ OS.indent(Indentation) << "\treturn b != 0;\n"; |
| 2027 |
-+ OS.indent(Indentation) << "}\n\n"; |
| 2028 |
-+#endif |
| 2029 |
-+ |
| 2030 |
- // The predicate function is just a big switch statement based on the |
| 2031 |
- // input predicate index. |
| 2032 |
- OS.indent(Indentation) << "static bool checkDecoderPredicate(unsigned Idx, " |
| 2033 |
-+#ifdef CAPSTONE |
| 2034 |
-+ << "uint64_t Bits)\n{\n"; |
| 2035 |
-+#else |
| 2036 |
- << "const FeatureBitset& Bits) {\n"; |
| 2037 |
-+#endif |
| 2038 |
- Indentation += 2; |
| 2039 |
- if (!Predicates.empty()) { |
| 2040 |
- OS.indent(Indentation) << "switch (Idx) {\n"; |
| 2041 |
-- OS.indent(Indentation) << "default: llvm_unreachable(\"Invalid index!\");\n"; |
| 2042 |
-+ OS.indent(Indentation) << "default: " |
| 2043 |
-+#ifdef CAPSTONE |
| 2044 |
-+ << "assert(0);\n" |
| 2045 |
-+#endif |
| 2046 |
-+ << "llvm_unreachable(\"Invalid index!\");\n"; |
| 2047 |
- unsigned Index = 0; |
| 2048 |
- for (const auto &Predicate : Predicates) { |
| 2049 |
- OS.indent(Indentation) << "case " << Index++ << ":\n"; |
| 2050 |
-- OS.indent(Indentation+2) << "return (" << Predicate << ");\n"; |
| 2051 |
-+ OS.indent(Indentation+2) << "return " |
| 2052 |
-+#ifdef CAPSTONE |
| 2053 |
-+ << "getbool" |
| 2054 |
-+#endif |
| 2055 |
-+ << "(" << Predicate << ");\n"; |
| 2056 |
- } |
| 2057 |
- OS.indent(Indentation) << "}\n"; |
| 2058 |
- } else { |
| 2059 |
- // No case statement to emit |
| 2060 |
-- OS.indent(Indentation) << "llvm_unreachable(\"Invalid index!\");\n"; |
| 2061 |
-+ OS.indent(Indentation) |
| 2062 |
-+#ifdef CAPSTONE |
| 2063 |
-+ << "assert(0);\n" |
| 2064 |
-+#endif |
| 2065 |
-+ << "llvm_unreachable(\"Invalid index!\");\n"; |
| 2066 |
- } |
| 2067 |
- Indentation -= 2; |
| 2068 |
- OS.indent(Indentation) << "}\n\n"; |
| 2069 |
-@@ -932,23 +996,39 @@ emitDecoderFunction(formatted_raw_ostream &OS, DecoderSet &Decoders, |
| 2070 |
- unsigned Indentation) const { |
| 2071 |
- // The decoder function is just a big switch statement based on the |
| 2072 |
- // input decoder index. |
| 2073 |
-+#ifdef CAPSTONE |
| 2074 |
-+#define EDF_EOL " \\\n" |
| 2075 |
-+ OS.indent(Indentation) << "#define DecodeToMCInst(fname,fieldname, InsnType) \\\n"; |
| 2076 |
-+ OS.indent(Indentation) << "static DecodeStatus fname(DecodeStatus S, unsigned Idx, InsnType insn, MCInst *MI, \\\n"; |
| 2077 |
-+ OS.indent(Indentation) << " uint64_t Address, const void *Decoder) \\\n"; |
| 2078 |
-+ OS.indent(Indentation) << "{ \\\n"; |
| 2079 |
-+#else |
| 2080 |
-+#define EDF_EOL "\n" |
| 2081 |
- OS.indent(Indentation) << "template<typename InsnType>\n"; |
| 2082 |
- OS.indent(Indentation) << "static DecodeStatus decodeToMCInst(DecodeStatus S," |
| 2083 |
- << " unsigned Idx, InsnType insn, MCInst &MI,\n"; |
| 2084 |
- OS.indent(Indentation) << " uint64_t " |
| 2085 |
- << "Address, const void *Decoder, bool &DecodeComplete) {\n"; |
| 2086 |
-+#endif |
| 2087 |
- Indentation += 2; |
| 2088 |
-+#ifndef CAPSTONE |
| 2089 |
- OS.indent(Indentation) << "DecodeComplete = true;\n"; |
| 2090 |
-- OS.indent(Indentation) << "InsnType tmp;\n"; |
| 2091 |
-- OS.indent(Indentation) << "switch (Idx) {\n"; |
| 2092 |
-- OS.indent(Indentation) << "default: llvm_unreachable(\"Invalid index!\");\n"; |
| 2093 |
-+#endif |
| 2094 |
-+ OS.indent(Indentation) << "InsnType tmp;" EDF_EOL; |
| 2095 |
-+ OS.indent(Indentation) << "switch (Idx) {" EDF_EOL; |
| 2096 |
-+ OS.indent(Indentation) << "default:" |
| 2097 |
-+#ifndef CAPSTONE |
| 2098 |
-+ << " llvm_unreachable(\"Invalid index!\");\n"; |
| 2099 |
-+#else |
| 2100 |
-+ << " assert(0);\\\n"; |
| 2101 |
-+#endif |
| 2102 |
- unsigned Index = 0; |
| 2103 |
- for (const auto &Decoder : Decoders) { |
| 2104 |
-- OS.indent(Indentation) << "case " << Index++ << ":\n"; |
| 2105 |
-+ OS.indent(Indentation) << "case " << Index++ << ":" EDF_EOL; |
| 2106 |
- OS << Decoder; |
| 2107 |
-- OS.indent(Indentation+2) << "return S;\n"; |
| 2108 |
-+ OS.indent(Indentation+2) << "return S;" EDF_EOL; |
| 2109 |
- } |
| 2110 |
-- OS.indent(Indentation) << "}\n"; |
| 2111 |
-+ OS.indent(Indentation) << "}" EDF_EOL; |
| 2112 |
- Indentation -= 2; |
| 2113 |
- OS.indent(Indentation) << "}\n\n"; |
| 2114 |
- } |
| 2115 |
-@@ -1075,16 +1155,21 @@ void FilterChooser::emitBinaryParser(raw_ostream &o, unsigned &Indentation, |
| 2116 |
- const std::string &Decoder = OpInfo.Decoder; |
| 2117 |
- |
| 2118 |
- if (OpInfo.numFields() != 1) |
| 2119 |
-- o.indent(Indentation) << "tmp = 0;\n"; |
| 2120 |
-+ o.indent(Indentation) << "tmp = 0;" EDF_EOL; |
| 2121 |
- |
| 2122 |
- for (const EncodingField &EF : OpInfo) { |
| 2123 |
- o.indent(Indentation) << "tmp "; |
| 2124 |
- if (OpInfo.numFields() != 1) o << '|'; |
| 2125 |
-- o << "= fieldFromInstruction" |
| 2126 |
-+ o << "= " |
| 2127 |
-+#ifdef CAPSTONE |
| 2128 |
-+ << "fieldname" |
| 2129 |
-+#else |
| 2130 |
-+ << "fieldFromInstruction" |
| 2131 |
-+#endif |
| 2132 |
- << "(insn, " << EF.Base << ", " << EF.Width << ')'; |
| 2133 |
- if (OpInfo.numFields() != 1 || EF.Offset != 0) |
| 2134 |
- o << " << " << EF.Offset; |
| 2135 |
-- o << ";\n"; |
| 2136 |
-+ o << ";" EDF_EOL; |
| 2137 |
- } |
| 2138 |
- |
| 2139 |
- if (Decoder != "") { |
| 2140 |
-@@ -1092,8 +1177,12 @@ void FilterChooser::emitBinaryParser(raw_ostream &o, unsigned &Indentation, |
| 2141 |
- o.indent(Indentation) << Emitter->GuardPrefix << Decoder |
| 2142 |
- << "(MI, tmp, Address, Decoder)" |
| 2143 |
- << Emitter->GuardPostfix |
| 2144 |
-+#ifdef CAPSTONE |
| 2145 |
-+ << " return MCDisassembler_Fail; \\\n"; |
| 2146 |
-+#else |
| 2147 |
- << " { " << (OpHasCompleteDecoder ? "" : "DecodeComplete = false; ") |
| 2148 |
- << "return MCDisassembler::Fail; }\n"; |
| 2149 |
-+#endif |
| 2150 |
- } else { |
| 2151 |
- OpHasCompleteDecoder = true; |
| 2152 |
- o.indent(Indentation) << "MI.addOperand(MCOperand::createImm(tmp));\n"; |
| 2153 |
-@@ -1112,7 +1201,13 @@ void FilterChooser::emitDecoder(raw_ostream &OS, unsigned Indentation, |
| 2154 |
- << "(MI, insn, Address, Decoder)" |
| 2155 |
- << Emitter->GuardPostfix |
| 2156 |
- << " { " << (HasCompleteDecoder ? "" : "DecodeComplete = false; ") |
| 2157 |
-- << "return MCDisassembler::Fail; }\n"; |
| 2158 |
-+ << "return " |
| 2159 |
-+#ifdef CAPSTONE |
| 2160 |
-+ << "MCDisassembler_Fail" |
| 2161 |
-+#else |
| 2162 |
-+ << "MCDisassembler::Fail" |
| 2163 |
-+#endif |
| 2164 |
-+ << "; }\n"; |
| 2165 |
- break; |
| 2166 |
- } |
| 2167 |
- |
| 2168 |
-@@ -1150,10 +1245,19 @@ unsigned FilterChooser::getDecoderIndex(DecoderSet &Decoders, |
| 2169 |
- static void emitSinglePredicateMatch(raw_ostream &o, StringRef str, |
| 2170 |
- const std::string &PredicateNamespace) { |
| 2171 |
- if (str[0] == '!') |
| 2172 |
-+#ifdef CAPSTONE |
| 2173 |
-+ o << "~(Bits & " << PredicateNamespace << "_" |
| 2174 |
-+ << str.slice(1,str.size()) << ")"; |
| 2175 |
-+#else |
| 2176 |
- o << "!Bits[" << PredicateNamespace << "::" |
| 2177 |
- << str.slice(1,str.size()) << "]"; |
| 2178 |
-+#endif |
| 2179 |
- else |
| 2180 |
-+#ifdef CAPSTONE |
| 2181 |
-+ o << "(Bits & " << PredicateNamespace << "_" << str << ")"; |
| 2182 |
-+#else |
| 2183 |
- o << "Bits[" << PredicateNamespace << "::" << str << "]"; |
| 2184 |
-+#endif |
| 2185 |
- } |
| 2186 |
- |
| 2187 |
- bool FilterChooser::emitPredicateMatch(raw_ostream &o, unsigned &Indentation, |
| 2188 |
-@@ -2090,7 +2194,18 @@ static void emitFieldFromInstruction(formatted_raw_ostream &OS) { |
| 2189 |
- << "// * Support shift (<<, >>) with signed and unsigned integers on the " |
| 2190 |
- "RHS\n" |
| 2191 |
- << "// * Support put (<<) to raw_ostream&\n" |
| 2192 |
-- << "template<typename InsnType>\n" |
| 2193 |
-+#ifdef CAPSTONE |
| 2194 |
-+ << "#define FieldFromInstruction(fname, InsnType) \\\n" |
| 2195 |
-+ << "static InsnType fname(InsnType insn, unsigned startBit, unsigned numBits) \\\n" |
| 2196 |
-+ << "{ \\\n" |
| 2197 |
-+ << " InsnType fieldMask; \\\n" |
| 2198 |
-+ << " if (numBits == sizeof(InsnType)*8) \\\n" |
| 2199 |
-+ << " fieldMask = (InsnType)(-1LL); \\\n" |
| 2200 |
-+ << " else \\\n" |
| 2201 |
-+ << " fieldMask = (((InsnType)1 << numBits) - 1) << startBit; \\\n" |
| 2202 |
-+ << " return (insn & fieldMask) >> startBit; \\\n" |
| 2203 |
-+#else |
| 2204 |
-+ << "template<typename InsnType>\n" |
| 2205 |
- << "#if defined(_MSC_VER) && !defined(__clang__)\n" |
| 2206 |
- << "__declspec(noinline)\n" |
| 2207 |
- << "#endif\n" |
| 2208 |
-@@ -2127,12 +2242,239 @@ static void emitFieldFromInstruction(formatted_raw_ostream &OS) { |
| 2209 |
- << " unsigned numBits) {\n" |
| 2210 |
- << " return fieldFromInstruction(insn, startBit, numBits, " |
| 2211 |
- "std::is_integral<InsnType>());\n" |
| 2212 |
-+#endif |
| 2213 |
- << "}\n\n"; |
| 2214 |
- } |
| 2215 |
- |
| 2216 |
- // emitDecodeInstruction - Emit the templated helper function |
| 2217 |
- // decodeInstruction(). |
| 2218 |
- static void emitDecodeInstruction(formatted_raw_ostream &OS) { |
| 2219 |
-+ |
| 2220 |
-+#if 0 |
| 2221 |
-+ OS << "#define DecodeInstruction(fname, fieldname, decoder, InsnType) \\\n" |
| 2222 |
-+ << "static DecodeStatus fname(const uint8_t DecodeTable[], MCInst *MI, \\\n" |
| 2223 |
-+ << " InsnType insn, uint64_t Address, const MCRegisterInfo *MRI, int feature) \\\n" |
| 2224 |
-+ << "{ \\\n" |
| 2225 |
-+ << " uint64_t Bits = getFeatureBits(feature); \\\n" |
| 2226 |
-+ << " const uint8_t *Ptr = DecodeTable; \\\n" |
| 2227 |
-+ << " uint32_t CurFieldValue = 0, ExpectedValue; \\\n" |
| 2228 |
-+ << " DecodeStatus S = MCDisassembler_Success; \\\n" |
| 2229 |
-+ << " unsigned Start, Len, NumToSkip, PIdx, Opc, DecodeIdx; \\\n" |
| 2230 |
-+ << " InsnType Val, FieldValue, PositiveMask, NegativeMask; \\\n" |
| 2231 |
-+ << " bool Pred, Fail; \\\n" |
| 2232 |
-+ << " for (;;) { \\\n" |
| 2233 |
-+ << " switch (*Ptr) { \\\n" |
| 2234 |
-+ << " default: \\\n" |
| 2235 |
-+ << " return MCDisassembler_Fail; \\\n" |
| 2236 |
-+ << " case MCD_OPC_ExtractField: { \\\n" |
| 2237 |
-+ << " Start = *++Ptr; \\\n" |
| 2238 |
-+ << " Len = *++Ptr; \\\n" |
| 2239 |
-+ << " ++Ptr; \\\n" |
| 2240 |
-+ << " CurFieldValue = (uint32_t)fieldname(insn, Start, Len); \\\n" |
| 2241 |
-+ << " break; \\\n" |
| 2242 |
-+ << " } \\\n" |
| 2243 |
-+ << " case MCD_OPC_FilterValue: { \\\n" |
| 2244 |
-+ << " Val = (InsnType)decodeULEB128(++Ptr, &Len); \\\n" |
| 2245 |
-+ << " Ptr += Len; \\\n" |
| 2246 |
-+ << " NumToSkip = *Ptr++; \\\n" |
| 2247 |
-+ << " NumToSkip |= (*Ptr++) << 8; \\\n" |
| 2248 |
-+ << " if (Val != CurFieldValue) \\\n" |
| 2249 |
-+ << " Ptr += NumToSkip; \\\n" |
| 2250 |
-+ << " break; \\\n" |
| 2251 |
-+ << " } \\\n" |
| 2252 |
-+ << " case MCD_OPC_CheckField: { \\\n" |
| 2253 |
-+ << " Start = *++Ptr; \\\n" |
| 2254 |
-+ << " Len = *++Ptr; \\\n" |
| 2255 |
-+ << " FieldValue = fieldname(insn, Start, Len); \\\n" |
| 2256 |
-+ << " ExpectedValue = (uint32_t)decodeULEB128(++Ptr, &Len); \\\n" |
| 2257 |
-+ << " Ptr += Len; \\\n" |
| 2258 |
-+ << " NumToSkip = *Ptr++; \\\n" |
| 2259 |
-+ << " NumToSkip |= (*Ptr++) << 8; \\\n" |
| 2260 |
-+ << " if (ExpectedValue != FieldValue) \\\n" |
| 2261 |
-+ << " Ptr += NumToSkip; \\\n" |
| 2262 |
-+ << " break; \\\n" |
| 2263 |
-+ << " } \\\n" |
| 2264 |
-+ << " case MCD_OPC_CheckPredicate: { \\\n" |
| 2265 |
-+ << " PIdx = (uint32_t)decodeULEB128(++Ptr, &Len); \\\n" |
| 2266 |
-+ << " Ptr += Len; \\\n" |
| 2267 |
-+ << " NumToSkip = *Ptr++; \\\n" |
| 2268 |
-+ << " NumToSkip |= (*Ptr++) << 8; \\\n" |
| 2269 |
-+ << " Pred = checkDecoderPredicate(PIdx, Bits); \\\n" |
| 2270 |
-+ << " if (!Pred) \\\n" |
| 2271 |
-+ << " Ptr += NumToSkip; \\\n" |
| 2272 |
-+ << " (void)Pred; \\\n" |
| 2273 |
-+ << " break; \\\n" |
| 2274 |
-+ << " } \\\n" |
| 2275 |
-+ << " case MCD_OPC_Decode: { \\\n" |
| 2276 |
-+ << " Opc = (unsigned)decodeULEB128(++Ptr, &Len); \\\n" |
| 2277 |
-+ << " Ptr += Len; \\\n" |
| 2278 |
-+ << " DecodeIdx = (unsigned)decodeULEB128(Ptr, &Len); \\\n" |
| 2279 |
-+ << " Ptr += Len; \\\n" |
| 2280 |
-+ << " MCInst_setOpcode(MI, Opc); \\\n" |
| 2281 |
-+ << " return decoder(S, DecodeIdx, insn, MI, Address, MRI); \\\n" |
| 2282 |
-+ << " } \\\n" |
| 2283 |
-+ << " case MCD_OPC_SoftFail: { \\\n" |
| 2284 |
-+ << " PositiveMask = (InsnType)decodeULEB128(++Ptr, &Len); \\\n" |
| 2285 |
-+ << " Ptr += Len; \\\n" |
| 2286 |
-+ << " NegativeMask = (InsnType)decodeULEB128(Ptr, &Len); \\\n" |
| 2287 |
-+ << " Ptr += Len; \\\n" |
| 2288 |
-+ << " Fail = (insn & PositiveMask) || (~insn & NegativeMask); \\\n" |
| 2289 |
-+ << " if (Fail) \\\n" |
| 2290 |
-+ << " S = MCDisassembler_SoftFail; \\\n" |
| 2291 |
-+ << " break; \\\n" |
| 2292 |
-+ << " } \\\n" |
| 2293 |
-+ << " case MCD_OPC_Fail: { \\\n" |
| 2294 |
-+ << " return MCDisassembler_Fail; \\\n" |
| 2295 |
-+ << " } \\\n" |
| 2296 |
-+ << " } \\\n" |
| 2297 |
-+ << " } \\\n" |
| 2298 |
-+#endif |
| 2299 |
-+ |
| 2300 |
-+#ifdef CAPSTONE |
| 2301 |
-+ OS << "static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], " |
| 2302 |
-+ |
| 2303 |
-+ "MCInst *MI,\\\n" |
| 2304 |
-+ << " InsnType insn, uint64_t " |
| 2305 |
-+ "Address,\\\n" |
| 2306 |
-+ << " const void *DisAsm,\\\n" |
| 2307 |
-+ << " int feature) {\\\n" |
| 2308 |
-+ << " uint64_t Bits = getFeatureBits(feature); \\\n" |
| 2309 |
-+ //<< " const FeatureBitset& Bits = STI.getFeatureBits();\n" |
| 2310 |
-+ << "\\\n" |
| 2311 |
-+ << " const uint8_t *Ptr = DecodeTable;\\\n" |
| 2312 |
-+ << " uint32_t CurFieldValue = 0;\\\n" |
| 2313 |
-+ << " DecodeStatus S = MCDisassembler_Success;\\\n" |
| 2314 |
-+ << " while (true) {\\\n" |
| 2315 |
-+ << " ptrdiff_t Loc = Ptr - DecodeTable;\\\n" |
| 2316 |
-+ << " switch (*Ptr) {\\\n" |
| 2317 |
-+ << " default:\\\n" |
| 2318 |
-+ << " return MCDisassembler_Fail;\\\n" |
| 2319 |
-+ << " case MCD_OPC_ExtractField: {\\\n" |
| 2320 |
-+ << " unsigned Start = *++Ptr;\\\n" |
| 2321 |
-+ << " unsigned Len = *++Ptr;\\\n" |
| 2322 |
-+ << " ++Ptr;\\\n" |
| 2323 |
-+ << " CurFieldValue = fieldFromInstruction(insn, Start, Len);\\\n" |
| 2324 |
-+ << " break;\\\n" |
| 2325 |
-+ << " }\\\n" |
| 2326 |
-+ << " case MCD_OPC_FilterValue: {\\\n" |
| 2327 |
-+ << " // Decode the field value.\\\n" |
| 2328 |
-+ << " unsigned Len;\\\n" |
| 2329 |
-+ << " InsnType Val = decodeULEB128(++Ptr, &Len);\\\n" |
| 2330 |
-+ << " Ptr += Len;\\\n" |
| 2331 |
-+ << " // NumToSkip is a plain 24-bit integer.\\\n" |
| 2332 |
-+ << " unsigned NumToSkip = *Ptr++;\\\n" |
| 2333 |
-+ << " NumToSkip |= (*Ptr++) << 8;\\\n" |
| 2334 |
-+ << " NumToSkip |= (*Ptr++) << 16;\\\n" |
| 2335 |
-+ << "\\\n" |
| 2336 |
-+ << " // Perform the filter operation.\\\n" |
| 2337 |
-+ << " if (Val != CurFieldValue)\\\n" |
| 2338 |
-+ << " Ptr += NumToSkip;\\\n" |
| 2339 |
-+ << "\\\n" |
| 2340 |
-+ << " break;\\\n" |
| 2341 |
-+ << " }\\\n" |
| 2342 |
-+ << " case MCD_OPC_CheckField: {\\\n" |
| 2343 |
-+ << " unsigned Start = *++Ptr;\\\n" |
| 2344 |
-+ << " unsigned Len = *++Ptr;\\\n" |
| 2345 |
-+ << " InsnType FieldValue = fieldFromInstruction(insn, Start, Len);\\\n" |
| 2346 |
-+ << " // Decode the field value.\\\n" |
| 2347 |
-+ << " uint32_t ExpectedValue = decodeULEB128(++Ptr, &Len);\\\n" |
| 2348 |
-+ << " Ptr += Len;\\\n" |
| 2349 |
-+ << " // NumToSkip is a plain 24-bit integer.\\\n" |
| 2350 |
-+ << " unsigned NumToSkip = *Ptr++;\\\n" |
| 2351 |
-+ << " NumToSkip |= (*Ptr++) << 8;\\\n" |
| 2352 |
-+ << " NumToSkip |= (*Ptr++) << 16;\\\n" |
| 2353 |
-+ << "\\\n" |
| 2354 |
-+ << " // If the actual and expected values don't match, skip.\\\n" |
| 2355 |
-+ << " if (ExpectedValue != FieldValue)\\\n" |
| 2356 |
-+ << " Ptr += NumToSkip;\\\n" |
| 2357 |
-+ << " break;\\\n" |
| 2358 |
-+ << " }\\\n" |
| 2359 |
-+ << " case MCD_OPC_CheckPredicate: {\\\n" |
| 2360 |
-+ << " unsigned Len;\\\n" |
| 2361 |
-+ << " // Decode the Predicate Index value.\\\n" |
| 2362 |
-+ << " unsigned PIdx = decodeULEB128(++Ptr, &Len);\\\n" |
| 2363 |
-+ << " Ptr += Len;\\\n" |
| 2364 |
-+ << " // NumToSkip is a plain 24-bit integer.\\\n" |
| 2365 |
-+ << " unsigned NumToSkip = *Ptr++;\\\n" |
| 2366 |
-+ << " NumToSkip |= (*Ptr++) << 8;\\\n" |
| 2367 |
-+ << " NumToSkip |= (*Ptr++) << 16;\\\n" |
| 2368 |
-+ << " // Check the predicate.\\\n" |
| 2369 |
-+ << " bool Pred;\\\n" |
| 2370 |
-+ << " if (!(Pred = checkDecoderPredicate(PIdx, Bits)))\\\n" |
| 2371 |
-+ << " Ptr += NumToSkip;\\\n" |
| 2372 |
-+ << " (void)Pred;\\\n" |
| 2373 |
-+ << " break;\\\n" |
| 2374 |
-+ << " }\\\n" |
| 2375 |
-+ << " case MCD_OPC_Decode: {\\\n" |
| 2376 |
-+ << " unsigned Len;\\\n" |
| 2377 |
-+ << " // Decode the Opcode value.\\\n" |
| 2378 |
-+ << " unsigned Opc = decodeULEB128(++Ptr, &Len);\\\n" |
| 2379 |
-+ << " Ptr += Len;\\\n" |
| 2380 |
-+ << " unsigned DecodeIdx = decodeULEB128(Ptr, &Len);\\\n" |
| 2381 |
-+ << " Ptr += Len;\\\n" |
| 2382 |
-+ << "\\\n" |
| 2383 |
-+ << " MCInst_clear(MI);\\\n" |
| 2384 |
-+ << " MCInst_setOpcode(MI, Opc);\\\n" |
| 2385 |
-+ << " bool DecodeComplete;\\\n" |
| 2386 |
-+ << " S = decodeToMCInst(S, DecodeIdx, insn, MI, Address, DisAsm, " |
| 2387 |
-+ "DecodeComplete);\\\n" |
| 2388 |
-+ << " assert(DecodeComplete);\\\n" |
| 2389 |
-+ << "\\\n" |
| 2390 |
-+ << " return S;\\\n" |
| 2391 |
-+ << " }\\\n" |
| 2392 |
-+ << " case MCD_OPC_TryDecode: {\\\n" |
| 2393 |
-+ << " unsigned Len;\\\n" |
| 2394 |
-+ << " // Decode the Opcode value.\\\n" |
| 2395 |
-+ << " unsigned Opc = decodeULEB128(++Ptr, &Len);\\\n" |
| 2396 |
-+ << " Ptr += Len;\\\n" |
| 2397 |
-+ << " unsigned DecodeIdx = decodeULEB128(Ptr, &Len);\\\n" |
| 2398 |
-+ << " Ptr += Len;\\\n" |
| 2399 |
-+ << " // NumToSkip is a plain 24-bit integer.\\\n" |
| 2400 |
-+ << " unsigned NumToSkip = *Ptr++;\\\n" |
| 2401 |
-+ << " NumToSkip |= (*Ptr++) << 8;\\\n" |
| 2402 |
-+ << " NumToSkip |= (*Ptr++) << 16;\\\n" |
| 2403 |
-+ << "\\\n" |
| 2404 |
-+ << " // Perform the decode operation.\\\n" |
| 2405 |
-+ << " MCInst TmpMI;\\\n" |
| 2406 |
-+ << " MCInst_setOpcode(&TmpMI, Opc);\\\n" |
| 2407 |
-+ << " bool DecodeComplete;\n" |
| 2408 |
-+ << " S = decodeToMCInst(S, DecodeIdx, insn, &TmpMI, Address, DisAsm, " |
| 2409 |
-+ "DecodeComplete);\\\n" |
| 2410 |
-+ << " if (DecodeComplete) {\\\n" |
| 2411 |
-+ << " // Decoding complete.\\\n" |
| 2412 |
-+ << " MI = &TmpMI;\\\n" |
| 2413 |
-+ << " return S;\\\n" |
| 2414 |
-+ << " } else {\\\n" |
| 2415 |
-+ << " assert(S == MCDisassembler_Fail);\\\n" |
| 2416 |
-+ << " // If the decoding was incomplete, skip.\\\n" |
| 2417 |
-+ << " Ptr += NumToSkip;\\\n" |
| 2418 |
-+ << " // Reset decode status. This also drops a SoftFail status " |
| 2419 |
-+ "that could be\\\n" |
| 2420 |
-+ << " // set before the decode attempt.\\\n" |
| 2421 |
-+ << " S = MCDisassembler_Success;\\\n" |
| 2422 |
-+ << " }\\\n" |
| 2423 |
-+ << " break;\\\n" |
| 2424 |
-+ << " }\\\n" |
| 2425 |
-+ << " case MCD_OPC_SoftFail: {\\\n" |
| 2426 |
-+ << " // Decode the mask values.\\\n" |
| 2427 |
-+ << " unsigned Len;\\\n" |
| 2428 |
-+ << " InsnType PositiveMask = decodeULEB128(++Ptr, &Len);\\\n" |
| 2429 |
-+ << " Ptr += Len;\\\n" |
| 2430 |
-+ << " InsnType NegativeMask = decodeULEB128(Ptr, &Len);\\\n" |
| 2431 |
-+ << " Ptr += Len;\\\n" |
| 2432 |
-+ << " bool Fail = (insn & PositiveMask) || (~insn & NegativeMask);\\\n" |
| 2433 |
-+ << " if (Fail)\\\n" |
| 2434 |
-+ << " S = MCDisassembler_SoftFail;\\\n" |
| 2435 |
-+ << " break;\\\n" |
| 2436 |
-+ << " }\\\n" |
| 2437 |
-+ << " case MCD_OPC_Fail: {\\\n" |
| 2438 |
-+ << " return MCDisassembler_Fail;\\\n" |
| 2439 |
-+ << " }\\\n" |
| 2440 |
-+ << " }\\\n" |
| 2441 |
-+ << " }\\\n" |
| 2442 |
-+ << " assert(0);\\\n" |
| 2443 |
-+ |
| 2444 |
-+#else |
| 2445 |
- OS << "template<typename InsnType>\n" |
| 2446 |
- << "static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], " |
| 2447 |
- "MCInst &MI,\n" |
| 2448 |
-@@ -2313,12 +2655,19 @@ static void emitDecodeInstruction(formatted_raw_ostream &OS) { |
| 2449 |
- << " }\n" |
| 2450 |
- << " llvm_unreachable(\"bogosity detected in disassembler state " |
| 2451 |
- "machine!\");\n" |
| 2452 |
-+#endif |
| 2453 |
- << "}\n\n"; |
| 2454 |
- } |
| 2455 |
- |
| 2456 |
- // Emits disassembler code for instruction decoding. |
| 2457 |
- void FixedLenDecoderEmitter::run(raw_ostream &o) { |
| 2458 |
- formatted_raw_ostream OS(o); |
| 2459 |
-+#ifdef CAPSTONE |
| 2460 |
-+ OS << "#include \"../../MCInst.h\"\n"; |
| 2461 |
-+ OS << "#include \"../../LEB128.h\"\n"; |
| 2462 |
-+ OS << "#include <assert.h>\n"; |
| 2463 |
-+ OS << "\n"; |
| 2464 |
-+#else |
| 2465 |
- OS << "#include \"llvm/MC/MCInst.h\"\n"; |
| 2466 |
- OS << "#include \"llvm/Support/Debug.h\"\n"; |
| 2467 |
- OS << "#include \"llvm/Support/DataTypes.h\"\n"; |
| 2468 |
-@@ -2327,6 +2676,7 @@ void FixedLenDecoderEmitter::run(raw_ostream &o) { |
| 2469 |
- OS << "#include <assert.h>\n"; |
| 2470 |
- OS << '\n'; |
| 2471 |
- OS << "namespace llvm {\n\n"; |
| 2472 |
-+#endif |
| 2473 |
- |
| 2474 |
- emitFieldFromInstruction(OS); |
| 2475 |
- |
| 2476 |
-@@ -2401,7 +2751,13 @@ void FixedLenDecoderEmitter::run(raw_ostream &o) { |
| 2477 |
- // Emit the main entry point for the decoder, decodeInstruction(). |
| 2478 |
- emitDecodeInstruction(OS); |
| 2479 |
- |
| 2480 |
-+#ifdef CAPSTONE |
| 2481 |
-+ OS << "FieldFromInstruction(fieldFromInstruction, uint64_t)\n"; |
| 2482 |
-+ OS << "DecodeToMCInst(decodeToMCInst, fieldFromInstruction, uint64_t)\n"; |
| 2483 |
-+ OS << "DecodeInstruction(decodeInstruction, fieldFromInstruction, decodeToMCInst, uint64_t)\n"; |
| 2484 |
-+#else |
| 2485 |
- OS << "\n} // End llvm namespace\n"; |
| 2486 |
-+#endif |
| 2487 |
- } |
| 2488 |
- |
| 2489 |
- namespace llvm { |
| 2490 |
-diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp |
| 2491 |
-index fd8775023..797f42a50 100644 |
| 2492 |
---- a/llvm/utils/TableGen/InstrInfoEmitter.cpp |
| 2493 |
-+++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp |
| 2494 |
-@@ -92,6 +92,7 @@ private: |
| 2495 |
- |
| 2496 |
- } // end anonymous namespace |
| 2497 |
- |
| 2498 |
-+#ifndef CAPSTONE |
| 2499 |
- static void PrintDefList(const std::vector<Record*> &Uses, |
| 2500 |
- unsigned Num, raw_ostream &OS) { |
| 2501 |
- OS << "static const MCPhysReg ImplicitList" << Num << "[] = { "; |
| 2502 |
-@@ -99,6 +100,7 @@ static void PrintDefList(const std::vector<Record*> &Uses, |
| 2503 |
- OS << getQualifiedName(U) << ", "; |
| 2504 |
- OS << "0 };\n"; |
| 2505 |
- } |
| 2506 |
-+#endif |
| 2507 |
- |
| 2508 |
- //===----------------------------------------------------------------------===// |
| 2509 |
- // Operand Info Emission. |
| 2510 |
-@@ -434,8 +436,17 @@ void InstrInfoEmitter::emitTIIHelperMethods(raw_ostream &OS, |
| 2511 |
- // run - Emit the main instruction description records for the target... |
| 2512 |
- void InstrInfoEmitter::run(raw_ostream &OS) { |
| 2513 |
- emitSourceFileHeader("Target Instruction Enum Values and Descriptors", OS); |
| 2514 |
-+ |
| 2515 |
-+#ifdef CAPSTONE |
| 2516 |
-+ OS << "/* Capstone Disassembly Engine */\n" |
| 2517 |
-+ "/* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */\n" |
| 2518 |
-+ "\n" |
| 2519 |
-+ "\n"; |
| 2520 |
-+#endif |
| 2521 |
-+ |
| 2522 |
- emitEnums(OS); |
| 2523 |
- |
| 2524 |
-+#ifndef CAPSTONE |
| 2525 |
- OS << "#ifdef GET_INSTRINFO_MC_DESC\n"; |
| 2526 |
- OS << "#undef GET_INSTRINFO_MC_DESC\n"; |
| 2527 |
- |
| 2528 |
-@@ -563,6 +574,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) { |
| 2529 |
- emitOperandTypesEnum(OS, Target); |
| 2530 |
- |
| 2531 |
- emitMCIIHelperMethods(OS, TargetName); |
| 2532 |
-+#endif |
| 2533 |
- } |
| 2534 |
- |
| 2535 |
- void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num, |
| 2536 |
-@@ -680,7 +692,9 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) { |
| 2537 |
- OS << "#ifdef GET_INSTRINFO_ENUM\n"; |
| 2538 |
- OS << "#undef GET_INSTRINFO_ENUM\n"; |
| 2539 |
- |
| 2540 |
-+#ifndef CAPSTONE |
| 2541 |
- OS << "namespace llvm {\n\n"; |
| 2542 |
-+#endif |
| 2543 |
- |
| 2544 |
- CodeGenTarget Target(Records); |
| 2545 |
- |
| 2546 |
-@@ -690,17 +704,39 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) { |
| 2547 |
- if (Namespace.empty()) |
| 2548 |
- PrintFatalError("No instructions defined!"); |
| 2549 |
- |
| 2550 |
-+#ifndef CAPSTONE |
| 2551 |
- OS << "namespace " << Namespace << " {\n"; |
| 2552 |
-- OS << " enum {\n"; |
| 2553 |
-+#endif |
| 2554 |
-+#ifdef CAPSTONE |
| 2555 |
-+ OS << "\n" |
| 2556 |
-+#else |
| 2557 |
-+ OS << " " |
| 2558 |
-+#endif |
| 2559 |
-+ << "enum {\n"; |
| 2560 |
- unsigned Num = 0; |
| 2561 |
- for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) |
| 2562 |
-- OS << " " << Inst->TheDef->getName() << "\t= " << Num++ << ",\n"; |
| 2563 |
-- OS << " INSTRUCTION_LIST_END = " << Num << "\n"; |
| 2564 |
-+ OS << " " |
| 2565 |
-+#ifdef CAPSTONE |
| 2566 |
-+ << Target.getName() << "_" |
| 2567 |
-+#endif |
| 2568 |
-+ << Inst->TheDef->getName() << "\t= " << Num++ << ",\n"; |
| 2569 |
-+ OS << " " |
| 2570 |
-+#ifdef CAPSTONE |
| 2571 |
-+ << Target.getName() << "_" |
| 2572 |
-+#endif |
| 2573 |
-+ << "INSTRUCTION_LIST_END = " << Num << "\n"; |
| 2574 |
- OS << " };\n\n"; |
| 2575 |
-+#ifndef CAPSTONE |
| 2576 |
- OS << "} // end " << Namespace << " namespace\n"; |
| 2577 |
- OS << "} // end llvm namespace\n"; |
| 2578 |
-- OS << "#endif // GET_INSTRINFO_ENUM\n\n"; |
| 2579 |
-- |
| 2580 |
-+#endif |
| 2581 |
-+ OS << "#endif // GET_INSTRINFO_ENUM\n" |
| 2582 |
-+#ifndef CAPSTONE |
| 2583 |
-+ << "\n" |
| 2584 |
-+#endif |
| 2585 |
-+ ; |
| 2586 |
-+ |
| 2587 |
-+#ifndef CAPSTONE |
| 2588 |
- OS << "#ifdef GET_INSTRINFO_SCHED_ENUM\n"; |
| 2589 |
- OS << "#undef GET_INSTRINFO_SCHED_ENUM\n"; |
| 2590 |
- OS << "namespace llvm {\n\n"; |
| 2591 |
-@@ -717,13 +753,140 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) { |
| 2592 |
- OS << "} // end llvm namespace\n"; |
| 2593 |
- |
| 2594 |
- OS << "#endif // GET_INSTRINFO_SCHED_ENUM\n\n"; |
| 2595 |
-+#endif |
| 2596 |
- } |
| 2597 |
- |
| 2598 |
- namespace llvm { |
| 2599 |
- |
| 2600 |
- void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) { |
| 2601 |
- InstrInfoEmitter(RK).run(OS); |
| 2602 |
-+#ifndef CAPSTONE |
| 2603 |
- EmitMapTable(RK, OS); |
| 2604 |
-+#endif |
| 2605 |
-+} |
| 2606 |
-+ |
| 2607 |
-+#ifdef CAPSTONE |
| 2608 |
-+std::string GetPublicName(const CodeGenInstruction *Inst) { |
| 2609 |
-+ std::string Name = Inst->TheDef->getName(); |
| 2610 |
-+ // Apply backward compatibility fixups. |
| 2611 |
-+ // BRNLE -> BNLER. |
| 2612 |
-+ if (Name.length() >= 5 && Name.substr(0, 5) == "BRAsm") { |
| 2613 |
-+ Name = "B" + Name.substr(5, Name.length() - 5) + "R"; |
| 2614 |
-+ } |
| 2615 |
-+ // SSKEOpt -> SSKE. |
| 2616 |
-+ while (Name.length() >= 3 && Name.substr(Name.length() - 3, 3) == "Opt") { |
| 2617 |
-+ Name = Name.substr(0, Name.length() - 3); |
| 2618 |
-+ } |
| 2619 |
-+ // BRCLAsm -> BRCL. |
| 2620 |
-+ while (true) { |
| 2621 |
-+ size_t pos = Name.find("Asm"); |
| 2622 |
-+ if (pos == std::string::npos) { |
| 2623 |
-+ break; |
| 2624 |
-+ } |
| 2625 |
-+ Name = Name.substr(0, pos) + Name.substr(pos + 3); |
| 2626 |
-+ } |
| 2627 |
-+ // CPSDRxx -> CPSDR. |
| 2628 |
-+ if (Name.length() >= 2) { |
| 2629 |
-+ std::string Suffix2 = Name.substr(Name.length() - 2, 2); |
| 2630 |
-+ if (Suffix2 == "dd" || Suffix2 == "ds" || |
| 2631 |
-+ Suffix2 == "sd" || Suffix2 == "ss") { |
| 2632 |
-+ Name = Name.substr(0, Name.length() - 2); |
| 2633 |
-+ } |
| 2634 |
-+ } |
| 2635 |
-+ return "SYSZ_INS_" + Name; |
| 2636 |
-+} |
| 2637 |
-+ |
| 2638 |
-+std::string GetRegisterName(Record *Reg) { |
| 2639 |
-+ std::string Name = Reg->getName(); |
| 2640 |
-+ for (char& c : Name) { |
| 2641 |
-+ c = toupper(c); |
| 2642 |
-+ } |
| 2643 |
-+ // R0L, R0D -> R0. |
| 2644 |
-+ if (Name.length() >= 3 && |
| 2645 |
-+ Name[Name.length() - 3] == 'R' && |
| 2646 |
-+ (Name[Name.length() - 1] == 'L' || |
| 2647 |
-+ Name[Name.length() - 1] == 'D')) { |
| 2648 |
-+ Name = Name.substr(0, Name.length() - 3) + Name[Name.length() - 2]; |
| 2649 |
-+ } |
| 2650 |
-+ return "SYSZ_REG_" + Name; |
| 2651 |
-+} |
| 2652 |
-+ |
| 2653 |
-+std::string GetGroupName(Record *Pred) { |
| 2654 |
-+ std::string Name = Pred->getName(); |
| 2655 |
-+ for (char& c : Name) { |
| 2656 |
-+ c = toupper(c); |
| 2657 |
-+ } |
| 2658 |
-+ if (Name.length() >= 7 && Name.substr(0, 7) == "FEATURE") { |
| 2659 |
-+ Name = Name.substr(7); |
| 2660 |
-+ } |
| 2661 |
-+ return "SYSZ_GRP_" + Name; |
| 2662 |
-+} |
| 2663 |
-+ |
| 2664 |
-+void EmitMappingInsn(RecordKeeper &RK, raw_ostream &OS) { |
| 2665 |
-+ OS << "// This is auto-gen data for Capstone engine (www.capstone-engine.org)\n" |
| 2666 |
-+ "// By Nguyen Anh Quynh <[email protected]>\n" |
| 2667 |
-+ "\n"; |
| 2668 |
-+ CodeGenTarget Target(RK); |
| 2669 |
-+ for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) { |
| 2670 |
-+ if (Inst->TheDef->getValueAsBit("isPseudo") || |
| 2671 |
-+ Inst->TheDef->getValueAsBit("isCodeGenOnly")) { |
| 2672 |
-+ continue; |
| 2673 |
-+ } |
| 2674 |
-+ OS << "{\n" |
| 2675 |
-+ << "\t" << Target.getName() << "_" << Inst->TheDef->getName() << ", " |
| 2676 |
-+ << GetPublicName(Inst) << ",\n" |
| 2677 |
-+ << "#ifndef CAPSTONE_DIET\n" |
| 2678 |
-+ << "\t{ "; |
| 2679 |
-+ for (Record *Use : Inst->TheDef->getValueAsListOfDefs("Uses")) { |
| 2680 |
-+ OS << GetRegisterName(Use) << ", "; |
| 2681 |
-+ } |
| 2682 |
-+ OS << "0 }, { "; |
| 2683 |
-+ for (Record *Def : Inst->TheDef->getValueAsListOfDefs("Defs")) { |
| 2684 |
-+ OS << GetRegisterName(Def) << ", "; |
| 2685 |
-+ } |
| 2686 |
-+ OS << "0 }, { "; |
| 2687 |
-+ ListInit *Predicates = Inst->TheDef->getValueAsListInit("Predicates"); |
| 2688 |
-+ for (unsigned i = 0; i < Predicates->size(); ++i) { |
| 2689 |
-+ OS << GetGroupName(Predicates->getElementAsRecord(i)) << ", "; |
| 2690 |
-+ } |
| 2691 |
-+ OS << "0 }, " |
| 2692 |
-+ << Inst->TheDef->getValueAsBit("isBranch") |
| 2693 |
-+ << ", " |
| 2694 |
-+ << Inst->TheDef->getValueAsBit("isIndirectBranch") |
| 2695 |
-+ << "\n" |
| 2696 |
-+ << "#endif\n" |
| 2697 |
-+ << "},\n"; |
| 2698 |
-+ } |
| 2699 |
-+} |
| 2700 |
-+ |
| 2701 |
-+std::string GetMnemonic(const CodeGenInstruction *Inst) { |
| 2702 |
-+ std::string Mnemonic = Inst->AsmString; |
| 2703 |
-+ |
| 2704 |
-+ for (size_t i = 0; i < Mnemonic.length(); i++) { |
| 2705 |
-+ if (Mnemonic[i] == '\t') { |
| 2706 |
-+ return Mnemonic.substr(0, i); |
| 2707 |
-+ } |
| 2708 |
-+ } |
| 2709 |
-+ return Mnemonic; |
| 2710 |
-+} |
| 2711 |
-+ |
| 2712 |
-+void EmitInsnNameMaps(RecordKeeper &RK, raw_ostream &OS) { |
| 2713 |
-+ OS << "// This is auto-gen data for Capstone engine (www.capstone-engine.org)\n" |
| 2714 |
-+ "// By Nguyen Anh Quynh <[email protected]>\n" |
| 2715 |
-+ "\n"; |
| 2716 |
-+ CodeGenTarget Target(RK); |
| 2717 |
-+ std::map<std::string, std::string> M; |
| 2718 |
-+ for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) { |
| 2719 |
-+ if (Inst->TheDef->getValueAsBit("isPseudo") || |
| 2720 |
-+ Inst->TheDef->getValueAsBit("isCodeGenOnly")) { |
| 2721 |
-+ continue; |
| 2722 |
-+ } |
| 2723 |
-+ M[GetPublicName(Inst)] = GetMnemonic(Inst); |
| 2724 |
-+ } |
| 2725 |
-+ for (auto &P : M) { |
| 2726 |
-+ OS << "\t{ " << P.first << ", \"" << P.second << "\" },\n"; |
| 2727 |
-+ } |
| 2728 |
- } |
| 2729 |
-+#endif |
| 2730 |
- |
| 2731 |
- } // end llvm namespace |
| 2732 |
-diff --git a/llvm/utils/TableGen/RegisterInfoEmitter.cpp b/llvm/utils/TableGen/RegisterInfoEmitter.cpp |
| 2733 |
-index 1b619072c..0df306680 100644 |
| 2734 |
---- a/llvm/utils/TableGen/RegisterInfoEmitter.cpp |
| 2735 |
-+++ b/llvm/utils/TableGen/RegisterInfoEmitter.cpp |
| 2736 |
-@@ -98,6 +98,12 @@ private: |
| 2737 |
- |
| 2738 |
- } // end anonymous namespace |
| 2739 |
- |
| 2740 |
-+#ifdef CAPSTONE |
| 2741 |
-+#define NAME_PREFIX Target.getName() << "_" << |
| 2742 |
-+#else |
| 2743 |
-+#define NAME_PREFIX |
| 2744 |
-+#endif |
| 2745 |
-+ |
| 2746 |
- // runEnums - Print out enum values for all of the registers. |
| 2747 |
- void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 2748 |
- CodeGenTarget &Target, CodeGenRegBank &Bank) { |
| 2749 |
-@@ -106,13 +112,22 @@ void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 2750 |
- // Register enums are stored as uint16_t in the tables. Make sure we'll fit. |
| 2751 |
- assert(Registers.size() <= 0xffff && "Too many regs to fit in tables"); |
| 2752 |
- |
| 2753 |
-+#ifndef CAPSTONE |
| 2754 |
- StringRef Namespace = Registers.front().TheDef->getValueAsString("Namespace"); |
| 2755 |
-+#endif |
| 2756 |
- |
| 2757 |
- emitSourceFileHeader("Target Register Enum Values", OS); |
| 2758 |
- |
| 2759 |
-+#ifdef CAPSTONE |
| 2760 |
-+ OS << "/* Capstone Disassembly Engine */\n" |
| 2761 |
-+ "/* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */\n" |
| 2762 |
-+ "\n"; |
| 2763 |
-+#endif |
| 2764 |
-+ |
| 2765 |
- OS << "\n#ifdef GET_REGINFO_ENUM\n"; |
| 2766 |
- OS << "#undef GET_REGINFO_ENUM\n\n"; |
| 2767 |
- |
| 2768 |
-+#ifndef CAPSTONE |
| 2769 |
- OS << "namespace llvm {\n\n"; |
| 2770 |
- |
| 2771 |
- OS << "class MCRegisterClass;\n" |
| 2772 |
-@@ -121,16 +136,20 @@ void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 2773 |
- |
| 2774 |
- if (!Namespace.empty()) |
| 2775 |
- OS << "namespace " << Namespace << " {\n"; |
| 2776 |
-- OS << "enum {\n NoRegister,\n"; |
| 2777 |
-+#endif |
| 2778 |
-+ |
| 2779 |
-+ OS << "enum {\n " << NAME_PREFIX "NoRegister,\n"; |
| 2780 |
- |
| 2781 |
- for (const auto &Reg : Registers) |
| 2782 |
-- OS << " " << Reg.getName() << " = " << Reg.EnumValue << ",\n"; |
| 2783 |
-+ OS << " " << NAME_PREFIX Reg.getName() << " = " << Reg.EnumValue << ",\n"; |
| 2784 |
- assert(Registers.size() == Registers.back().EnumValue && |
| 2785 |
- "Register enum value mismatch!"); |
| 2786 |
-- OS << " NUM_TARGET_REGS \t// " << Registers.size()+1 << "\n"; |
| 2787 |
-+ OS << " " << NAME_PREFIX "NUM_TARGET_REGS \t// " << Registers.size()+1 << "\n"; |
| 2788 |
- OS << "};\n"; |
| 2789 |
-+#ifndef CAPSTONE |
| 2790 |
- if (!Namespace.empty()) |
| 2791 |
- OS << "} // end namespace " << Namespace << "\n"; |
| 2792 |
-+#endif |
| 2793 |
- |
| 2794 |
- const auto &RegisterClasses = Bank.getRegClasses(); |
| 2795 |
- if (!RegisterClasses.empty()) { |
| 2796 |
-@@ -139,18 +158,29 @@ void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 2797 |
- assert(RegisterClasses.size() <= 0xffff && |
| 2798 |
- "Too many register classes to fit in tables"); |
| 2799 |
- |
| 2800 |
-- OS << "\n// Register classes\n\n"; |
| 2801 |
-+ OS << "\n// Register classes\n"; |
| 2802 |
-+#ifndef CAPSTONE |
| 2803 |
-+ OS << "\n"; |
| 2804 |
- if (!Namespace.empty()) |
| 2805 |
- OS << "namespace " << Namespace << " {\n"; |
| 2806 |
-+#endif |
| 2807 |
- OS << "enum {\n"; |
| 2808 |
- for (const auto &RC : RegisterClasses) |
| 2809 |
-- OS << " " << RC.getName() << "RegClassID" |
| 2810 |
-+ OS << " " << NAME_PREFIX RC.getName() << "RegClassID" |
| 2811 |
- << " = " << RC.EnumValue << ",\n"; |
| 2812 |
-- OS << "\n };\n"; |
| 2813 |
-+#ifdef CAPSTONE |
| 2814 |
-+ OS |
| 2815 |
-+#else |
| 2816 |
-+ OS << "\n " |
| 2817 |
-+#endif |
| 2818 |
-+ << "};\n"; |
| 2819 |
-+#ifndef CAPSTONE |
| 2820 |
- if (!Namespace.empty()) |
| 2821 |
- OS << "} // end namespace " << Namespace << "\n\n"; |
| 2822 |
-+#endif |
| 2823 |
- } |
| 2824 |
- |
| 2825 |
-+#ifndef CAPSTONE |
| 2826 |
- const std::vector<Record*> &RegAltNameIndices = Target.getRegAltNameIndices(); |
| 2827 |
- // If the only definition is the default NoRegAltName, we don't need to |
| 2828 |
- // emit anything. |
| 2829 |
-@@ -181,8 +211,11 @@ void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 2830 |
- if (!Namespace.empty()) |
| 2831 |
- OS << "} // end namespace " << Namespace << "\n\n"; |
| 2832 |
- } |
| 2833 |
-+#endif |
| 2834 |
- |
| 2835 |
-+#ifndef CAPSTONE |
| 2836 |
- OS << "} // end namespace llvm\n\n"; |
| 2837 |
-+#endif |
| 2838 |
- OS << "#endif // GET_REGINFO_ENUM\n\n"; |
| 2839 |
- } |
| 2840 |
- |
| 2841 |
-@@ -869,7 +902,9 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 2842 |
- |
| 2843 |
- const auto &Regs = RegBank.getRegisters(); |
| 2844 |
- |
| 2845 |
-+#ifndef CAPSTONE |
| 2846 |
- auto &SubRegIndices = RegBank.getSubRegIndices(); |
| 2847 |
-+#endif |
| 2848 |
- // The lists of sub-registers and super-registers go in the same array. That |
| 2849 |
- // allows us to share suffixes. |
| 2850 |
- typedef std::vector<const CodeGenRegister*> RegVec; |
| 2851 |
-@@ -961,25 +996,40 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 2852 |
- LaneMaskSeqs.layout(); |
| 2853 |
- SubRegIdxSeqs.layout(); |
| 2854 |
- |
| 2855 |
-+#ifndef CAPSTONE |
| 2856 |
- OS << "namespace llvm {\n\n"; |
| 2857 |
-+#endif |
| 2858 |
- |
| 2859 |
- const std::string &TargetName = Target.getName(); |
| 2860 |
- |
| 2861 |
- // Emit the shared table of differential lists. |
| 2862 |
-- OS << "extern const MCPhysReg " << TargetName << "RegDiffLists[] = {\n"; |
| 2863 |
-+#ifdef CAPSTONE |
| 2864 |
-+ OS << "static" |
| 2865 |
-+#else |
| 2866 |
-+ OS << "extern" |
| 2867 |
-+#endif |
| 2868 |
-+ << " const MCPhysReg " << TargetName << "RegDiffLists[] = {\n"; |
| 2869 |
- DiffSeqs.emit(OS, printDiff16); |
| 2870 |
- OS << "};\n\n"; |
| 2871 |
- |
| 2872 |
-+#ifndef CAPSTONE |
| 2873 |
- // Emit the shared table of regunit lane mask sequences. |
| 2874 |
- OS << "extern const LaneBitmask " << TargetName << "LaneMaskLists[] = {\n"; |
| 2875 |
- LaneMaskSeqs.emit(OS, printMask, "LaneBitmask::getAll()"); |
| 2876 |
- OS << "};\n\n"; |
| 2877 |
-+#endif |
| 2878 |
- |
| 2879 |
- // Emit the table of sub-register indexes. |
| 2880 |
-- OS << "extern const uint16_t " << TargetName << "SubRegIdxLists[] = {\n"; |
| 2881 |
-+#ifdef CAPSTONE |
| 2882 |
-+ OS << "static" |
| 2883 |
-+#else |
| 2884 |
-+ OS << "extern" |
| 2885 |
-+#endif |
| 2886 |
-+ << " const uint16_t " << TargetName << "SubRegIdxLists[] = {\n"; |
| 2887 |
- SubRegIdxSeqs.emit(OS, printSubRegIndex); |
| 2888 |
- OS << "};\n\n"; |
| 2889 |
- |
| 2890 |
-+#ifndef CAPSTONE |
| 2891 |
- // Emit the table of sub-register index sizes. |
| 2892 |
- OS << "extern const MCRegisterInfo::SubRegCoveredBits " |
| 2893 |
- << TargetName << "SubRegIdxRanges[] = {\n"; |
| 2894 |
-@@ -989,14 +1039,22 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 2895 |
- << Idx.getName() << "\n"; |
| 2896 |
- } |
| 2897 |
- OS << "};\n\n"; |
| 2898 |
-+#endif |
| 2899 |
- |
| 2900 |
- // Emit the string table. |
| 2901 |
- RegStrings.layout(); |
| 2902 |
-+#ifndef CAPSTONE |
| 2903 |
- OS << "extern const char " << TargetName << "RegStrings[] = {\n"; |
| 2904 |
- RegStrings.emit(OS, printChar); |
| 2905 |
- OS << "};\n\n"; |
| 2906 |
-+#endif |
| 2907 |
- |
| 2908 |
-- OS << "extern const MCRegisterDesc " << TargetName |
| 2909 |
-+#ifdef CAPSTONE |
| 2910 |
-+ OS << "static" |
| 2911 |
-+#else |
| 2912 |
-+ OS << "extern" |
| 2913 |
-+#endif |
| 2914 |
-+ << " const MCRegisterDesc " << TargetName |
| 2915 |
- << "RegDesc[] = { // Descriptors\n"; |
| 2916 |
- OS << " { " << RegStrings.get("") << ", 0, 0, 0, 0, 0 },\n"; |
| 2917 |
- |
| 2918 |
-@@ -1012,6 +1070,7 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 2919 |
- } |
| 2920 |
- OS << "};\n\n"; // End of register descriptors... |
| 2921 |
- |
| 2922 |
-+#ifndef CAPSTONE |
| 2923 |
- // Emit the table of register unit roots. Each regunit has one or two root |
| 2924 |
- // registers. |
| 2925 |
- OS << "extern const MCPhysReg " << TargetName << "RegUnitRoots[][2] = {\n"; |
| 2926 |
-@@ -1025,11 +1084,14 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 2927 |
- OS << " },\n"; |
| 2928 |
- } |
| 2929 |
- OS << "};\n\n"; |
| 2930 |
-+#endif |
| 2931 |
- |
| 2932 |
- const auto &RegisterClasses = RegBank.getRegClasses(); |
| 2933 |
- |
| 2934 |
- // Loop over all of the register classes... emitting each one. |
| 2935 |
-+#ifndef CAPSTONE |
| 2936 |
- OS << "namespace { // Register classes...\n"; |
| 2937 |
-+#endif |
| 2938 |
- |
| 2939 |
- SequenceToOffsetTable<std::string> RegClassStrings; |
| 2940 |
- |
| 2941 |
-@@ -1044,15 +1106,28 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 2942 |
- |
| 2943 |
- // Emit the register list now. |
| 2944 |
- OS << " // " << Name << " Register Class...\n" |
| 2945 |
-- << " const MCPhysReg " << Name |
| 2946 |
-+ << " " |
| 2947 |
-+#ifdef CAPSTONE |
| 2948 |
-+ << "static " |
| 2949 |
-+#endif |
| 2950 |
-+ << "const MCPhysReg " << Name |
| 2951 |
- << "[] = {\n "; |
| 2952 |
- for (Record *Reg : Order) { |
| 2953 |
-- OS << getQualifiedName(Reg) << ", "; |
| 2954 |
-+#ifdef CAPSTONE |
| 2955 |
-+ OS << NAME_PREFIX Reg->getName() |
| 2956 |
-+#else |
| 2957 |
-+ OS << getQualifiedName(Reg) |
| 2958 |
-+#endif |
| 2959 |
-+ << ", "; |
| 2960 |
- } |
| 2961 |
- OS << "\n };\n\n"; |
| 2962 |
- |
| 2963 |
- OS << " // " << Name << " Bit set.\n" |
| 2964 |
-- << " const uint8_t " << Name |
| 2965 |
-+ << " " |
| 2966 |
-+#ifdef CAPSTONE |
| 2967 |
-+ << "static " |
| 2968 |
-+#endif |
| 2969 |
-+ << "const uint8_t " << Name |
| 2970 |
- << "Bits[] = {\n "; |
| 2971 |
- BitVectorEmitter BVE; |
| 2972 |
- for (Record *Reg : Order) { |
| 2973 |
-@@ -1062,14 +1137,23 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 2974 |
- OS << "\n };\n\n"; |
| 2975 |
- |
| 2976 |
- } |
| 2977 |
-+#ifndef CAPSTONE |
| 2978 |
- OS << "} // end anonymous namespace\n\n"; |
| 2979 |
-+#endif |
| 2980 |
- |
| 2981 |
- RegClassStrings.layout(); |
| 2982 |
-+#ifndef CAPSTONE |
| 2983 |
- OS << "extern const char " << TargetName << "RegClassStrings[] = {\n"; |
| 2984 |
- RegClassStrings.emit(OS, printChar); |
| 2985 |
- OS << "};\n\n"; |
| 2986 |
-+#endif |
| 2987 |
- |
| 2988 |
-- OS << "extern const MCRegisterClass " << TargetName |
| 2989 |
-+#ifdef CAPSTONE |
| 2990 |
-+ OS << "static" |
| 2991 |
-+#else |
| 2992 |
-+ OS << "extern" |
| 2993 |
-+#endif |
| 2994 |
-+ << " const MCRegisterClass " << TargetName |
| 2995 |
- << "MCRegisterClasses[] = {\n"; |
| 2996 |
- |
| 2997 |
- for (const auto &RC : RegisterClasses) { |
| 2998 |
-@@ -1077,13 +1161,20 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 2999 |
- OS << " { " << RC.getName() << ", " << RC.getName() << "Bits, " |
| 3000 |
- << RegClassStrings.get(RC.getName()) << ", " |
| 3001 |
- << RC.getOrder().size() << ", sizeof(" << RC.getName() << "Bits), " |
| 3002 |
-- << RC.getQualifiedName() + "RegClassID" << ", " |
| 3003 |
-+#ifdef CAPSTONE |
| 3004 |
-+ << NAME_PREFIX RC.getName() |
| 3005 |
-+#else |
| 3006 |
-+ << RC.getQualifiedName() |
| 3007 |
-+#endif |
| 3008 |
-+ << "RegClassID" << ", " |
| 3009 |
-+ //<< RegSize/8 << ", " |
| 3010 |
- << RC.CopyCost << ", " |
| 3011 |
- << ( RC.Allocatable ? "true" : "false" ) << " },\n"; |
| 3012 |
- } |
| 3013 |
- |
| 3014 |
- OS << "};\n\n"; |
| 3015 |
- |
| 3016 |
-+#ifndef CAPSTONE |
| 3017 |
- EmitRegMappingTables(OS, Regs, false); |
| 3018 |
- |
| 3019 |
- // Emit Reg encoding table |
| 3020 |
-@@ -1102,7 +1193,9 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 3021 |
- OS << " " << Value << ",\n"; |
| 3022 |
- } |
| 3023 |
- OS << "};\n"; // End of HW encoding table |
| 3024 |
-+#endif |
| 3025 |
- |
| 3026 |
-+#ifndef CAPSTONE |
| 3027 |
- // MCRegisterInfo initialization routine. |
| 3028 |
- OS << "static inline void Init" << TargetName |
| 3029 |
- << "MCRegisterInfo(MCRegisterInfo *RI, unsigned RA, " |
| 3030 |
-@@ -1123,7 +1216,12 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 3031 |
- OS << "}\n\n"; |
| 3032 |
- |
| 3033 |
- OS << "} // end namespace llvm\n\n"; |
| 3034 |
-- OS << "#endif // GET_REGINFO_MC_DESC\n\n"; |
| 3035 |
-+#endif |
| 3036 |
-+ OS << "#endif // GET_REGINFO_MC_DESC\n" |
| 3037 |
-+#ifndef CAPSTONE |
| 3038 |
-+ << "\n" |
| 3039 |
-+#endif |
| 3040 |
-+ ; |
| 3041 |
- } |
| 3042 |
- |
| 3043 |
- void |
| 3044 |
-@@ -1605,8 +1703,10 @@ void RegisterInfoEmitter::run(raw_ostream &OS) { |
| 3045 |
- CodeGenRegBank &RegBank = Target.getRegBank(); |
| 3046 |
- runEnums(OS, Target, RegBank); |
| 3047 |
- runMCDesc(OS, Target, RegBank); |
| 3048 |
-+#ifndef CAPSTONE |
| 3049 |
- runTargetHeader(OS, Target, RegBank); |
| 3050 |
- runTargetDesc(OS, Target, RegBank); |
| 3051 |
-+#endif |
| 3052 |
- |
| 3053 |
- if (RegisterInfoDebug) |
| 3054 |
- debugDump(errs()); |
| 3055 |
-diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp |
| 3056 |
-index 792c957ea..3ddfd1371 100644 |
| 3057 |
---- a/llvm/utils/TableGen/SubtargetEmitter.cpp |
| 3058 |
-+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp |
| 3059 |
-@@ -149,7 +149,9 @@ void SubtargetEmitter::Enumeration(raw_ostream &OS) { |
| 3060 |
- if (N > MAX_SUBTARGET_FEATURES) |
| 3061 |
- PrintFatalError("Too many subtarget features! Bump MAX_SUBTARGET_FEATURES."); |
| 3062 |
- |
| 3063 |
-+#ifndef CAPSTONE |
| 3064 |
- OS << "namespace " << Target << " {\n"; |
| 3065 |
-+#endif |
| 3066 |
- |
| 3067 |
- // Open enumeration. |
| 3068 |
- OS << "enum {\n"; |
| 3069 |
-@@ -160,12 +162,22 @@ void SubtargetEmitter::Enumeration(raw_ostream &OS) { |
| 3070 |
- Record *Def = DefList[i]; |
| 3071 |
- |
| 3072 |
- // Get and emit name |
| 3073 |
-- OS << " " << Def->getName() << " = " << i << ",\n"; |
| 3074 |
-+ OS << " " |
| 3075 |
-+#ifdef CAPSTONE |
| 3076 |
-+ << Target << "_" |
| 3077 |
-+#endif |
| 3078 |
-+ << Def->getName() << " = " |
| 3079 |
-+#ifdef CAPSTONE |
| 3080 |
-+ << "1ULL << " |
| 3081 |
-+#endif |
| 3082 |
-+ << i << ",\n"; |
| 3083 |
- } |
| 3084 |
- |
| 3085 |
- // Close enumeration and namespace |
| 3086 |
- OS << "};\n"; |
| 3087 |
-+#ifndef CAPSTONE |
| 3088 |
- OS << "} // end namespace " << Target << "\n"; |
| 3089 |
-+#endif |
| 3090 |
- } |
| 3091 |
- |
| 3092 |
- // |
| 3093 |
-@@ -1786,14 +1798,27 @@ void SubtargetEmitter::EmitMCInstrAnalysisPredicateFunctions(raw_ostream &OS) { |
| 3094 |
- void SubtargetEmitter::run(raw_ostream &OS) { |
| 3095 |
- emitSourceFileHeader("Subtarget Enumeration Source Fragment", OS); |
| 3096 |
- |
| 3097 |
-+#ifdef CAPSTONE |
| 3098 |
-+ OS << "/* Capstone Disassembly Engine, http://www.capstone-engine.org */\n" |
| 3099 |
-+ "/* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */\n" |
| 3100 |
-+ "\n"; |
| 3101 |
-+#endif |
| 3102 |
-+ |
| 3103 |
- OS << "\n#ifdef GET_SUBTARGETINFO_ENUM\n"; |
| 3104 |
- OS << "#undef GET_SUBTARGETINFO_ENUM\n\n"; |
| 3105 |
- |
| 3106 |
-+#ifndef CAPSTONE |
| 3107 |
- OS << "namespace llvm {\n"; |
| 3108 |
-+#endif |
| 3109 |
- Enumeration(OS); |
| 3110 |
-+#ifdef CAPSTONE |
| 3111 |
-+ OS << "\n"; |
| 3112 |
-+#else |
| 3113 |
- OS << "} // end namespace llvm\n\n"; |
| 3114 |
-+#endif |
| 3115 |
- OS << "#endif // GET_SUBTARGETINFO_ENUM\n\n"; |
| 3116 |
- |
| 3117 |
-+#ifndef CAPSTONE |
| 3118 |
- OS << "\n#ifdef GET_SUBTARGETINFO_MC_DESC\n"; |
| 3119 |
- OS << "#undef GET_SUBTARGETINFO_MC_DESC\n\n"; |
| 3120 |
- |
| 3121 |
-@@ -1942,6 +1967,7 @@ void SubtargetEmitter::run(raw_ostream &OS) { |
| 3122 |
- OS << "#endif // GET_SUBTARGETINFO_CTOR\n\n"; |
| 3123 |
- |
| 3124 |
- EmitMCInstrAnalysisPredicateFunctions(OS); |
| 3125 |
-+#endif |
| 3126 |
- } |
| 3127 |
- |
| 3128 |
- namespace llvm { |
| 3129 |
-diff --git a/llvm/utils/TableGen/TableGen.cpp b/llvm/utils/TableGen/TableGen.cpp |
| 3130 |
-index 38f81dc39..abe172be2 100644 |
| 3131 |
---- a/llvm/utils/TableGen/TableGen.cpp |
| 3132 |
-+++ b/llvm/utils/TableGen/TableGen.cpp |
| 3133 |
-@@ -27,6 +27,8 @@ enum ActionType { |
| 3134 |
- GenEmitter, |
| 3135 |
- GenRegisterInfo, |
| 3136 |
- GenInstrInfo, |
| 3137 |
-+ GenMappingInsn, |
| 3138 |
-+ GenInsnNameMaps, |
| 3139 |
- GenInstrDocs, |
| 3140 |
- GenAsmWriter, |
| 3141 |
- GenAsmMatcher, |
| 3142 |
-@@ -68,6 +70,10 @@ namespace { |
| 3143 |
- "Generate registers and register classes info"), |
| 3144 |
- clEnumValN(GenInstrInfo, "gen-instr-info", |
| 3145 |
- "Generate instruction descriptions"), |
| 3146 |
-+ clEnumValN(GenMappingInsn, "gen-mapping-insn", |
| 3147 |
-+ ""), |
| 3148 |
-+ clEnumValN(GenInsnNameMaps, "gen-insn-name-maps", |
| 3149 |
-+ ""), |
| 3150 |
- clEnumValN(GenInstrDocs, "gen-instr-docs", |
| 3151 |
- "Generate instruction documentation"), |
| 3152 |
- clEnumValN(GenCallingConv, "gen-callingconv", |
| 3153 |
-@@ -143,6 +149,12 @@ bool LLVMTableGenMain(raw_ostream &OS, RecordKeeper &Records) { |
| 3154 |
- case GenInstrInfo: |
| 3155 |
- EmitInstrInfo(Records, OS); |
| 3156 |
- break; |
| 3157 |
-+ case GenMappingInsn: |
| 3158 |
-+ EmitMappingInsn(Records, OS); |
| 3159 |
-+ break; |
| 3160 |
-+ case GenInsnNameMaps: |
| 3161 |
-+ EmitInsnNameMaps(Records, OS); |
| 3162 |
-+ break; |
| 3163 |
- case GenInstrDocs: |
| 3164 |
- EmitInstrDocs(Records, OS); |
| 3165 |
- break; |
| 3166 |
-diff --git a/llvm/utils/TableGen/TableGenBackends.h b/llvm/utils/TableGen/TableGenBackends.h |
| 3167 |
-index 135ec65c0..82f787dba 100644 |
| 3168 |
---- a/llvm/utils/TableGen/TableGenBackends.h |
| 3169 |
-+++ b/llvm/utils/TableGen/TableGenBackends.h |
| 3170 |
-@@ -74,6 +74,8 @@ void EmitDFAPacketizer(RecordKeeper &RK, raw_ostream &OS); |
| 3171 |
- void EmitDisassembler(RecordKeeper &RK, raw_ostream &OS); |
| 3172 |
- void EmitFastISel(RecordKeeper &RK, raw_ostream &OS); |
| 3173 |
- void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS); |
| 3174 |
-+void EmitMappingInsn(RecordKeeper &RK, raw_ostream &OS); |
| 3175 |
-+void EmitInsnNameMaps(RecordKeeper &RK, raw_ostream &OS); |
| 3176 |
- void EmitInstrDocs(RecordKeeper &RK, raw_ostream &OS); |
| 3177 |
- void EmitPseudoLowering(RecordKeeper &RK, raw_ostream &OS); |
| 3178 |
- void EmitCompressInst(RecordKeeper &RK, raw_ostream &OS); |
| 3179 |
--- |
| 3180 |
-2.20.1 |
| 3181 |
- |
| 3182 |
diff --git a/llvm/0002-update-TableGen-for-generate-RISCV-port-inc-for-CAPS.patch b/llvm/0002-update-TableGen-for-generate-RISCV-port-inc-for-CAPS.patch |
| 3183 |
deleted file mode 100644 |
| 3184 |
index a395c32a7..000000000 |
| 3185 |
--- a/llvm/0002-update-TableGen-for-generate-RISCV-port-inc-for-CAPS.patch |
| 3186 |
+++ /dev/null |
| 3187 |
@@ -1,905 +0,0 @@ |
| 3188 |
-From 40ac7444e7f3679fad852564acca4f30f47fb52d Mon Sep 17 00:00:00 2001 |
| 3189 |
-From: fanfuqiang <[email protected]> |
| 3190 |
-Date: Thu, 28 Feb 2019 01:37:55 +0800 |
| 3191 |
-Subject: [PATCH] update TableGen for generate RISCV port inc for CAPSTONE |
| 3192 |
- |
| 3193 |
---- |
| 3194 |
- llvm/lib/Target/RISCV/CMakeLists.txt | 2 +- |
| 3195 |
- llvm/utils/TableGen/AsmWriterEmitter.cpp | 175 ++++++++++++++++-- |
| 3196 |
- .../utils/TableGen/FixedLenDecoderEmitter.cpp | 122 ++++++------ |
| 3197 |
- llvm/utils/TableGen/InstrInfoEmitter.cpp | 14 +- |
| 3198 |
- llvm/utils/TableGen/RegisterInfoEmitter.cpp | 20 +- |
| 3199 |
- llvm/utils/TableGen/TableGen.cpp | 6 + |
| 3200 |
- 6 files changed, 249 insertions(+), 90 deletions(-) |
| 3201 |
- |
| 3202 |
-diff --git a/llvm/lib/Target/RISCV/CMakeLists.txt b/llvm/lib/Target/RISCV/CMakeLists.txt |
| 3203 |
-index 1821f4b01..603aa3f54 100644 |
| 3204 |
---- a/llvm/lib/Target/RISCV/CMakeLists.txt |
| 3205 |
-+++ b/llvm/lib/Target/RISCV/CMakeLists.txt |
| 3206 |
-@@ -6,7 +6,7 @@ tablegen(LLVM RISCVGenCompressInstEmitter.inc -gen-compress-inst-emitter) |
| 3207 |
- tablegen(LLVM RISCVGenDAGISel.inc -gen-dag-isel) |
| 3208 |
- tablegen(LLVM RISCVGenDisassemblerTables.inc -gen-disassembler) |
| 3209 |
- tablegen(LLVM RISCVGenInstrInfo.inc -gen-instr-info) |
| 3210 |
--tablegen(LLVM RISCVGenMappingInsn.inc -gen-mapping-insn) |
| 3211 |
-+tablegen(LLVM RISCVMappingInsn.inc -gen-mapping-insn) |
| 3212 |
- tablegen(LLVM RISCVGenInsnNameMaps.inc -gen-insn-name-maps) |
| 3213 |
- tablegen(LLVM RISCVGenMCCodeEmitter.inc -gen-emitter) |
| 3214 |
- tablegen(LLVM RISCVGenMCPseudoLowering.inc -gen-pseudo-lowering) |
| 3215 |
-diff --git a/llvm/utils/TableGen/AsmWriterEmitter.cpp b/llvm/utils/TableGen/AsmWriterEmitter.cpp |
| 3216 |
-index c24dc6052..ac82573fe 100644 |
| 3217 |
---- a/llvm/utils/TableGen/AsmWriterEmitter.cpp |
| 3218 |
-+++ b/llvm/utils/TableGen/AsmWriterEmitter.cpp |
| 3219 |
-@@ -270,12 +270,13 @@ static void UnescapeString(std::string &Str) { |
| 3220 |
- /// implementation. Destroys all instances of AsmWriterInst information, by |
| 3221 |
- /// clearing the Instructions vector. |
| 3222 |
- void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { |
| 3223 |
-+#ifdef CAPSTONE |
| 3224 |
-+ bool PassSubtarget = false; |
| 3225 |
-+#else |
| 3226 |
- Record *AsmWriter = Target.getAsmWriter(); |
| 3227 |
--#ifndef CAPSTONE |
| 3228 |
- StringRef ClassName = AsmWriter->getValueAsString("AsmWriterClassName"); |
| 3229 |
--#endif |
| 3230 |
- bool PassSubtarget = AsmWriter->getValueAsInt("PassSubtarget"); |
| 3231 |
-- |
| 3232 |
-+#endif |
| 3233 |
- O << |
| 3234 |
- "/// printInstruction - This method is automatically generated by tablegen\n" |
| 3235 |
- "/// from the instruction set description.\n" |
| 3236 |
-@@ -434,7 +435,11 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { |
| 3237 |
- } |
| 3238 |
- |
| 3239 |
- // Emit the initial tab character. |
| 3240 |
--#ifndef CAPSTONE |
| 3241 |
-+#ifdef CAPSTONE |
| 3242 |
-+ O << "#ifndef CAPSTONE_DIET\n" |
| 3243 |
-+ << " SStream_concat0(O, \"\\t\");\n" |
| 3244 |
-+ << "#endif\n\n"; |
| 3245 |
-+#else |
| 3246 |
- O << " O << \"\\t\";\n\n"; |
| 3247 |
- #endif |
| 3248 |
- |
| 3249 |
-@@ -493,10 +498,10 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { |
| 3250 |
- << ((1 << NumBits)-1) << ") {\n" |
| 3251 |
- << " default: " |
| 3252 |
- #ifdef CAPSTONE |
| 3253 |
-- << "assert(0);\n" |
| 3254 |
--#endif |
| 3255 |
-+ << "assert(0 && \"Invalid command number.\");\n"; |
| 3256 |
-+#else |
| 3257 |
- << "llvm_unreachable(\"Invalid command number.\");\n"; |
| 3258 |
-- |
| 3259 |
-+#endif |
| 3260 |
- // Print out all the cases. |
| 3261 |
- for (unsigned j = 0, e = Commands.size(); j != e; ++j) { |
| 3262 |
- O << " case " << j << ":\n"; |
| 3263 |
-@@ -576,9 +581,7 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName, |
| 3264 |
- } |
| 3265 |
- |
| 3266 |
- StringTable.layout(); |
| 3267 |
--#ifdef CAPSTONE |
| 3268 |
-- O << "#ifndef CAPSTONE_DIET\n"; |
| 3269 |
--#endif |
| 3270 |
-+ |
| 3271 |
- O << " static const char AsmStrs" << AltName << "[] = {\n"; |
| 3272 |
- StringTable.emit(O, printChar); |
| 3273 |
- O << " };\n\n"; |
| 3274 |
-@@ -625,7 +628,8 @@ void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) { |
| 3275 |
- O << " " |
| 3276 |
- << "assert(RegNo && RegNo < " << (Registers.size()+1) |
| 3277 |
- << " && \"Invalid register number!\");\n" |
| 3278 |
-- << "\n"; |
| 3279 |
-+ << "\n" |
| 3280 |
-+ << "#ifndef CAPSTONE_DIET\n"; |
| 3281 |
- |
| 3282 |
- if (hasAltNames) { |
| 3283 |
- for (const Record *R : AltNameIndices) |
| 3284 |
-@@ -636,7 +640,7 @@ void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) { |
| 3285 |
- if (hasAltNames) { |
| 3286 |
- O << " switch(AltIdx) {\n" |
| 3287 |
- #ifdef CAPSTONE |
| 3288 |
-- << " default: assert(0);\n"; |
| 3289 |
-+ << " default: assert(0 && \"Invalid register alt name index!\");\n"; |
| 3290 |
- #else |
| 3291 |
- << " default: llvm_unreachable(\"Invalid register alt name index!\");\n"; |
| 3292 |
- #endif |
| 3293 |
-@@ -886,7 +890,9 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3294 |
- |
| 3295 |
- IAPrinter IAP(CGA.Result->getAsString(), FlatAliasAsmString); |
| 3296 |
- |
| 3297 |
-+#ifndef CAPSTONE // Silence the compiler waring. |
| 3298 |
- StringRef Namespace = Target.getName(); |
| 3299 |
-+#endif |
| 3300 |
- std::vector<Record *> ReqFeatures; |
| 3301 |
- if (PassSubtarget) { |
| 3302 |
- // We only consider ReqFeatures predicates if PassSubtarget |
| 3303 |
-@@ -902,7 +908,11 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3304 |
- NumMIOps += ResultInstOpnd.MINumOperands; |
| 3305 |
- |
| 3306 |
- std::string Cond; |
| 3307 |
-+#ifdef CAPSTONE |
| 3308 |
-+ Cond = std::string("MCInst_getNumOperands(MI) == ") + utostr(NumMIOps); |
| 3309 |
-+#else |
| 3310 |
- Cond = std::string("MI->getNumOperands() == ") + utostr(NumMIOps); |
| 3311 |
-+#endif |
| 3312 |
- IAP.addCond(Cond); |
| 3313 |
- |
| 3314 |
- bool CantHandle = false; |
| 3315 |
-@@ -926,9 +936,11 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3316 |
- } |
| 3317 |
- break; |
| 3318 |
- } |
| 3319 |
-- |
| 3320 |
-+#ifdef CAPSTONE |
| 3321 |
-+ std::string Op = "MCInst_getOperand(MI, " + utostr(MIOpNum) + ")"; |
| 3322 |
-+#else |
| 3323 |
- std::string Op = "MI->getOperand(" + utostr(MIOpNum) + ")"; |
| 3324 |
-- |
| 3325 |
-+#endif |
| 3326 |
- const CodeGenInstAlias::ResultOperand &RO = CGA.ResultOperands[i]; |
| 3327 |
- |
| 3328 |
- switch (RO.Kind) { |
| 3329 |
-@@ -954,19 +966,39 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3330 |
- if (Rec->isSubClassOf("RegisterOperand")) |
| 3331 |
- Rec = Rec->getValueAsDef("RegClass"); |
| 3332 |
- if (Rec->isSubClassOf("RegisterClass")) { |
| 3333 |
-+#ifdef CAPSTONE |
| 3334 |
-+ IAP.addCond("MCOperand_isReg(" + Op + ")"); |
| 3335 |
-+#else |
| 3336 |
- IAP.addCond(Op + ".isReg()"); |
| 3337 |
-+#endif |
| 3338 |
- |
| 3339 |
- if (!IAP.isOpMapped(ROName)) { |
| 3340 |
- IAP.addOperand(ROName, MIOpNum, PrintMethodIdx); |
| 3341 |
- Record *R = CGA.ResultOperands[i].getRecord(); |
| 3342 |
- if (R->isSubClassOf("RegisterOperand")) |
| 3343 |
- R = R->getValueAsDef("RegClass"); |
| 3344 |
-+ |
| 3345 |
-+#ifdef CAPSTONE |
| 3346 |
-+ Cond = std::string("MCRegisterClass_contains(") + |
| 3347 |
-+ "MCRegisterInfo_getRegClass(" + "MRI, " + |
| 3348 |
-+ Target.getName().str() + "_" + R->getName().str() + "RegClassID)" + |
| 3349 |
-+ ", " + |
| 3350 |
-+ "MCOperand_getReg(" + Op + "))"; |
| 3351 |
-+#else |
| 3352 |
- Cond = std::string("MRI.getRegClass(") + Target.getName().str() + |
| 3353 |
- "::" + R->getName().str() + "RegClassID).contains(" + Op + |
| 3354 |
- ".getReg())"; |
| 3355 |
-+#endif |
| 3356 |
-+ |
| 3357 |
- } else { |
| 3358 |
-+#ifdef CAPSTONE |
| 3359 |
-+ Cond = std::string("MCOperand_getReg(") + Op + ") == " + |
| 3360 |
-+ "MCOperand_getReg(MCInst_getOperand(MI, " + |
| 3361 |
-+ utostr(IAP.getOpIndex(ROName)) + "))"; |
| 3362 |
-+#else |
| 3363 |
- Cond = Op + ".getReg() == MI->getOperand(" + |
| 3364 |
- utostr(IAP.getOpIndex(ROName)) + ").getReg()"; |
| 3365 |
-+#endif |
| 3366 |
- } |
| 3367 |
- } else { |
| 3368 |
- // Assume all printable operands are desired for now. This can be |
| 3369 |
-@@ -984,8 +1016,12 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3370 |
- break; // No conditions on this operand at all |
| 3371 |
- } |
| 3372 |
- Cond = (Target.getName() + ClassName + "ValidateMCOperand(" + Op + |
| 3373 |
-+ #ifdef CAPSTONE |
| 3374 |
-+ ", " + utostr(Entry) + ")").str(); |
| 3375 |
-+ #else |
| 3376 |
- ", STI, " + utostr(Entry) + ")") |
| 3377 |
- .str(); |
| 3378 |
-+ #endif |
| 3379 |
- } |
| 3380 |
- // for all subcases of ResultOperand::K_Record: |
| 3381 |
- IAP.addCond(Cond); |
| 3382 |
-@@ -994,9 +1030,15 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3383 |
- case CodeGenInstAlias::ResultOperand::K_Imm: { |
| 3384 |
- // Just because the alias has an immediate result, doesn't mean the |
| 3385 |
- // MCInst will. An MCExpr could be present, for example. |
| 3386 |
-+#ifdef CAPSTONE |
| 3387 |
-+ IAP.addCond("MCOperand_isImm(" + Op + ")"); |
| 3388 |
-+ Cond = "MCOperand_getImm(" + Op + ") == " + |
| 3389 |
-+ itostr(CGA.ResultOperands[i].getImm()); |
| 3390 |
-+#else |
| 3391 |
- IAP.addCond(Op + ".isImm()"); |
| 3392 |
-- |
| 3393 |
- Cond = Op + ".getImm() == " + itostr(CGA.ResultOperands[i].getImm()); |
| 3394 |
-+#endif |
| 3395 |
-+ |
| 3396 |
- IAP.addCond(Cond); |
| 3397 |
- break; |
| 3398 |
- } |
| 3399 |
-@@ -1008,8 +1050,14 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3400 |
- break; |
| 3401 |
- } |
| 3402 |
- |
| 3403 |
-+#ifdef CAPSTONE |
| 3404 |
-+ Cond = "MCOperand_getReg(" + Op + ") == " + Target.getName().str() + |
| 3405 |
-+ "_" + CGA.ResultOperands[i].getRegister()->getName().str(); |
| 3406 |
-+#else |
| 3407 |
- Cond = Op + ".getReg() == " + Target.getName().str() + "::" + |
| 3408 |
- CGA.ResultOperands[i].getRegister()->getName().str(); |
| 3409 |
-+#endif |
| 3410 |
-+ |
| 3411 |
- IAP.addCond(Cond); |
| 3412 |
- break; |
| 3413 |
- } |
| 3414 |
-@@ -1019,6 +1067,7 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3415 |
- |
| 3416 |
- if (CantHandle) continue; |
| 3417 |
- |
| 3418 |
-+#ifndef CAPSTONE |
| 3419 |
- for (auto I = ReqFeatures.cbegin(); I != ReqFeatures.cend(); I++) { |
| 3420 |
- Record *R = *I; |
| 3421 |
- StringRef AsmCondString = R->getValueAsString("AssemblerCondString"); |
| 3422 |
-@@ -1040,6 +1089,7 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3423 |
- IAP.addCond(Cond); |
| 3424 |
- } |
| 3425 |
- } |
| 3426 |
-+#endif |
| 3427 |
- |
| 3428 |
- IAPrinterMap[Aliases.first].push_back(std::move(IAP)); |
| 3429 |
- } |
| 3430 |
-@@ -1052,10 +1102,17 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3431 |
- std::string Header; |
| 3432 |
- raw_string_ostream HeaderO(Header); |
| 3433 |
- |
| 3434 |
-+#ifdef CAPSTONE |
| 3435 |
-+ HeaderO << "\nstatic bool printAliasInstr(MCInst *MI, SStream * OS, void *info)" |
| 3436 |
-+ << "\n" |
| 3437 |
-+ << "{\n" |
| 3438 |
-+ << " MCRegisterInfo *MRI = (MCRegisterInfo *) info;\n"; |
| 3439 |
-+#else |
| 3440 |
- HeaderO << "bool " << Target.getName() << ClassName |
| 3441 |
- << "::printAliasInstr(const MCInst" |
| 3442 |
- << " *MI, " << (PassSubtarget ? "const MCSubtargetInfo &STI, " : "") |
| 3443 |
- << "raw_ostream &OS) {\n"; |
| 3444 |
-+#endif |
| 3445 |
- |
| 3446 |
- std::string Cases; |
| 3447 |
- raw_string_ostream CasesO(Cases); |
| 3448 |
-@@ -1079,7 +1136,16 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3449 |
- |
| 3450 |
- if (UniqueIAPs.empty()) continue; |
| 3451 |
- |
| 3452 |
-+#ifdef CAPSTONE |
| 3453 |
-+ // TODO: tricky. |
| 3454 |
-+ const char* tmpCase = Entry.first.c_str(); |
| 3455 |
-+ assert (Entry.first.size() > 7); |
| 3456 |
-+ CasesO.indent(2) << "case " |
| 3457 |
-+ << "RISCV_" << std::string(tmpCase + 7) // strlen("RISCV::) == 7 |
| 3458 |
-+ << ":\n"; |
| 3459 |
-+#else |
| 3460 |
- CasesO.indent(2) << "case " << Entry.first << ":\n"; |
| 3461 |
-+#endif |
| 3462 |
- |
| 3463 |
- for (IAPrinter *IAP : UniqueIAPs) { |
| 3464 |
- CasesO.indent(4); |
| 3465 |
-@@ -1100,13 +1166,21 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3466 |
- |
| 3467 |
- if (!MCOpPredicates.empty()) |
| 3468 |
- O << "static bool " << Target.getName() << ClassName |
| 3469 |
-+#ifdef CAPSTONE |
| 3470 |
-+ << "ValidateMCOperand(MCOperand *MCOp,\n" |
| 3471 |
-+#else |
| 3472 |
- << "ValidateMCOperand(const MCOperand &MCOp,\n" |
| 3473 |
- << " const MCSubtargetInfo &STI,\n" |
| 3474 |
-+#endif |
| 3475 |
- << " unsigned PredicateIndex);\n"; |
| 3476 |
- |
| 3477 |
- O << HeaderO.str(); |
| 3478 |
- O.indent(2) << "const char *AsmString;\n"; |
| 3479 |
-+#ifdef CAPSTONE |
| 3480 |
-+ O.indent(2) << "switch (MCInst_getOpcode(MI)) {\n"; |
| 3481 |
-+#else |
| 3482 |
- O.indent(2) << "switch (MI->getOpcode()) {\n"; |
| 3483 |
-+#endif |
| 3484 |
- O.indent(2) << "default: return false;\n"; |
| 3485 |
- O << CasesO.str(); |
| 3486 |
- O.indent(2) << "}\n\n"; |
| 3487 |
-@@ -1114,14 +1188,27 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3488 |
- // Code that prints the alias, replacing the operands with the ones from the |
| 3489 |
- // MCInst. |
| 3490 |
- O << " unsigned I = 0;\n"; |
| 3491 |
-+#ifdef CAPSTONE |
| 3492 |
-+ O << " char *tmpString = cs_strdup(AsmString);\n"; |
| 3493 |
-+#endif |
| 3494 |
- O << " while (AsmString[I] != ' ' && AsmString[I] != '\\t' &&\n"; |
| 3495 |
- O << " AsmString[I] != '$' && AsmString[I] != '\\0')\n"; |
| 3496 |
- O << " ++I;\n"; |
| 3497 |
-+#ifdef CAPSTONE |
| 3498 |
-+ O << " tmpString[I] = 0;\n"; |
| 3499 |
-+ O << " SStream_concat0(OS, \"\\t\");\n"; |
| 3500 |
-+ O << " SStream_concat0(OS, tmpString);\n"; |
| 3501 |
-+ O << " SStream_concat0(OS, \"\\n\");\n"; |
| 3502 |
-+#else |
| 3503 |
- O << " OS << '\\t' << StringRef(AsmString, I);\n"; |
| 3504 |
-- |
| 3505 |
-+#endif |
| 3506 |
- O << " if (AsmString[I] != '\\0') {\n"; |
| 3507 |
- O << " if (AsmString[I] == ' ' || AsmString[I] == '\\t') {\n"; |
| 3508 |
-+#ifdef CAPSTONE |
| 3509 |
-+ O << " SStream_concat0(OS, \"\\t\");\n"; |
| 3510 |
-+#else |
| 3511 |
- O << " OS << '\\t';\n"; |
| 3512 |
-+#endif |
| 3513 |
- O << " ++I;\n"; |
| 3514 |
- O << " }\n"; |
| 3515 |
- O << " do {\n"; |
| 3516 |
-@@ -1131,15 +1218,28 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3517 |
- O << " ++I;\n"; |
| 3518 |
- O << " int OpIdx = AsmString[I++] - 1;\n"; |
| 3519 |
- O << " int PrintMethodIdx = AsmString[I++] - 1;\n"; |
| 3520 |
-+#ifdef CAPSTONE |
| 3521 |
-+ O << " printCustomAliasOperand(MI, OpIdx, PrintMethodIdx, OS);\n"; |
| 3522 |
-+#else |
| 3523 |
- O << " printCustomAliasOperand(MI, OpIdx, PrintMethodIdx, "; |
| 3524 |
- O << (PassSubtarget ? "STI, " : ""); |
| 3525 |
- O << "OS);\n"; |
| 3526 |
-+#endif |
| 3527 |
- O << " } else\n"; |
| 3528 |
-+ |
| 3529 |
-+#ifdef CAPSTONE |
| 3530 |
-+ O << " printOperand(MI, (unsigned)(AsmString[I++]) - 1, OS);\n"; |
| 3531 |
-+#else |
| 3532 |
- O << " printOperand(MI, unsigned(AsmString[I++]) - 1, "; |
| 3533 |
- O << (PassSubtarget ? "STI, " : ""); |
| 3534 |
- O << "OS);\n"; |
| 3535 |
-+#endif |
| 3536 |
- O << " } else {\n"; |
| 3537 |
-+#ifdef CAPSTONE |
| 3538 |
-+ O << " SStream_concat0(OS, &AsmString[I++]);\n"; |
| 3539 |
-+#else |
| 3540 |
- O << " OS << AsmString[I++];\n"; |
| 3541 |
-+#endif |
| 3542 |
- O << " }\n"; |
| 3543 |
- O << " } while (AsmString[I] != '\\0');\n"; |
| 3544 |
- O << " }\n\n"; |
| 3545 |
-@@ -1150,25 +1250,48 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3546 |
- ////////////////////////////// |
| 3547 |
- // Write out the printCustomAliasOperand function |
| 3548 |
- ////////////////////////////// |
| 3549 |
-- |
| 3550 |
-+#ifdef CAPSTONE |
| 3551 |
-+ O << "static void " |
| 3552 |
-+#else |
| 3553 |
- O << "void " << Target.getName() << ClassName << "::" |
| 3554 |
-+#endif |
| 3555 |
- << "printCustomAliasOperand(\n" |
| 3556 |
-+#ifdef CAPSTONE |
| 3557 |
-+ << " MCInst *MI, unsigned OpIdx,\n" |
| 3558 |
-+#else |
| 3559 |
- << " const MCInst *MI, unsigned OpIdx,\n" |
| 3560 |
-+#endif |
| 3561 |
- << " unsigned PrintMethodIdx,\n" |
| 3562 |
-+#ifdef CAPSTONE |
| 3563 |
-+ << " SStream *OS) {\n"; |
| 3564 |
-+#else |
| 3565 |
- << (PassSubtarget ? " const MCSubtargetInfo &STI,\n" : "") |
| 3566 |
- << " raw_ostream &OS) {\n"; |
| 3567 |
-+#endif |
| 3568 |
- if (PrintMethods.empty()) |
| 3569 |
-+#ifdef CAPSTONE |
| 3570 |
-+ O << " assert(0 && \"Unknown PrintMethod kind\");\n"; |
| 3571 |
-+#else |
| 3572 |
- O << " llvm_unreachable(\"Unknown PrintMethod kind\");\n"; |
| 3573 |
-+#endif |
| 3574 |
- else { |
| 3575 |
- O << " switch (PrintMethodIdx) {\n" |
| 3576 |
- << " default:\n" |
| 3577 |
-+#ifdef CAPSTONE |
| 3578 |
-+ << " assert(0 && \"Unknown PrintMethod kind\");\n" |
| 3579 |
-+#else |
| 3580 |
- << " llvm_unreachable(\"Unknown PrintMethod kind\");\n" |
| 3581 |
-+#endif |
| 3582 |
- << " break;\n"; |
| 3583 |
- |
| 3584 |
- for (unsigned i = 0; i < PrintMethods.size(); ++i) { |
| 3585 |
- O << " case " << i << ":\n" |
| 3586 |
- << " " << PrintMethods[i] << "(MI, OpIdx, " |
| 3587 |
-+#ifdef CAPSTONE |
| 3588 |
-+ << "OS);\n" |
| 3589 |
-+#else |
| 3590 |
- << (PassSubtarget ? "STI, " : "") << "OS);\n" |
| 3591 |
-+#endif |
| 3592 |
- << " break;\n"; |
| 3593 |
- } |
| 3594 |
- O << " }\n"; |
| 3595 |
-@@ -1177,9 +1300,20 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3596 |
- |
| 3597 |
- if (!MCOpPredicates.empty()) { |
| 3598 |
- O << "static bool " << Target.getName() << ClassName |
| 3599 |
-+#ifdef CAPSTONE |
| 3600 |
-+ << "ValidateMCOperand(MCOperand *MCOp,\n" |
| 3601 |
-+#else |
| 3602 |
- << "ValidateMCOperand(const MCOperand &MCOp,\n" |
| 3603 |
- << " const MCSubtargetInfo &STI,\n" |
| 3604 |
-- << " unsigned PredicateIndex) {\n" |
| 3605 |
-+#endif |
| 3606 |
-+ << " unsigned PredicateIndex) {\n" |
| 3607 |
-+#ifdef CAPSTONE |
| 3608 |
-+ << " // TODO: need some constant untils operate the MCOperand,\n" |
| 3609 |
-+ << " // but current CAPSTONE does't have.\n" |
| 3610 |
-+ << " // So, We just return true\n" |
| 3611 |
-+ << " return true;\n\n" |
| 3612 |
-+ << "#if 0\n" |
| 3613 |
-+#endif |
| 3614 |
- << " switch (PredicateIndex) {\n" |
| 3615 |
- << " default:\n" |
| 3616 |
- << " llvm_unreachable(\"Unknown MCOperandPredicate kind\");\n" |
| 3617 |
-@@ -1195,6 +1329,9 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { |
| 3618 |
- llvm_unreachable("Unexpected MCOperandPredicate field!"); |
| 3619 |
- } |
| 3620 |
- O << " }\n" |
| 3621 |
-+#ifdef CAPSTONE |
| 3622 |
-+ << "#endif\n" |
| 3623 |
-+#endif |
| 3624 |
- << "}\n\n"; |
| 3625 |
- } |
| 3626 |
- |
| 3627 |
-@@ -1228,7 +1365,7 @@ void AsmWriterEmitter::run(raw_ostream &O) { |
| 3628 |
- #endif |
| 3629 |
- EmitPrintInstruction(O); |
| 3630 |
- EmitGetRegisterName(O); |
| 3631 |
--#ifndef CAPSTONE |
| 3632 |
-+#ifdef CAPSTONE |
| 3633 |
- EmitPrintAliasInstruction(O); |
| 3634 |
- #endif |
| 3635 |
- } |
| 3636 |
-diff --git a/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp b/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp |
| 3637 |
-index 3db428dfa..e1bfaa934 100644 |
| 3638 |
---- a/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp |
| 3639 |
-+++ b/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp |
| 3640 |
-@@ -946,13 +946,6 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 3641 |
- void FixedLenDecoderEmitter:: |
| 3642 |
- emitPredicateFunction(formatted_raw_ostream &OS, PredicateSet &Predicates, |
| 3643 |
- unsigned Indentation) const { |
| 3644 |
--#ifdef CAPSTONE |
| 3645 |
-- OS.indent(Indentation) << "static bool getbool(uint64_t b)\n"; |
| 3646 |
-- OS.indent(Indentation) << "{\n"; |
| 3647 |
-- OS.indent(Indentation) << "\treturn b != 0;\n"; |
| 3648 |
-- OS.indent(Indentation) << "}\n\n"; |
| 3649 |
--#endif |
| 3650 |
-- |
| 3651 |
- // The predicate function is just a big switch statement based on the |
| 3652 |
- // input predicate index. |
| 3653 |
- OS.indent(Indentation) << "static bool checkDecoderPredicate(unsigned Idx, " |
| 3654 |
-@@ -966,26 +959,25 @@ emitPredicateFunction(formatted_raw_ostream &OS, PredicateSet &Predicates, |
| 3655 |
- OS.indent(Indentation) << "switch (Idx) {\n"; |
| 3656 |
- OS.indent(Indentation) << "default: " |
| 3657 |
- #ifdef CAPSTONE |
| 3658 |
-- << "assert(0);\n" |
| 3659 |
--#endif |
| 3660 |
-+ << "assert(0 && \"Invalid index!\");\n"; |
| 3661 |
-+#else |
| 3662 |
- << "llvm_unreachable(\"Invalid index!\");\n"; |
| 3663 |
-+#endif |
| 3664 |
- unsigned Index = 0; |
| 3665 |
- for (const auto &Predicate : Predicates) { |
| 3666 |
- OS.indent(Indentation) << "case " << Index++ << ":\n"; |
| 3667 |
- OS.indent(Indentation+2) << "return " |
| 3668 |
--#ifdef CAPSTONE |
| 3669 |
-- << "getbool" |
| 3670 |
--#endif |
| 3671 |
-- << "(" << Predicate << ");\n"; |
| 3672 |
-+ << Predicate << ";\n"; |
| 3673 |
- } |
| 3674 |
- OS.indent(Indentation) << "}\n"; |
| 3675 |
- } else { |
| 3676 |
- // No case statement to emit |
| 3677 |
- OS.indent(Indentation) |
| 3678 |
- #ifdef CAPSTONE |
| 3679 |
-- << "assert(0);\n" |
| 3680 |
--#endif |
| 3681 |
-+ << "assert(0 && \"Invalid index!\");\n"; |
| 3682 |
-+#else |
| 3683 |
- << "llvm_unreachable(\"Invalid index!\");\n"; |
| 3684 |
-+#endif |
| 3685 |
- } |
| 3686 |
- Indentation -= 2; |
| 3687 |
- OS.indent(Indentation) << "}\n\n"; |
| 3688 |
-@@ -998,10 +990,11 @@ emitDecoderFunction(formatted_raw_ostream &OS, DecoderSet &Decoders, |
| 3689 |
- // input decoder index. |
| 3690 |
- #ifdef CAPSTONE |
| 3691 |
- #define EDF_EOL " \\\n" |
| 3692 |
-- OS.indent(Indentation) << "#define DecodeToMCInst(fname,fieldname, InsnType) \\\n"; |
| 3693 |
-- OS.indent(Indentation) << "static DecodeStatus fname(DecodeStatus S, unsigned Idx, InsnType insn, MCInst *MI, \\\n"; |
| 3694 |
-- OS.indent(Indentation) << " uint64_t Address, const void *Decoder) \\\n"; |
| 3695 |
-- OS.indent(Indentation) << "{ \\\n"; |
| 3696 |
-+ OS.indent(Indentation) << "#define DecodeToMCInst(fname, fieldname, InsnType) \\\n"; |
| 3697 |
-+ OS.indent(Indentation) << "static DecodeStatus fname(DecodeStatus S, unsigned Idx," |
| 3698 |
-+ << " InsnType insn, MCInst *MI, \\\n"; |
| 3699 |
-+ OS.indent(Indentation) << " uint64_t Address, const void *Decoder,\\\n"; |
| 3700 |
-+ OS.indent(Indentation) << " bool *DecodeComplete) {\\\n"; |
| 3701 |
- #else |
| 3702 |
- #define EDF_EOL "\n" |
| 3703 |
- OS.indent(Indentation) << "template<typename InsnType>\n"; |
| 3704 |
-@@ -1011,16 +1004,18 @@ emitDecoderFunction(formatted_raw_ostream &OS, DecoderSet &Decoders, |
| 3705 |
- << "Address, const void *Decoder, bool &DecodeComplete) {\n"; |
| 3706 |
- #endif |
| 3707 |
- Indentation += 2; |
| 3708 |
--#ifndef CAPSTONE |
| 3709 |
-+#ifdef CAPSTONE |
| 3710 |
-+ OS.indent(Indentation) << "*DecodeComplete = true;\\\n"; |
| 3711 |
-+#else |
| 3712 |
- OS.indent(Indentation) << "DecodeComplete = true;\n"; |
| 3713 |
- #endif |
| 3714 |
- OS.indent(Indentation) << "InsnType tmp;" EDF_EOL; |
| 3715 |
- OS.indent(Indentation) << "switch (Idx) {" EDF_EOL; |
| 3716 |
- OS.indent(Indentation) << "default:" |
| 3717 |
--#ifndef CAPSTONE |
| 3718 |
-- << " llvm_unreachable(\"Invalid index!\");\n"; |
| 3719 |
-+#ifdef CAPSTONE |
| 3720 |
-+ << " assert(0 && \"Invalid index!\");\\\n"; |
| 3721 |
- #else |
| 3722 |
-- << " assert(0);\\\n"; |
| 3723 |
-+ << " llvm_unreachable(\"Invalid index!\");\n"; |
| 3724 |
- #endif |
| 3725 |
- unsigned Index = 0; |
| 3726 |
- for (const auto &Decoder : Decoders) { |
| 3727 |
-@@ -1174,8 +1169,27 @@ void FilterChooser::emitBinaryParser(raw_ostream &o, unsigned &Indentation, |
| 3728 |
- |
| 3729 |
- if (Decoder != "") { |
| 3730 |
- OpHasCompleteDecoder = OpInfo.HasCompleteDecoder; |
| 3731 |
-+#ifdef CAPSTONE |
| 3732 |
-+ std::string::size_type posOfLeftAngle = 0, posOfRightAngle = 0; |
| 3733 |
-+ posOfLeftAngle = Decoder.find("<"); |
| 3734 |
-+ posOfRightAngle = Decoder.find(">"); |
| 3735 |
-+ std::string printDecoder = Decoder; |
| 3736 |
-+ if (posOfLeftAngle != std::string::npos && |
| 3737 |
-+ posOfRightAngle != std::string::npos) { |
| 3738 |
-+ printDecoder = Decoder.substr(0, posOfLeftAngle); |
| 3739 |
-+ o.indent(Indentation) << Emitter->GuardPrefix |
| 3740 |
-+ << printDecoder |
| 3741 |
-+ << "(MI, tmp, Address, Decoder, " |
| 3742 |
-+ << Decoder.substr(posOfLeftAngle+1, posOfRightAngle-posOfLeftAngle-1); |
| 3743 |
-+ } else |
| 3744 |
-+ o.indent(Indentation) << Emitter->GuardPrefix << Decoder |
| 3745 |
-+ << "(MI, tmp, Address, Decoder"; |
| 3746 |
-+ // trick. |
| 3747 |
-+ o << ")" |
| 3748 |
-+#else |
| 3749 |
- o.indent(Indentation) << Emitter->GuardPrefix << Decoder |
| 3750 |
- << "(MI, tmp, Address, Decoder)" |
| 3751 |
-+#endif |
| 3752 |
- << Emitter->GuardPostfix |
| 3753 |
- #ifdef CAPSTONE |
| 3754 |
- << " return MCDisassembler_Fail; \\\n"; |
| 3755 |
-@@ -1246,7 +1260,7 @@ static void emitSinglePredicateMatch(raw_ostream &o, StringRef str, |
| 3756 |
- const std::string &PredicateNamespace) { |
| 3757 |
- if (str[0] == '!') |
| 3758 |
- #ifdef CAPSTONE |
| 3759 |
-- o << "~(Bits & " << PredicateNamespace << "_" |
| 3760 |
-+ o << "!(Bits & " << PredicateNamespace << "_" |
| 3761 |
- << str.slice(1,str.size()) << ")"; |
| 3762 |
- #else |
| 3763 |
- o << "!Bits[" << PredicateNamespace << "::" |
| 3764 |
-@@ -2331,15 +2345,13 @@ static void emitDecodeInstruction(formatted_raw_ostream &OS) { |
| 3765 |
- #endif |
| 3766 |
- |
| 3767 |
- #ifdef CAPSTONE |
| 3768 |
-- OS << "static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], " |
| 3769 |
-- |
| 3770 |
-+ OS << "#define DecodeInstruction(fname, fieldname, decoder, InsnType) \\\n" |
| 3771 |
-+ << "static DecodeStatus fname(const uint8_t DecodeTable[], " |
| 3772 |
- "MCInst *MI,\\\n" |
| 3773 |
-- << " InsnType insn, uint64_t " |
| 3774 |
-+ << " InsnType insn, uint64_t " |
| 3775 |
- "Address,\\\n" |
| 3776 |
-- << " const void *DisAsm,\\\n" |
| 3777 |
-- << " int feature) {\\\n" |
| 3778 |
-- << " uint64_t Bits = getFeatureBits(feature); \\\n" |
| 3779 |
-- //<< " const FeatureBitset& Bits = STI.getFeatureBits();\n" |
| 3780 |
-+ << " const void *DisAsm, int feature) {\\\n" |
| 3781 |
-+ << " uint64_t Bits = getFeatureBits(feature);\\\n" |
| 3782 |
- << "\\\n" |
| 3783 |
- << " const uint8_t *Ptr = DecodeTable;\\\n" |
| 3784 |
- << " uint32_t CurFieldValue = 0;\\\n" |
| 3785 |
-@@ -2353,52 +2365,42 @@ static void emitDecodeInstruction(formatted_raw_ostream &OS) { |
| 3786 |
- << " unsigned Start = *++Ptr;\\\n" |
| 3787 |
- << " unsigned Len = *++Ptr;\\\n" |
| 3788 |
- << " ++Ptr;\\\n" |
| 3789 |
-- << " CurFieldValue = fieldFromInstruction(insn, Start, Len);\\\n" |
| 3790 |
-+ << " CurFieldValue = fieldname(insn, Start, Len);\\\n" |
| 3791 |
- << " break;\\\n" |
| 3792 |
- << " }\\\n" |
| 3793 |
- << " case MCD_OPC_FilterValue: {\\\n" |
| 3794 |
-- << " // Decode the field value.\\\n" |
| 3795 |
- << " unsigned Len;\\\n" |
| 3796 |
- << " InsnType Val = decodeULEB128(++Ptr, &Len);\\\n" |
| 3797 |
- << " Ptr += Len;\\\n" |
| 3798 |
-- << " // NumToSkip is a plain 24-bit integer.\\\n" |
| 3799 |
- << " unsigned NumToSkip = *Ptr++;\\\n" |
| 3800 |
- << " NumToSkip |= (*Ptr++) << 8;\\\n" |
| 3801 |
- << " NumToSkip |= (*Ptr++) << 16;\\\n" |
| 3802 |
- << "\\\n" |
| 3803 |
-- << " // Perform the filter operation.\\\n" |
| 3804 |
- << " if (Val != CurFieldValue)\\\n" |
| 3805 |
- << " Ptr += NumToSkip;\\\n" |
| 3806 |
-- << "\\\n" |
| 3807 |
- << " break;\\\n" |
| 3808 |
- << " }\\\n" |
| 3809 |
- << " case MCD_OPC_CheckField: {\\\n" |
| 3810 |
- << " unsigned Start = *++Ptr;\\\n" |
| 3811 |
- << " unsigned Len = *++Ptr;\\\n" |
| 3812 |
-- << " InsnType FieldValue = fieldFromInstruction(insn, Start, Len);\\\n" |
| 3813 |
-- << " // Decode the field value.\\\n" |
| 3814 |
-+ << " InsnType FieldValue = fieldname(insn, Start, Len);\\\n" |
| 3815 |
- << " uint32_t ExpectedValue = decodeULEB128(++Ptr, &Len);\\\n" |
| 3816 |
- << " Ptr += Len;\\\n" |
| 3817 |
-- << " // NumToSkip is a plain 24-bit integer.\\\n" |
| 3818 |
- << " unsigned NumToSkip = *Ptr++;\\\n" |
| 3819 |
- << " NumToSkip |= (*Ptr++) << 8;\\\n" |
| 3820 |
- << " NumToSkip |= (*Ptr++) << 16;\\\n" |
| 3821 |
- << "\\\n" |
| 3822 |
-- << " // If the actual and expected values don't match, skip.\\\n" |
| 3823 |
- << " if (ExpectedValue != FieldValue)\\\n" |
| 3824 |
- << " Ptr += NumToSkip;\\\n" |
| 3825 |
- << " break;\\\n" |
| 3826 |
- << " }\\\n" |
| 3827 |
- << " case MCD_OPC_CheckPredicate: {\\\n" |
| 3828 |
- << " unsigned Len;\\\n" |
| 3829 |
-- << " // Decode the Predicate Index value.\\\n" |
| 3830 |
- << " unsigned PIdx = decodeULEB128(++Ptr, &Len);\\\n" |
| 3831 |
- << " Ptr += Len;\\\n" |
| 3832 |
-- << " // NumToSkip is a plain 24-bit integer.\\\n" |
| 3833 |
- << " unsigned NumToSkip = *Ptr++;\\\n" |
| 3834 |
- << " NumToSkip |= (*Ptr++) << 8;\\\n" |
| 3835 |
- << " NumToSkip |= (*Ptr++) << 16;\\\n" |
| 3836 |
-- << " // Check the predicate.\\\n" |
| 3837 |
- << " bool Pred;\\\n" |
| 3838 |
- << " if (!(Pred = checkDecoderPredicate(PIdx, Bits)))\\\n" |
| 3839 |
- << " Ptr += NumToSkip;\\\n" |
| 3840 |
-@@ -2407,7 +2409,6 @@ static void emitDecodeInstruction(formatted_raw_ostream &OS) { |
| 3841 |
- << " }\\\n" |
| 3842 |
- << " case MCD_OPC_Decode: {\\\n" |
| 3843 |
- << " unsigned Len;\\\n" |
| 3844 |
-- << " // Decode the Opcode value.\\\n" |
| 3845 |
- << " unsigned Opc = decodeULEB128(++Ptr, &Len);\\\n" |
| 3846 |
- << " Ptr += Len;\\\n" |
| 3847 |
- << " unsigned DecodeIdx = decodeULEB128(Ptr, &Len);\\\n" |
| 3848 |
-@@ -2416,47 +2417,39 @@ static void emitDecodeInstruction(formatted_raw_ostream &OS) { |
| 3849 |
- << " MCInst_clear(MI);\\\n" |
| 3850 |
- << " MCInst_setOpcode(MI, Opc);\\\n" |
| 3851 |
- << " bool DecodeComplete;\\\n" |
| 3852 |
-- << " S = decodeToMCInst(S, DecodeIdx, insn, MI, Address, DisAsm, " |
| 3853 |
-- "DecodeComplete);\\\n" |
| 3854 |
-+ << " S = decoder(S, DecodeIdx, insn, MI, Address, DisAsm, " |
| 3855 |
-+ "&DecodeComplete);\\\n" |
| 3856 |
- << " assert(DecodeComplete);\\\n" |
| 3857 |
- << "\\\n" |
| 3858 |
- << " return S;\\\n" |
| 3859 |
- << " }\\\n" |
| 3860 |
- << " case MCD_OPC_TryDecode: {\\\n" |
| 3861 |
- << " unsigned Len;\\\n" |
| 3862 |
-- << " // Decode the Opcode value.\\\n" |
| 3863 |
- << " unsigned Opc = decodeULEB128(++Ptr, &Len);\\\n" |
| 3864 |
- << " Ptr += Len;\\\n" |
| 3865 |
- << " unsigned DecodeIdx = decodeULEB128(Ptr, &Len);\\\n" |
| 3866 |
- << " Ptr += Len;\\\n" |
| 3867 |
-- << " // NumToSkip is a plain 24-bit integer.\\\n" |
| 3868 |
- << " unsigned NumToSkip = *Ptr++;\\\n" |
| 3869 |
- << " NumToSkip |= (*Ptr++) << 8;\\\n" |
| 3870 |
- << " NumToSkip |= (*Ptr++) << 16;\\\n" |
| 3871 |
- << "\\\n" |
| 3872 |
-- << " // Perform the decode operation.\\\n" |
| 3873 |
- << " MCInst TmpMI;\\\n" |
| 3874 |
- << " MCInst_setOpcode(&TmpMI, Opc);\\\n" |
| 3875 |
-- << " bool DecodeComplete;\n" |
| 3876 |
-- << " S = decodeToMCInst(S, DecodeIdx, insn, &TmpMI, Address, DisAsm, " |
| 3877 |
-- "DecodeComplete);\\\n" |
| 3878 |
-+ << " bool DecodeComplete;\\\n" |
| 3879 |
-+ << " S = decoder(S, DecodeIdx, insn, &TmpMI, Address, DisAsm, " |
| 3880 |
-+ "&DecodeComplete);\\\n" |
| 3881 |
-+ << "\\\n" |
| 3882 |
- << " if (DecodeComplete) {\\\n" |
| 3883 |
-- << " // Decoding complete.\\\n" |
| 3884 |
-- << " MI = &TmpMI;\\\n" |
| 3885 |
-+ << " *MI = TmpMI;\\\n" |
| 3886 |
- << " return S;\\\n" |
| 3887 |
- << " } else {\\\n" |
| 3888 |
- << " assert(S == MCDisassembler_Fail);\\\n" |
| 3889 |
-- << " // If the decoding was incomplete, skip.\\\n" |
| 3890 |
- << " Ptr += NumToSkip;\\\n" |
| 3891 |
-- << " // Reset decode status. This also drops a SoftFail status " |
| 3892 |
-- "that could be\\\n" |
| 3893 |
-- << " // set before the decode attempt.\\\n" |
| 3894 |
- << " S = MCDisassembler_Success;\\\n" |
| 3895 |
- << " }\\\n" |
| 3896 |
- << " break;\\\n" |
| 3897 |
- << " }\\\n" |
| 3898 |
- << " case MCD_OPC_SoftFail: {\\\n" |
| 3899 |
-- << " // Decode the mask values.\\\n" |
| 3900 |
- << " unsigned Len;\\\n" |
| 3901 |
- << " InsnType PositiveMask = decodeULEB128(++Ptr, &Len);\\\n" |
| 3902 |
- << " Ptr += Len;\\\n" |
| 3903 |
-@@ -2472,8 +2465,8 @@ static void emitDecodeInstruction(formatted_raw_ostream &OS) { |
| 3904 |
- << " }\\\n" |
| 3905 |
- << " }\\\n" |
| 3906 |
- << " }\\\n" |
| 3907 |
-- << " assert(0);\\\n" |
| 3908 |
-- |
| 3909 |
-+ << " assert(0 && \"bogosity detected in disassembler state " |
| 3910 |
-+ "machine!\");\\\n" |
| 3911 |
- #else |
| 3912 |
- OS << "template<typename InsnType>\n" |
| 3913 |
- << "static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], " |
| 3914 |
-@@ -2752,9 +2745,10 @@ void FixedLenDecoderEmitter::run(raw_ostream &o) { |
| 3915 |
- emitDecodeInstruction(OS); |
| 3916 |
- |
| 3917 |
- #ifdef CAPSTONE |
| 3918 |
-- OS << "FieldFromInstruction(fieldFromInstruction, uint64_t)\n"; |
| 3919 |
-- OS << "DecodeToMCInst(decodeToMCInst, fieldFromInstruction, uint64_t)\n"; |
| 3920 |
-- OS << "DecodeInstruction(decodeInstruction, fieldFromInstruction, decodeToMCInst, uint64_t)\n"; |
| 3921 |
-+ OS << "// For RISCV instruction is 32 bits.\n"; |
| 3922 |
-+ OS << "FieldFromInstruction(fieldFromInstruction, uint32_t)\n"; |
| 3923 |
-+ OS << "DecodeToMCInst(decodeToMCInst, fieldFromInstruction, uint32_t)\n"; |
| 3924 |
-+ OS << "DecodeInstruction(decodeInstruction, fieldFromInstruction, decodeToMCInst, uint32_t)\n"; |
| 3925 |
- #else |
| 3926 |
- OS << "\n} // End llvm namespace\n"; |
| 3927 |
- #endif |
| 3928 |
-diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp |
| 3929 |
-index 01605184f..e59dace24 100644 |
| 3930 |
---- a/llvm/utils/TableGen/InstrInfoEmitter.cpp |
| 3931 |
-+++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp |
| 3932 |
-@@ -769,6 +769,7 @@ void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) { |
| 3933 |
- #ifdef CAPSTONE |
| 3934 |
- std::string GetPublicName(const CodeGenInstruction *Inst) { |
| 3935 |
- std::string Name = Inst->TheDef->getName(); |
| 3936 |
-+#if 0 |
| 3937 |
- // Apply backward compatibility fixups. |
| 3938 |
- // BRNLE -> BNLER. |
| 3939 |
- if (Name.length() >= 5 && Name.substr(0, 5) == "BRAsm") { |
| 3940 |
-@@ -785,7 +786,7 @@ std::string GetPublicName(const CodeGenInstruction *Inst) { |
| 3941 |
- break; |
| 3942 |
- } |
| 3943 |
- Name = Name.substr(0, pos) + Name.substr(pos + 3); |
| 3944 |
-- } |
| 3945 |
-+ }f 0 |
| 3946 |
- // CPSDRxx -> CPSDR. |
| 3947 |
- if (Name.length() >= 2) { |
| 3948 |
- std::string Suffix2 = Name.substr(Name.length() - 2, 2); |
| 3949 |
-@@ -794,7 +795,8 @@ std::string GetPublicName(const CodeGenInstruction *Inst) { |
| 3950 |
- Name = Name.substr(0, Name.length() - 2); |
| 3951 |
- } |
| 3952 |
- } |
| 3953 |
-- return "SYSZ_INS_" + Name; |
| 3954 |
-+#endif |
| 3955 |
-+ return "RISCV_INS_" + Name; |
| 3956 |
- } |
| 3957 |
- |
| 3958 |
- std::string GetRegisterName(Record *Reg) { |
| 3959 |
-@@ -802,6 +804,7 @@ std::string GetRegisterName(Record *Reg) { |
| 3960 |
- for (char& c : Name) { |
| 3961 |
- c = toupper(c); |
| 3962 |
- } |
| 3963 |
-+#if 0 |
| 3964 |
- // R0L, R0D -> R0. |
| 3965 |
- if (Name.length() >= 3 && |
| 3966 |
- Name[Name.length() - 3] == 'R' && |
| 3967 |
-@@ -809,7 +812,8 @@ std::string GetRegisterName(Record *Reg) { |
| 3968 |
- Name[Name.length() - 1] == 'D')) { |
| 3969 |
- Name = Name.substr(0, Name.length() - 3) + Name[Name.length() - 2]; |
| 3970 |
- } |
| 3971 |
-- return "SYSZ_REG_" + Name; |
| 3972 |
-+#endif |
| 3973 |
-+ return "RISCV_REG_" + Name; |
| 3974 |
- } |
| 3975 |
- |
| 3976 |
- std::string GetGroupName(Record *Pred) { |
| 3977 |
-@@ -817,10 +821,12 @@ std::string GetGroupName(Record *Pred) { |
| 3978 |
- for (char& c : Name) { |
| 3979 |
- c = toupper(c); |
| 3980 |
- } |
| 3981 |
-+#if 0 |
| 3982 |
- if (Name.length() >= 7 && Name.substr(0, 7) == "FEATURE") { |
| 3983 |
- Name = Name.substr(7); |
| 3984 |
- } |
| 3985 |
-- return "SYSZ_GRP_" + Name; |
| 3986 |
-+#endif |
| 3987 |
-+ return "RISCV_GRP_" + Name; |
| 3988 |
- } |
| 3989 |
- |
| 3990 |
- void EmitMappingInsn(RecordKeeper &RK, raw_ostream &OS) { |
| 3991 |
-diff --git a/llvm/utils/TableGen/RegisterInfoEmitter.cpp b/llvm/utils/TableGen/RegisterInfoEmitter.cpp |
| 3992 |
-index 0df306680..cf9c352d7 100644 |
| 3993 |
---- a/llvm/utils/TableGen/RegisterInfoEmitter.cpp |
| 3994 |
-+++ b/llvm/utils/TableGen/RegisterInfoEmitter.cpp |
| 3995 |
-@@ -180,12 +180,20 @@ void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 3996 |
- #endif |
| 3997 |
- } |
| 3998 |
- |
| 3999 |
--#ifndef CAPSTONE |
| 4000 |
- const std::vector<Record*> &RegAltNameIndices = Target.getRegAltNameIndices(); |
| 4001 |
- // If the only definition is the default NoRegAltName, we don't need to |
| 4002 |
- // emit anything. |
| 4003 |
- if (RegAltNameIndices.size() > 1) { |
| 4004 |
- OS << "\n// Register alternate name indices\n\n"; |
| 4005 |
-+#ifdef CAPSTONE |
| 4006 |
-+ OS << "enum {\n"; |
| 4007 |
-+ for (unsigned i = 0, e = RegAltNameIndices.size(); i != e; ++i) |
| 4008 |
-+ OS << " " << NAME_PREFIX RegAltNameIndices[i]->getName() |
| 4009 |
-+ << ",\t// " << i << "\n"; |
| 4010 |
-+ OS << " " << NAME_PREFIX "NUM_TARGET_REG_ALT_NAMES = " |
| 4011 |
-+ << RegAltNameIndices.size() << "\n"; |
| 4012 |
-+ OS << "};\n"; |
| 4013 |
-+#else |
| 4014 |
- if (!Namespace.empty()) |
| 4015 |
- OS << "namespace " << Namespace << " {\n"; |
| 4016 |
- OS << "enum {\n"; |
| 4017 |
-@@ -195,11 +203,19 @@ void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 4018 |
- OS << "};\n"; |
| 4019 |
- if (!Namespace.empty()) |
| 4020 |
- OS << "} // end namespace " << Namespace << "\n\n"; |
| 4021 |
-+#endif |
| 4022 |
- } |
| 4023 |
- |
| 4024 |
- auto &SubRegIndices = Bank.getSubRegIndices(); |
| 4025 |
- if (!SubRegIndices.empty()) { |
| 4026 |
- OS << "\n// Subregister indices\n\n"; |
| 4027 |
-+#ifdef CAPSTONE |
| 4028 |
-+ OS << "enum {\n" << " " << NAME_PREFIX "NoSubRegister,\n"; |
| 4029 |
-+ unsigned i = 0; |
| 4030 |
-+ for (const auto &Idx : SubRegIndices) |
| 4031 |
-+ OS << " " << NAME_PREFIX Idx.getName() << ",\t// " << ++i << "\n"; |
| 4032 |
-+ OS << " " << NAME_PREFIX "NUM_TARGET_SUBREGS\n};\n"; |
| 4033 |
-+#else |
| 4034 |
- std::string Namespace = SubRegIndices.front().getNamespace(); |
| 4035 |
- if (!Namespace.empty()) |
| 4036 |
- OS << "namespace " << Namespace << " {\n"; |
| 4037 |
-@@ -210,8 +226,8 @@ void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 4038 |
- OS << " NUM_TARGET_SUBREGS\n};\n"; |
| 4039 |
- if (!Namespace.empty()) |
| 4040 |
- OS << "} // end namespace " << Namespace << "\n\n"; |
| 4041 |
-- } |
| 4042 |
- #endif |
| 4043 |
-+ } |
| 4044 |
- |
| 4045 |
- #ifndef CAPSTONE |
| 4046 |
- OS << "} // end namespace llvm\n\n"; |
| 4047 |
-diff --git a/llvm/utils/TableGen/TableGen.cpp b/llvm/utils/TableGen/TableGen.cpp |
| 4048 |
-index 9e2a868be..7ec93c0e0 100644 |
| 4049 |
---- a/llvm/utils/TableGen/TableGen.cpp |
| 4050 |
-+++ b/llvm/utils/TableGen/TableGen.cpp |
| 4051 |
-@@ -27,8 +27,10 @@ enum ActionType { |
| 4052 |
- GenEmitter, |
| 4053 |
- GenRegisterInfo, |
| 4054 |
- GenInstrInfo, |
| 4055 |
-+#ifdef CAPSTONE |
| 4056 |
- GenMappingInsn, |
| 4057 |
- GenInsnNameMaps, |
| 4058 |
-+#endif |
| 4059 |
- GenInstrDocs, |
| 4060 |
- GenAsmWriter, |
| 4061 |
- GenAsmMatcher, |
| 4062 |
-@@ -76,10 +78,12 @@ namespace { |
| 4063 |
- "Generate registers and register classes info"), |
| 4064 |
- clEnumValN(GenInstrInfo, "gen-instr-info", |
| 4065 |
- "Generate instruction descriptions"), |
| 4066 |
-+#ifdef CAPSTONE |
| 4067 |
- clEnumValN(GenMappingInsn, "gen-mapping-insn", |
| 4068 |
- ""), |
| 4069 |
- clEnumValN(GenInsnNameMaps, "gen-insn-name-maps", |
| 4070 |
- ""), |
| 4071 |
-+#endif |
| 4072 |
- clEnumValN(GenInstrDocs, "gen-instr-docs", |
| 4073 |
- "Generate instruction documentation"), |
| 4074 |
- clEnumValN(GenCallingConv, "gen-callingconv", |
| 4075 |
-@@ -160,12 +164,14 @@ bool LLVMTableGenMain(raw_ostream &OS, RecordKeeper &Records) { |
| 4076 |
- case GenInstrInfo: |
| 4077 |
- EmitInstrInfo(Records, OS); |
| 4078 |
- break; |
| 4079 |
-+#ifdef CAPSTONE |
| 4080 |
- case GenMappingInsn: |
| 4081 |
- EmitMappingInsn(Records, OS); |
| 4082 |
- break; |
| 4083 |
- case GenInsnNameMaps: |
| 4084 |
- EmitInsnNameMaps(Records, OS); |
| 4085 |
- break; |
| 4086 |
-+#endif |
| 4087 |
- case GenInstrDocs: |
| 4088 |
- EmitInstrDocs(Records, OS); |
| 4089 |
- break; |
| 4090 |
--- |
| 4091 |
-2.20.1 |
| 4092 |
- |
| 4093 |
diff --git a/llvm/0003-clear-old-patchs.patch b/llvm/0003-clear-old-patchs.patch |
| 4094 |
deleted file mode 100644 |
| 4095 |
index 720024662..000000000 |
| 4096 |
--- a/llvm/0003-clear-old-patchs.patch |
| 4097 |
+++ /dev/null |
| 4098 |
@@ -1,1602 +0,0 @@ |
| 4099 |
-From 02eecf3f85ad03f12babab3067f2c1bcfff35ed3 Mon Sep 17 00:00:00 2001 |
| 4100 |
-From: fanfuqiang <[email protected]> |
| 4101 |
-Date: Thu, 28 Feb 2019 01:50:13 +0800 |
| 4102 |
-Subject: [PATCH] clear old patchs |
| 4103 |
- |
| 4104 |
---- |
| 4105 |
- ...apstone-generate-GenRegisterInfo.inc.patch | 338 ------------- |
| 4106 |
- ...pstone-generate-GenSubtargetInfo.inc.patch | 86 ---- |
| 4107 |
- ...3-capstone-generate-GenInstrInfo.inc.patch | 130 ----- |
| 4108 |
- ...e-generate-GenDisassemblerTables.inc.patch | 472 ------------------ |
| 4109 |
- ...5-capstone-generate-GenAsmWriter.inc.patch | 225 --------- |
| 4110 |
- ...06-capstone-generate-MappingInsn.inc.patch | 174 ------- |
| 4111 |
- ...apstone-generate-GenInsnNameMaps.inc.patch | 110 ---- |
| 4112 |
- 7 files changed, 1535 deletions(-) |
| 4113 |
- delete mode 100644 llvm/0001-capstone-generate-GenRegisterInfo.inc.patch |
| 4114 |
- delete mode 100644 llvm/0002-capstone-generate-GenSubtargetInfo.inc.patch |
| 4115 |
- delete mode 100644 llvm/0003-capstone-generate-GenInstrInfo.inc.patch |
| 4116 |
- delete mode 100644 llvm/0004-capstone-generate-GenDisassemblerTables.inc.patch |
| 4117 |
- delete mode 100644 llvm/0005-capstone-generate-GenAsmWriter.inc.patch |
| 4118 |
- delete mode 100644 llvm/0006-capstone-generate-MappingInsn.inc.patch |
| 4119 |
- delete mode 100644 llvm/0007-capstone-generate-GenInsnNameMaps.inc.patch |
| 4120 |
- |
| 4121 |
-diff --git a/llvm/0001-capstone-generate-GenRegisterInfo.inc.patch b/llvm/0001-capstone-generate-GenRegisterInfo.inc.patch |
| 4122 |
-deleted file mode 100644 |
| 4123 |
-index b51aa515a..000000000 |
| 4124 |
---- a/llvm/0001-capstone-generate-GenRegisterInfo.inc.patch |
| 4125 |
-+++ /dev/null |
| 4126 |
-@@ -1,338 +0,0 @@ |
| 4127 |
--From 5d631cb16e7ba5dd0380ff1ee9dda192b1cdad18 Mon Sep 17 00:00:00 2001 |
| 4128 |
--From: mephi42 <[email protected]> |
| 4129 |
--Date: Tue, 7 Aug 2018 17:02:40 +0200 |
| 4130 |
--Subject: [PATCH 1/7] capstone: generate *GenRegisterInfo.inc |
| 4131 |
-- |
| 4132 |
----- |
| 4133 |
-- utils/TableGen/RegisterInfoEmitter.cpp | 130 ++++++++++++++++++++++--- |
| 4134 |
-- 1 file changed, 115 insertions(+), 15 deletions(-) |
| 4135 |
-- |
| 4136 |
--diff --git a/utils/TableGen/RegisterInfoEmitter.cpp b/utils/TableGen/RegisterInfoEmitter.cpp |
| 4137 |
--index 49016cca799..6ebb7148b1b 100644 |
| 4138 |
----- a/utils/TableGen/RegisterInfoEmitter.cpp |
| 4139 |
--+++ b/utils/TableGen/RegisterInfoEmitter.cpp |
| 4140 |
--@@ -99,6 +99,12 @@ private: |
| 4141 |
-- |
| 4142 |
-- } // end anonymous namespace |
| 4143 |
-- |
| 4144 |
--+#ifdef CAPSTONE |
| 4145 |
--+#define NAME_PREFIX Target.getName() << "_" << |
| 4146 |
--+#else |
| 4147 |
--+#define NAME_PREFIX |
| 4148 |
--+#endif |
| 4149 |
--+ |
| 4150 |
-- // runEnums - Print out enum values for all of the registers. |
| 4151 |
-- void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 4152 |
-- CodeGenTarget &Target, CodeGenRegBank &Bank) { |
| 4153 |
--@@ -107,13 +113,22 @@ void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 4154 |
-- // Register enums are stored as uint16_t in the tables. Make sure we'll fit. |
| 4155 |
-- assert(Registers.size() <= 0xffff && "Too many regs to fit in tables"); |
| 4156 |
-- |
| 4157 |
--+#ifndef CAPSTONE |
| 4158 |
-- StringRef Namespace = Registers.front().TheDef->getValueAsString("Namespace"); |
| 4159 |
--+#endif |
| 4160 |
-- |
| 4161 |
-- emitSourceFileHeader("Target Register Enum Values", OS); |
| 4162 |
-- |
| 4163 |
--+#ifdef CAPSTONE |
| 4164 |
--+ OS << "/* Capstone Disassembly Engine */\n" |
| 4165 |
--+ "/* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */\n" |
| 4166 |
--+ "\n"; |
| 4167 |
--+#endif |
| 4168 |
--+ |
| 4169 |
-- OS << "\n#ifdef GET_REGINFO_ENUM\n"; |
| 4170 |
-- OS << "#undef GET_REGINFO_ENUM\n\n"; |
| 4171 |
-- |
| 4172 |
--+#ifndef CAPSTONE |
| 4173 |
-- OS << "namespace llvm {\n\n"; |
| 4174 |
-- |
| 4175 |
-- OS << "class MCRegisterClass;\n" |
| 4176 |
--@@ -122,16 +137,20 @@ void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 4177 |
-- |
| 4178 |
-- if (!Namespace.empty()) |
| 4179 |
-- OS << "namespace " << Namespace << " {\n"; |
| 4180 |
--- OS << "enum {\n NoRegister,\n"; |
| 4181 |
--+#endif |
| 4182 |
--+ |
| 4183 |
--+ OS << "enum {\n " << NAME_PREFIX "NoRegister,\n"; |
| 4184 |
-- |
| 4185 |
-- for (const auto &Reg : Registers) |
| 4186 |
--- OS << " " << Reg.getName() << " = " << Reg.EnumValue << ",\n"; |
| 4187 |
--+ OS << " " << NAME_PREFIX Reg.getName() << " = " << Reg.EnumValue << ",\n"; |
| 4188 |
-- assert(Registers.size() == Registers.back().EnumValue && |
| 4189 |
-- "Register enum value mismatch!"); |
| 4190 |
--- OS << " NUM_TARGET_REGS \t// " << Registers.size()+1 << "\n"; |
| 4191 |
--+ OS << " " << NAME_PREFIX "NUM_TARGET_REGS \t// " << Registers.size()+1 << "\n"; |
| 4192 |
-- OS << "};\n"; |
| 4193 |
--+#ifndef CAPSTONE |
| 4194 |
-- if (!Namespace.empty()) |
| 4195 |
-- OS << "} // end namespace " << Namespace << "\n"; |
| 4196 |
--+#endif |
| 4197 |
-- |
| 4198 |
-- const auto &RegisterClasses = Bank.getRegClasses(); |
| 4199 |
-- if (!RegisterClasses.empty()) { |
| 4200 |
--@@ -140,18 +159,29 @@ void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 4201 |
-- assert(RegisterClasses.size() <= 0xffff && |
| 4202 |
-- "Too many register classes to fit in tables"); |
| 4203 |
-- |
| 4204 |
--- OS << "\n// Register classes\n\n"; |
| 4205 |
--+ OS << "\n// Register classes\n"; |
| 4206 |
--+#ifndef CAPSTONE |
| 4207 |
--+ OS << "\n"; |
| 4208 |
-- if (!Namespace.empty()) |
| 4209 |
-- OS << "namespace " << Namespace << " {\n"; |
| 4210 |
--+#endif |
| 4211 |
-- OS << "enum {\n"; |
| 4212 |
-- for (const auto &RC : RegisterClasses) |
| 4213 |
--- OS << " " << RC.getName() << "RegClassID" |
| 4214 |
--+ OS << " " << NAME_PREFIX RC.getName() << "RegClassID" |
| 4215 |
-- << " = " << RC.EnumValue << ",\n"; |
| 4216 |
--- OS << "\n };\n"; |
| 4217 |
--+#ifdef CAPSTONE |
| 4218 |
--+ OS |
| 4219 |
--+#else |
| 4220 |
--+ OS << "\n " |
| 4221 |
--+#endif |
| 4222 |
--+ << "};\n"; |
| 4223 |
--+#ifndef CAPSTONE |
| 4224 |
-- if (!Namespace.empty()) |
| 4225 |
-- OS << "} // end namespace " << Namespace << "\n\n"; |
| 4226 |
--+#endif |
| 4227 |
-- } |
| 4228 |
-- |
| 4229 |
--+#ifndef CAPSTONE |
| 4230 |
-- const std::vector<Record*> &RegAltNameIndices = Target.getRegAltNameIndices(); |
| 4231 |
-- // If the only definition is the default NoRegAltName, we don't need to |
| 4232 |
-- // emit anything. |
| 4233 |
--@@ -182,8 +212,11 @@ void RegisterInfoEmitter::runEnums(raw_ostream &OS, |
| 4234 |
-- if (!Namespace.empty()) |
| 4235 |
-- OS << "} // end namespace " << Namespace << "\n\n"; |
| 4236 |
-- } |
| 4237 |
--+#endif |
| 4238 |
-- |
| 4239 |
--+#ifndef CAPSTONE |
| 4240 |
-- OS << "} // end namespace llvm\n\n"; |
| 4241 |
--+#endif |
| 4242 |
-- OS << "#endif // GET_REGINFO_ENUM\n\n"; |
| 4243 |
-- } |
| 4244 |
-- |
| 4245 |
--@@ -830,7 +863,9 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 4246 |
-- |
| 4247 |
-- const auto &Regs = RegBank.getRegisters(); |
| 4248 |
-- |
| 4249 |
--+#ifndef CAPSTONE |
| 4250 |
-- auto &SubRegIndices = RegBank.getSubRegIndices(); |
| 4251 |
--+#endif |
| 4252 |
-- // The lists of sub-registers and super-registers go in the same array. That |
| 4253 |
-- // allows us to share suffixes. |
| 4254 |
-- typedef std::vector<const CodeGenRegister*> RegVec; |
| 4255 |
--@@ -922,25 +957,40 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 4256 |
-- LaneMaskSeqs.layout(); |
| 4257 |
-- SubRegIdxSeqs.layout(); |
| 4258 |
-- |
| 4259 |
--+#ifndef CAPSTONE |
| 4260 |
-- OS << "namespace llvm {\n\n"; |
| 4261 |
--+#endif |
| 4262 |
-- |
| 4263 |
-- const std::string &TargetName = Target.getName(); |
| 4264 |
-- |
| 4265 |
-- // Emit the shared table of differential lists. |
| 4266 |
--- OS << "extern const MCPhysReg " << TargetName << "RegDiffLists[] = {\n"; |
| 4267 |
--+#ifdef CAPSTONE |
| 4268 |
--+ OS << "static" |
| 4269 |
--+#else |
| 4270 |
--+ OS << "extern" |
| 4271 |
--+#endif |
| 4272 |
--+ << " const MCPhysReg " << TargetName << "RegDiffLists[] = {\n"; |
| 4273 |
-- DiffSeqs.emit(OS, printDiff16); |
| 4274 |
-- OS << "};\n\n"; |
| 4275 |
-- |
| 4276 |
--+#ifndef CAPSTONE |
| 4277 |
-- // Emit the shared table of regunit lane mask sequences. |
| 4278 |
-- OS << "extern const LaneBitmask " << TargetName << "LaneMaskLists[] = {\n"; |
| 4279 |
-- LaneMaskSeqs.emit(OS, printMask, "LaneBitmask::getAll()"); |
| 4280 |
-- OS << "};\n\n"; |
| 4281 |
--+#endif |
| 4282 |
-- |
| 4283 |
-- // Emit the table of sub-register indexes. |
| 4284 |
--- OS << "extern const uint16_t " << TargetName << "SubRegIdxLists[] = {\n"; |
| 4285 |
--+#ifdef CAPSTONE |
| 4286 |
--+ OS << "static" |
| 4287 |
--+#else |
| 4288 |
--+ OS << "extern" |
| 4289 |
--+#endif |
| 4290 |
--+ << " const uint16_t " << TargetName << "SubRegIdxLists[] = {\n"; |
| 4291 |
-- SubRegIdxSeqs.emit(OS, printSubRegIndex); |
| 4292 |
-- OS << "};\n\n"; |
| 4293 |
-- |
| 4294 |
--+#ifndef CAPSTONE |
| 4295 |
-- // Emit the table of sub-register index sizes. |
| 4296 |
-- OS << "extern const MCRegisterInfo::SubRegCoveredBits " |
| 4297 |
-- << TargetName << "SubRegIdxRanges[] = {\n"; |
| 4298 |
--@@ -950,14 +1000,22 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 4299 |
-- << Idx.getName() << "\n"; |
| 4300 |
-- } |
| 4301 |
-- OS << "};\n\n"; |
| 4302 |
--+#endif |
| 4303 |
-- |
| 4304 |
-- // Emit the string table. |
| 4305 |
-- RegStrings.layout(); |
| 4306 |
--+#ifndef CAPSTONE |
| 4307 |
-- OS << "extern const char " << TargetName << "RegStrings[] = {\n"; |
| 4308 |
-- RegStrings.emit(OS, printChar); |
| 4309 |
-- OS << "};\n\n"; |
| 4310 |
--+#endif |
| 4311 |
-- |
| 4312 |
--- OS << "extern const MCRegisterDesc " << TargetName |
| 4313 |
--+#ifdef CAPSTONE |
| 4314 |
--+ OS << "static" |
| 4315 |
--+#else |
| 4316 |
--+ OS << "extern" |
| 4317 |
--+#endif |
| 4318 |
--+ << " const MCRegisterDesc " << TargetName |
| 4319 |
-- << "RegDesc[] = { // Descriptors\n"; |
| 4320 |
-- OS << " { " << RegStrings.get("") << ", 0, 0, 0, 0, 0 },\n"; |
| 4321 |
-- |
| 4322 |
--@@ -973,6 +1031,7 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 4323 |
-- } |
| 4324 |
-- OS << "};\n\n"; // End of register descriptors... |
| 4325 |
-- |
| 4326 |
--+#ifndef CAPSTONE |
| 4327 |
-- // Emit the table of register unit roots. Each regunit has one or two root |
| 4328 |
-- // registers. |
| 4329 |
-- OS << "extern const MCPhysReg " << TargetName << "RegUnitRoots[][2] = {\n"; |
| 4330 |
--@@ -986,11 +1045,14 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 4331 |
-- OS << " },\n"; |
| 4332 |
-- } |
| 4333 |
-- OS << "};\n\n"; |
| 4334 |
--+#endif |
| 4335 |
-- |
| 4336 |
-- const auto &RegisterClasses = RegBank.getRegClasses(); |
| 4337 |
-- |
| 4338 |
-- // Loop over all of the register classes... emitting each one. |
| 4339 |
--+#ifndef CAPSTONE |
| 4340 |
-- OS << "namespace { // Register classes...\n"; |
| 4341 |
--+#endif |
| 4342 |
-- |
| 4343 |
-- SequenceToOffsetTable<std::string> RegClassStrings; |
| 4344 |
-- |
| 4345 |
--@@ -1005,15 +1067,28 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 4346 |
-- |
| 4347 |
-- // Emit the register list now. |
| 4348 |
-- OS << " // " << Name << " Register Class...\n" |
| 4349 |
--- << " const MCPhysReg " << Name |
| 4350 |
--+ << " " |
| 4351 |
--+#ifdef CAPSTONE |
| 4352 |
--+ << "static " |
| 4353 |
--+#endif |
| 4354 |
--+ << "const MCPhysReg " << Name |
| 4355 |
-- << "[] = {\n "; |
| 4356 |
-- for (Record *Reg : Order) { |
| 4357 |
--- OS << getQualifiedName(Reg) << ", "; |
| 4358 |
--+#ifdef CAPSTONE |
| 4359 |
--+ OS << NAME_PREFIX Reg->getName() |
| 4360 |
--+#else |
| 4361 |
--+ OS << getQualifiedName(Reg) |
| 4362 |
--+#endif |
| 4363 |
--+ << ", "; |
| 4364 |
-- } |
| 4365 |
-- OS << "\n };\n\n"; |
| 4366 |
-- |
| 4367 |
-- OS << " // " << Name << " Bit set.\n" |
| 4368 |
--- << " const uint8_t " << Name |
| 4369 |
--+ << " " |
| 4370 |
--+#ifdef CAPSTONE |
| 4371 |
--+ << "static " |
| 4372 |
--+#endif |
| 4373 |
--+ << "const uint8_t " << Name |
| 4374 |
-- << "Bits[] = {\n "; |
| 4375 |
-- BitVectorEmitter BVE; |
| 4376 |
-- for (Record *Reg : Order) { |
| 4377 |
--@@ -1023,14 +1098,23 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 4378 |
-- OS << "\n };\n\n"; |
| 4379 |
-- |
| 4380 |
-- } |
| 4381 |
--+#ifndef CAPSTONE |
| 4382 |
-- OS << "} // end anonymous namespace\n\n"; |
| 4383 |
--+#endif |
| 4384 |
-- |
| 4385 |
-- RegClassStrings.layout(); |
| 4386 |
--+#ifndef CAPSTONE |
| 4387 |
-- OS << "extern const char " << TargetName << "RegClassStrings[] = {\n"; |
| 4388 |
-- RegClassStrings.emit(OS, printChar); |
| 4389 |
-- OS << "};\n\n"; |
| 4390 |
--+#endif |
| 4391 |
-- |
| 4392 |
--- OS << "extern const MCRegisterClass " << TargetName |
| 4393 |
--+#ifdef CAPSTONE |
| 4394 |
--+ OS << "static" |
| 4395 |
--+#else |
| 4396 |
--+ OS << "extern" |
| 4397 |
--+#endif |
| 4398 |
--+ << " const MCRegisterClass " << TargetName |
| 4399 |
-- << "MCRegisterClasses[] = {\n"; |
| 4400 |
-- |
| 4401 |
-- for (const auto &RC : RegisterClasses) { |
| 4402 |
--@@ -1041,7 +1125,12 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 4403 |
-- OS << " { " << RC.getName() << ", " << RC.getName() << "Bits, " |
| 4404 |
-- << RegClassStrings.get(RC.getName()) << ", " |
| 4405 |
-- << RC.getOrder().size() << ", sizeof(" << RC.getName() << "Bits), " |
| 4406 |
--- << RC.getQualifiedName() + "RegClassID" << ", " |
| 4407 |
--+#ifdef CAPSTONE |
| 4408 |
--+ << NAME_PREFIX RC.getName() |
| 4409 |
--+#else |
| 4410 |
--+ << RC.getQualifiedName() |
| 4411 |
--+#endif |
| 4412 |
--+ << "RegClassID" << ", " |
| 4413 |
-- << RegSize/8 << ", " |
| 4414 |
-- << RC.CopyCost << ", " |
| 4415 |
-- << ( RC.Allocatable ? "true" : "false" ) << " },\n"; |
| 4416 |
--@@ -1049,6 +1138,7 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 4417 |
-- |
| 4418 |
-- OS << "};\n\n"; |
| 4419 |
-- |
| 4420 |
--+#ifndef CAPSTONE |
| 4421 |
-- EmitRegMappingTables(OS, Regs, false); |
| 4422 |
-- |
| 4423 |
-- // Emit Reg encoding table |
| 4424 |
--@@ -1067,7 +1157,9 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 4425 |
-- OS << " " << Value << ",\n"; |
| 4426 |
-- } |
| 4427 |
-- OS << "};\n"; // End of HW encoding table |
| 4428 |
--+#endif |
| 4429 |
-- |
| 4430 |
--+#ifndef CAPSTONE |
| 4431 |
-- // MCRegisterInfo initialization routine. |
| 4432 |
-- OS << "static inline void Init" << TargetName |
| 4433 |
-- << "MCRegisterInfo(MCRegisterInfo *RI, unsigned RA, " |
| 4434 |
--@@ -1088,7 +1180,12 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 4435 |
-- OS << "}\n\n"; |
| 4436 |
-- |
| 4437 |
-- OS << "} // end namespace llvm\n\n"; |
| 4438 |
--- OS << "#endif // GET_REGINFO_MC_DESC\n\n"; |
| 4439 |
--+#endif |
| 4440 |
--+ OS << "#endif // GET_REGINFO_MC_DESC\n" |
| 4441 |
--+#ifndef CAPSTONE |
| 4442 |
--+ << "\n" |
| 4443 |
--+#endif |
| 4444 |
--+ ; |
| 4445 |
-- } |
| 4446 |
-- |
| 4447 |
-- void |
| 4448 |
--@@ -1568,10 +1665,13 @@ RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target, |
| 4449 |
-- |
| 4450 |
-- void RegisterInfoEmitter::run(raw_ostream &OS) { |
| 4451 |
-- CodeGenRegBank &RegBank = Target.getRegBank(); |
| 4452 |
--+ |
| 4453 |
-- runEnums(OS, Target, RegBank); |
| 4454 |
-- runMCDesc(OS, Target, RegBank); |
| 4455 |
--+#ifndef CAPSTONE |
| 4456 |
-- runTargetHeader(OS, Target, RegBank); |
| 4457 |
-- runTargetDesc(OS, Target, RegBank); |
| 4458 |
--+#endif |
| 4459 |
-- |
| 4460 |
-- if (RegisterInfoDebug) |
| 4461 |
-- debugDump(errs()); |
| 4462 |
---- |
| 4463 |
--2.19.1 |
| 4464 |
-- |
| 4465 |
-diff --git a/llvm/0002-capstone-generate-GenSubtargetInfo.inc.patch b/llvm/0002-capstone-generate-GenSubtargetInfo.inc.patch |
| 4466 |
-deleted file mode 100644 |
| 4467 |
-index 56ad28256..000000000 |
| 4468 |
---- a/llvm/0002-capstone-generate-GenSubtargetInfo.inc.patch |
| 4469 |
-+++ /dev/null |
| 4470 |
-@@ -1,86 +0,0 @@ |
| 4471 |
--From 46ca491e1bbbc9ace2a91fe6a7b112c83b9b88cc Mon Sep 17 00:00:00 2001 |
| 4472 |
--From: mephi42 <[email protected]> |
| 4473 |
--Date: Tue, 7 Aug 2018 17:42:59 +0200 |
| 4474 |
--Subject: [PATCH 2/7] capstone: generate *GenSubtargetInfo.inc |
| 4475 |
-- |
| 4476 |
----- |
| 4477 |
-- utils/TableGen/SubtargetEmitter.cpp | 28 +++++++++++++++++++++++++++- |
| 4478 |
-- 1 file changed, 27 insertions(+), 1 deletion(-) |
| 4479 |
-- |
| 4480 |
--diff --git a/utils/TableGen/SubtargetEmitter.cpp b/utils/TableGen/SubtargetEmitter.cpp |
| 4481 |
--index c5da8d8142f..98ab3240472 100644 |
| 4482 |
----- a/utils/TableGen/SubtargetEmitter.cpp |
| 4483 |
--+++ b/utils/TableGen/SubtargetEmitter.cpp |
| 4484 |
--@@ -147,7 +147,9 @@ void SubtargetEmitter::Enumeration(raw_ostream &OS) { |
| 4485 |
-- if (N > MAX_SUBTARGET_FEATURES) |
| 4486 |
-- PrintFatalError("Too many subtarget features! Bump MAX_SUBTARGET_FEATURES."); |
| 4487 |
-- |
| 4488 |
--+#ifndef CAPSTONE |
| 4489 |
-- OS << "namespace " << Target << " {\n"; |
| 4490 |
--+#endif |
| 4491 |
-- |
| 4492 |
-- // Open enumeration. |
| 4493 |
-- OS << "enum {\n"; |
| 4494 |
--@@ -158,12 +160,22 @@ void SubtargetEmitter::Enumeration(raw_ostream &OS) { |
| 4495 |
-- Record *Def = DefList[i]; |
| 4496 |
-- |
| 4497 |
-- // Get and emit name |
| 4498 |
--- OS << " " << Def->getName() << " = " << i << ",\n"; |
| 4499 |
--+ OS << " " |
| 4500 |
--+#ifdef CAPSTONE |
| 4501 |
--+ << Target << "_" |
| 4502 |
--+#endif |
| 4503 |
--+ << Def->getName() << " = " |
| 4504 |
--+#ifdef CAPSTONE |
| 4505 |
--+ << "1ULL << " |
| 4506 |
--+#endif |
| 4507 |
--+ << i << ",\n"; |
| 4508 |
-- } |
| 4509 |
-- |
| 4510 |
-- // Close enumeration and namespace |
| 4511 |
-- OS << "};\n"; |
| 4512 |
--+#ifndef CAPSTONE |
| 4513 |
-- OS << "} // end namespace " << Target << "\n"; |
| 4514 |
--+#endif |
| 4515 |
-- } |
| 4516 |
-- |
| 4517 |
-- // |
| 4518 |
--@@ -1709,14 +1721,27 @@ void SubtargetEmitter::emitGenMCSubtargetInfo(raw_ostream &OS) { |
| 4519 |
-- void SubtargetEmitter::run(raw_ostream &OS) { |
| 4520 |
-- emitSourceFileHeader("Subtarget Enumeration Source Fragment", OS); |
| 4521 |
-- |
| 4522 |
--+#ifdef CAPSTONE |
| 4523 |
--+ OS << "/* Capstone Disassembly Engine, http://www.capstone-engine.org */\n" |
| 4524 |
--+ "/* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */\n" |
| 4525 |
--+ "\n"; |
| 4526 |
--+#endif |
| 4527 |
--+ |
| 4528 |
-- OS << "\n#ifdef GET_SUBTARGETINFO_ENUM\n"; |
| 4529 |
-- OS << "#undef GET_SUBTARGETINFO_ENUM\n\n"; |
| 4530 |
-- |
| 4531 |
--+#ifndef CAPSTONE |
| 4532 |
-- OS << "namespace llvm {\n"; |
| 4533 |
--+#endif |
| 4534 |
-- Enumeration(OS); |
| 4535 |
--+#ifdef CAPSTONE |
| 4536 |
--+ OS << "\n"; |
| 4537 |
--+#else |
| 4538 |
-- OS << "} // end namespace llvm\n\n"; |
| 4539 |
--+#endif |
| 4540 |
-- OS << "#endif // GET_SUBTARGETINFO_ENUM\n\n"; |
| 4541 |
-- |
| 4542 |
--+#ifndef CAPSTONE |
| 4543 |
-- OS << "\n#ifdef GET_SUBTARGETINFO_MC_DESC\n"; |
| 4544 |
-- OS << "#undef GET_SUBTARGETINFO_MC_DESC\n\n"; |
| 4545 |
-- |
| 4546 |
--@@ -1857,6 +1882,7 @@ void SubtargetEmitter::run(raw_ostream &OS) { |
| 4547 |
-- OS << "} // end namespace llvm\n\n"; |
| 4548 |
-- |
| 4549 |
-- OS << "#endif // GET_SUBTARGETINFO_CTOR\n\n"; |
| 4550 |
--+#endif |
| 4551 |
-- } |
| 4552 |
-- |
| 4553 |
-- namespace llvm { |
| 4554 |
---- |
| 4555 |
--2.19.1 |
| 4556 |
-- |
| 4557 |
-diff --git a/llvm/0003-capstone-generate-GenInstrInfo.inc.patch b/llvm/0003-capstone-generate-GenInstrInfo.inc.patch |
| 4558 |
-deleted file mode 100644 |
| 4559 |
-index 2baa59fc9..000000000 |
| 4560 |
---- a/llvm/0003-capstone-generate-GenInstrInfo.inc.patch |
| 4561 |
-+++ /dev/null |
| 4562 |
-@@ -1,130 +0,0 @@ |
| 4563 |
--From a73fe8ac18d3ca81fa7a8d8c404cd7e0faf92ddc Mon Sep 17 00:00:00 2001 |
| 4564 |
--From: mephi42 <[email protected]> |
| 4565 |
--Date: Tue, 7 Aug 2018 17:59:43 +0200 |
| 4566 |
--Subject: [PATCH 3/7] capstone: generate *GenInstrInfo.inc |
| 4567 |
-- |
| 4568 |
----- |
| 4569 |
-- utils/TableGen/InstrInfoEmitter.cpp | 49 ++++++++++++++++++++++++++--- |
| 4570 |
-- 1 file changed, 44 insertions(+), 5 deletions(-) |
| 4571 |
-- |
| 4572 |
--diff --git a/utils/TableGen/InstrInfoEmitter.cpp b/utils/TableGen/InstrInfoEmitter.cpp |
| 4573 |
--index 0aff1aa6f94..2f3a2729262 100644 |
| 4574 |
----- a/utils/TableGen/InstrInfoEmitter.cpp |
| 4575 |
--+++ b/utils/TableGen/InstrInfoEmitter.cpp |
| 4576 |
--@@ -92,6 +92,7 @@ private: |
| 4577 |
-- |
| 4578 |
-- } // end anonymous namespace |
| 4579 |
-- |
| 4580 |
--+#ifndef CAPSTONE |
| 4581 |
-- static void PrintDefList(const std::vector<Record*> &Uses, |
| 4582 |
-- unsigned Num, raw_ostream &OS) { |
| 4583 |
-- OS << "static const MCPhysReg ImplicitList" << Num << "[] = { "; |
| 4584 |
--@@ -99,6 +100,7 @@ static void PrintDefList(const std::vector<Record*> &Uses, |
| 4585 |
-- OS << getQualifiedName(U) << ", "; |
| 4586 |
-- OS << "0 };\n"; |
| 4587 |
-- } |
| 4588 |
--+#endif |
| 4589 |
-- |
| 4590 |
-- //===----------------------------------------------------------------------===// |
| 4591 |
-- // Operand Info Emission. |
| 4592 |
--@@ -426,8 +428,17 @@ void InstrInfoEmitter::emitTIIHelperMethods(raw_ostream &OS) { |
| 4593 |
-- // run - Emit the main instruction description records for the target... |
| 4594 |
-- void InstrInfoEmitter::run(raw_ostream &OS) { |
| 4595 |
-- emitSourceFileHeader("Target Instruction Enum Values and Descriptors", OS); |
| 4596 |
--+ |
| 4597 |
--+#ifdef CAPSTONE |
| 4598 |
--+ OS << "/* Capstone Disassembly Engine */\n" |
| 4599 |
--+ "/* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */\n" |
| 4600 |
--+ "\n" |
| 4601 |
--+ "\n"; |
| 4602 |
--+#endif |
| 4603 |
--+ |
| 4604 |
-- emitEnums(OS); |
| 4605 |
-- |
| 4606 |
--+#ifndef CAPSTONE |
| 4607 |
-- OS << "#ifdef GET_INSTRINFO_MC_DESC\n"; |
| 4608 |
-- OS << "#undef GET_INSTRINFO_MC_DESC\n"; |
| 4609 |
-- |
| 4610 |
--@@ -545,6 +556,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) { |
| 4611 |
-- emitOperandTypesEnum(OS, Target); |
| 4612 |
-- |
| 4613 |
-- emitMCIIHelperMethods(OS); |
| 4614 |
--+#endif |
| 4615 |
-- } |
| 4616 |
-- |
| 4617 |
-- void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num, |
| 4618 |
--@@ -659,7 +671,9 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) { |
| 4619 |
-- OS << "#ifdef GET_INSTRINFO_ENUM\n"; |
| 4620 |
-- OS << "#undef GET_INSTRINFO_ENUM\n"; |
| 4621 |
-- |
| 4622 |
--+#ifndef CAPSTONE |
| 4623 |
-- OS << "namespace llvm {\n\n"; |
| 4624 |
--+#endif |
| 4625 |
-- |
| 4626 |
-- CodeGenTarget Target(Records); |
| 4627 |
-- |
| 4628 |
--@@ -669,17 +683,39 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) { |
| 4629 |
-- if (Namespace.empty()) |
| 4630 |
-- PrintFatalError("No instructions defined!"); |
| 4631 |
-- |
| 4632 |
--+#ifndef CAPSTONE |
| 4633 |
-- OS << "namespace " << Namespace << " {\n"; |
| 4634 |
--- OS << " enum {\n"; |
| 4635 |
--+#endif |
| 4636 |
--+#ifdef CAPSTONE |
| 4637 |
--+ OS << "\n" |
| 4638 |
--+#else |
| 4639 |
--+ OS << " " |
| 4640 |
--+#endif |
| 4641 |
--+ << "enum {\n"; |
| 4642 |
-- unsigned Num = 0; |
| 4643 |
-- for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) |
| 4644 |
--- OS << " " << Inst->TheDef->getName() << "\t= " << Num++ << ",\n"; |
| 4645 |
--- OS << " INSTRUCTION_LIST_END = " << Num << "\n"; |
| 4646 |
--+ OS << " " |
| 4647 |
--+#ifdef CAPSTONE |
| 4648 |
--+ << Target.getName() << "_" |
| 4649 |
--+#endif |
| 4650 |
--+ << Inst->TheDef->getName() << "\t= " << Num++ << ",\n"; |
| 4651 |
--+ OS << " " |
| 4652 |
--+#ifdef CAPSTONE |
| 4653 |
--+ << Target.getName() << "_" |
| 4654 |
--+#endif |
| 4655 |
--+ << "INSTRUCTION_LIST_END = " << Num << "\n"; |
| 4656 |
-- OS << " };\n\n"; |
| 4657 |
--+#ifndef CAPSTONE |
| 4658 |
-- OS << "} // end " << Namespace << " namespace\n"; |
| 4659 |
-- OS << "} // end llvm namespace\n"; |
| 4660 |
--- OS << "#endif // GET_INSTRINFO_ENUM\n\n"; |
| 4661 |
--- |
| 4662 |
--+#endif |
| 4663 |
--+ OS << "#endif // GET_INSTRINFO_ENUM\n" |
| 4664 |
--+#ifndef CAPSTONE |
| 4665 |
--+ << "\n" |
| 4666 |
--+#endif |
| 4667 |
--+ ; |
| 4668 |
--+ |
| 4669 |
--+#ifndef CAPSTONE |
| 4670 |
-- OS << "#ifdef GET_INSTRINFO_SCHED_ENUM\n"; |
| 4671 |
-- OS << "#undef GET_INSTRINFO_SCHED_ENUM\n"; |
| 4672 |
-- OS << "namespace llvm {\n\n"; |
| 4673 |
--@@ -696,13 +732,16 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) { |
| 4674 |
-- OS << "} // end llvm namespace\n"; |
| 4675 |
-- |
| 4676 |
-- OS << "#endif // GET_INSTRINFO_SCHED_ENUM\n\n"; |
| 4677 |
--+#endif |
| 4678 |
-- } |
| 4679 |
-- |
| 4680 |
-- namespace llvm { |
| 4681 |
-- |
| 4682 |
-- void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) { |
| 4683 |
-- InstrInfoEmitter(RK).run(OS); |
| 4684 |
--+#ifndef CAPSTONE |
| 4685 |
-- EmitMapTable(RK, OS); |
| 4686 |
--+#endif |
| 4687 |
-- } |
| 4688 |
-- |
| 4689 |
-- } // end llvm namespace |
| 4690 |
---- |
| 4691 |
--2.19.1 |
| 4692 |
-- |
| 4693 |
-diff --git a/llvm/0004-capstone-generate-GenDisassemblerTables.inc.patch b/llvm/0004-capstone-generate-GenDisassemblerTables.inc.patch |
| 4694 |
-deleted file mode 100644 |
| 4695 |
-index 0002b81b4..000000000 |
| 4696 |
---- a/llvm/0004-capstone-generate-GenDisassemblerTables.inc.patch |
| 4697 |
-+++ /dev/null |
| 4698 |
-@@ -1,472 +0,0 @@ |
| 4699 |
--From 29da4c6929679b8ac4019767ab4ebcd83c9894b4 Mon Sep 17 00:00:00 2001 |
| 4700 |
--From: mephi42 <[email protected]> |
| 4701 |
--Date: Tue, 7 Aug 2018 18:20:17 +0200 |
| 4702 |
--Subject: [PATCH 4/7] capstone: generate *GenDisassemblerTables.inc |
| 4703 |
-- |
| 4704 |
----- |
| 4705 |
-- utils/TableGen/DisassemblerEmitter.cpp | 12 +- |
| 4706 |
-- utils/TableGen/FixedLenDecoderEmitter.cpp | 248 ++++++++++++++++++++-- |
| 4707 |
-- 2 files changed, 239 insertions(+), 21 deletions(-) |
| 4708 |
-- |
| 4709 |
--diff --git a/utils/TableGen/DisassemblerEmitter.cpp b/utils/TableGen/DisassemblerEmitter.cpp |
| 4710 |
--index b99a0a973a2..2ac6d89645c 100644 |
| 4711 |
----- a/utils/TableGen/DisassemblerEmitter.cpp |
| 4712 |
--+++ b/utils/TableGen/DisassemblerEmitter.cpp |
| 4713 |
--@@ -106,6 +106,11 @@ extern void EmitFixedLenDecoder(RecordKeeper &RK, raw_ostream &OS, |
| 4714 |
-- void EmitDisassembler(RecordKeeper &Records, raw_ostream &OS) { |
| 4715 |
-- CodeGenTarget Target(Records); |
| 4716 |
-- emitSourceFileHeader(" * " + Target.getName().str() + " Disassembler", OS); |
| 4717 |
--+#ifdef CAPSTONE |
| 4718 |
--+ OS << "/* Capstone Disassembly Engine */\n" |
| 4719 |
--+ "/* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */\n" |
| 4720 |
--+ "\n"; |
| 4721 |
--+#endif |
| 4722 |
-- |
| 4723 |
-- // X86 uses a custom disassembler. |
| 4724 |
-- if (Target.getName() == "X86") { |
| 4725 |
--@@ -150,7 +155,12 @@ void EmitDisassembler(RecordKeeper &Records, raw_ostream &OS) { |
| 4726 |
-- } |
| 4727 |
-- |
| 4728 |
-- EmitFixedLenDecoder(Records, OS, Target.getName(), |
| 4729 |
--- "if (", " == MCDisassembler::Fail)", |
| 4730 |
--+ "if (", |
| 4731 |
--+#ifdef CAPSTONE |
| 4732 |
--+ " == MCDisassembler_Fail)", |
| 4733 |
--+#else |
| 4734 |
--+ " == MCDisassembler::Fail)", |
| 4735 |
--+#endif |
| 4736 |
-- "MCDisassembler::Success", "MCDisassembler::Fail", ""); |
| 4737 |
-- } |
| 4738 |
-- |
| 4739 |
--diff --git a/utils/TableGen/FixedLenDecoderEmitter.cpp b/utils/TableGen/FixedLenDecoderEmitter.cpp |
| 4740 |
--index fcecc764d44..36845d960d8 100644 |
| 4741 |
----- a/utils/TableGen/FixedLenDecoderEmitter.cpp |
| 4742 |
--+++ b/utils/TableGen/FixedLenDecoderEmitter.cpp |
| 4743 |
--@@ -730,7 +730,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 4744 |
-- ++I; |
| 4745 |
-- unsigned Start = *I++; |
| 4746 |
-- unsigned Len = *I++; |
| 4747 |
--- OS.indent(Indentation) << "MCD::OPC_ExtractField, " << Start << ", " |
| 4748 |
--+ OS.indent(Indentation) |
| 4749 |
--+#ifdef CAPSTONE |
| 4750 |
--+ << "MCD_OPC_ExtractField" |
| 4751 |
--+#else |
| 4752 |
--+ << "MCD::OPC_ExtractField" |
| 4753 |
--+#endif |
| 4754 |
--+ << ", " << Start << ", " |
| 4755 |
-- << Len << ", // Inst{"; |
| 4756 |
-- if (Len > 1) |
| 4757 |
-- OS << (Start + Len - 1) << "-"; |
| 4758 |
--@@ -739,7 +745,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 4759 |
-- } |
| 4760 |
-- case MCD::OPC_FilterValue: { |
| 4761 |
-- ++I; |
| 4762 |
--- OS.indent(Indentation) << "MCD::OPC_FilterValue, "; |
| 4763 |
--+ OS.indent(Indentation) |
| 4764 |
--+#ifdef CAPSTONE |
| 4765 |
--+ << "MCD_OPC_FilterValue" |
| 4766 |
--+#else |
| 4767 |
--+ << "MCD::OPC_FilterValue" |
| 4768 |
--+#endif |
| 4769 |
--+ << ", "; |
| 4770 |
-- // The filter value is ULEB128 encoded. |
| 4771 |
-- while (*I >= 128) |
| 4772 |
-- OS << (unsigned)*I++ << ", "; |
| 4773 |
--@@ -759,7 +771,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 4774 |
-- ++I; |
| 4775 |
-- unsigned Start = *I++; |
| 4776 |
-- unsigned Len = *I++; |
| 4777 |
--- OS.indent(Indentation) << "MCD::OPC_CheckField, " << Start << ", " |
| 4778 |
--+ OS.indent(Indentation) |
| 4779 |
--+#ifdef CAPSTONE |
| 4780 |
--+ << "MCD_OPC_CheckField" |
| 4781 |
--+#else |
| 4782 |
--+ << "MCD::OPC_CheckField" |
| 4783 |
--+#endif |
| 4784 |
--+ << ", " << Start << ", " |
| 4785 |
-- << Len << ", ";// << Val << ", " << NumToSkip << ",\n"; |
| 4786 |
-- // ULEB128 encoded field value. |
| 4787 |
-- for (; *I >= 128; ++I) |
| 4788 |
--@@ -777,7 +795,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 4789 |
-- } |
| 4790 |
-- case MCD::OPC_CheckPredicate: { |
| 4791 |
-- ++I; |
| 4792 |
--- OS.indent(Indentation) << "MCD::OPC_CheckPredicate, "; |
| 4793 |
--+ OS.indent(Indentation) |
| 4794 |
--+#ifdef CAPSTONE |
| 4795 |
--+ << "MCD_OPC_CheckPredicate" |
| 4796 |
--+#else |
| 4797 |
--+ << "MCD::OPC_CheckPredicate" |
| 4798 |
--+#endif |
| 4799 |
--+ << ", "; |
| 4800 |
-- for (; *I >= 128; ++I) |
| 4801 |
-- OS << (unsigned)*I << ", "; |
| 4802 |
-- OS << (unsigned)*I++ << ", "; |
| 4803 |
--@@ -803,7 +827,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 4804 |
-- && "ULEB128 value too large!"); |
| 4805 |
-- // Decode the Opcode value. |
| 4806 |
-- unsigned Opc = decodeULEB128(Buffer); |
| 4807 |
--- OS.indent(Indentation) << "MCD::OPC_" << (IsTry ? "Try" : "") |
| 4808 |
--+ OS.indent(Indentation) |
| 4809 |
--+#ifdef CAPSTONE |
| 4810 |
--+ << "MCD_OPC_" |
| 4811 |
--+#else |
| 4812 |
--+ << "MCD::OPC_" |
| 4813 |
--+#endif |
| 4814 |
--+ << (IsTry ? "Try" : "") |
| 4815 |
-- << "Decode, "; |
| 4816 |
-- for (p = Buffer; *p >= 128; ++p) |
| 4817 |
-- OS << (unsigned)*p << ", "; |
| 4818 |
--@@ -837,7 +867,12 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 4819 |
-- } |
| 4820 |
-- case MCD::OPC_SoftFail: { |
| 4821 |
-- ++I; |
| 4822 |
--- OS.indent(Indentation) << "MCD::OPC_SoftFail"; |
| 4823 |
--+ OS.indent(Indentation) |
| 4824 |
--+#ifdef CAPSTONE |
| 4825 |
--+ << "MCD_OPC_SoftFail"; |
| 4826 |
--+#else |
| 4827 |
--+ << "MCD::OPC_SoftFail"; |
| 4828 |
--+#endif |
| 4829 |
-- // Positive mask |
| 4830 |
-- uint64_t Value = 0; |
| 4831 |
-- unsigned Shift = 0; |
| 4832 |
--@@ -869,7 +904,13 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 4833 |
-- } |
| 4834 |
-- case MCD::OPC_Fail: { |
| 4835 |
-- ++I; |
| 4836 |
--- OS.indent(Indentation) << "MCD::OPC_Fail,\n"; |
| 4837 |
--+ OS.indent(Indentation) |
| 4838 |
--+#ifdef CAPSTONE |
| 4839 |
--+ << "MCD_OPC_Fail" |
| 4840 |
--+#else |
| 4841 |
--+ << "MCD::OPC_Fail" |
| 4842 |
--+#endif |
| 4843 |
--+ << ",\n"; |
| 4844 |
-- break; |
| 4845 |
-- } |
| 4846 |
-- } |
| 4847 |
--@@ -884,23 +925,46 @@ void FixedLenDecoderEmitter::emitTable(formatted_raw_ostream &OS, |
| 4848 |
-- void FixedLenDecoderEmitter:: |
| 4849 |
-- emitPredicateFunction(formatted_raw_ostream &OS, PredicateSet &Predicates, |
| 4850 |
-- unsigned Indentation) const { |
| 4851 |
--+#ifdef CAPSTONE |
| 4852 |
--+ OS.indent(Indentation) << "static bool getbool(uint64_t b)\n"; |
| 4853 |
--+ OS.indent(Indentation) << "{\n"; |
| 4854 |
--+ OS.indent(Indentation) << "\treturn b != 0;\n"; |
| 4855 |
--+ OS.indent(Indentation) << "}\n\n"; |
| 4856 |
--+#endif |
| 4857 |
--+ |
| 4858 |
-- // The predicate function is just a big switch statement based on the |
| 4859 |
-- // input predicate index. |
| 4860 |
-- OS.indent(Indentation) << "static bool checkDecoderPredicate(unsigned Idx, " |
| 4861 |
--+#ifdef CAPSTONE |
| 4862 |
--+ << "uint64_t Bits)\n{\n"; |
| 4863 |
--+#else |
| 4864 |
-- << "const FeatureBitset& Bits) {\n"; |
| 4865 |
--+#endif |
| 4866 |
-- Indentation += 2; |
| 4867 |
-- if (!Predicates.empty()) { |
| 4868 |
-- OS.indent(Indentation) << "switch (Idx) {\n"; |
| 4869 |
--- OS.indent(Indentation) << "default: llvm_unreachable(\"Invalid index!\");\n"; |
| 4870 |
--+ OS.indent(Indentation) << "default: " |
| 4871 |
--+#ifdef CAPSTONE |
| 4872 |
--+ << "// " |
| 4873 |
--+#endif |
| 4874 |
--+ << "llvm_unreachable(\"Invalid index!\");\n"; |
| 4875 |
-- unsigned Index = 0; |
| 4876 |
-- for (const auto &Predicate : Predicates) { |
| 4877 |
-- OS.indent(Indentation) << "case " << Index++ << ":\n"; |
| 4878 |
--- OS.indent(Indentation+2) << "return (" << Predicate << ");\n"; |
| 4879 |
--+ OS.indent(Indentation+2) << "return " |
| 4880 |
--+#ifdef CAPSTONE |
| 4881 |
--+ << "getbool" |
| 4882 |
--+#endif |
| 4883 |
--+ << "(" << Predicate << ");\n"; |
| 4884 |
-- } |
| 4885 |
-- OS.indent(Indentation) << "}\n"; |
| 4886 |
-- } else { |
| 4887 |
-- // No case statement to emit |
| 4888 |
--- OS.indent(Indentation) << "llvm_unreachable(\"Invalid index!\");\n"; |
| 4889 |
--+ OS.indent(Indentation) |
| 4890 |
--+#ifdef CAPSTONE |
| 4891 |
--+ << "// " |
| 4892 |
--+#endif |
| 4893 |
--+ << "llvm_unreachable(\"Invalid index!\");\n"; |
| 4894 |
-- } |
| 4895 |
-- Indentation -= 2; |
| 4896 |
-- OS.indent(Indentation) << "}\n\n"; |
| 4897 |
--@@ -911,23 +975,39 @@ emitDecoderFunction(formatted_raw_ostream &OS, DecoderSet &Decoders, |
| 4898 |
-- unsigned Indentation) const { |
| 4899 |
-- // The decoder function is just a big switch statement based on the |
| 4900 |
-- // input decoder index. |
| 4901 |
--+#ifdef CAPSTONE |
| 4902 |
--+#define EDF_EOL " \\\n" |
| 4903 |
--+ OS.indent(Indentation) << "#define DecodeToMCInst(fname,fieldname, InsnType) \\\n"; |
| 4904 |
--+ OS.indent(Indentation) << "static DecodeStatus fname(DecodeStatus S, unsigned Idx, InsnType insn, MCInst *MI, \\\n"; |
| 4905 |
--+ OS.indent(Indentation) << " uint64_t Address, const void *Decoder) \\\n"; |
| 4906 |
--+ OS.indent(Indentation) << "{ \\\n"; |
| 4907 |
--+#else |
| 4908 |
--+#define EDF_EOL "\n" |
| 4909 |
-- OS.indent(Indentation) << "template<typename InsnType>\n"; |
| 4910 |
-- OS.indent(Indentation) << "static DecodeStatus decodeToMCInst(DecodeStatus S," |
| 4911 |
-- << " unsigned Idx, InsnType insn, MCInst &MI,\n"; |
| 4912 |
-- OS.indent(Indentation) << " uint64_t " |
| 4913 |
-- << "Address, const void *Decoder, bool &DecodeComplete) {\n"; |
| 4914 |
--+#endif |
| 4915 |
-- Indentation += 2; |
| 4916 |
--+#ifndef CAPSTONE |
| 4917 |
-- OS.indent(Indentation) << "DecodeComplete = true;\n"; |
| 4918 |
--- OS.indent(Indentation) << "InsnType tmp;\n"; |
| 4919 |
--- OS.indent(Indentation) << "switch (Idx) {\n"; |
| 4920 |
--- OS.indent(Indentation) << "default: llvm_unreachable(\"Invalid index!\");\n"; |
| 4921 |
--+#endif |
| 4922 |
--+ OS.indent(Indentation) << "InsnType tmp;" EDF_EOL; |
| 4923 |
--+ OS.indent(Indentation) << "switch (Idx) {" EDF_EOL; |
| 4924 |
--+ OS.indent(Indentation) << "default:" |
| 4925 |
--+#ifndef CAPSTONE |
| 4926 |
--+ << " llvm_unreachable(\"Invalid index!\");\n"; |
| 4927 |
--+#else |
| 4928 |
--+ << " \\\n"; |
| 4929 |
--+#endif |
| 4930 |
-- unsigned Index = 0; |
| 4931 |
-- for (const auto &Decoder : Decoders) { |
| 4932 |
--- OS.indent(Indentation) << "case " << Index++ << ":\n"; |
| 4933 |
--+ OS.indent(Indentation) << "case " << Index++ << ":" EDF_EOL; |
| 4934 |
-- OS << Decoder; |
| 4935 |
--- OS.indent(Indentation+2) << "return S;\n"; |
| 4936 |
--+ OS.indent(Indentation+2) << "return S;" EDF_EOL; |
| 4937 |
-- } |
| 4938 |
--- OS.indent(Indentation) << "}\n"; |
| 4939 |
--+ OS.indent(Indentation) << "}" EDF_EOL; |
| 4940 |
-- Indentation -= 2; |
| 4941 |
-- OS.indent(Indentation) << "}\n\n"; |
| 4942 |
-- } |
| 4943 |
--@@ -1054,16 +1134,21 @@ void FilterChooser::emitBinaryParser(raw_ostream &o, unsigned &Indentation, |
| 4944 |
-- const std::string &Decoder = OpInfo.Decoder; |
| 4945 |
-- |
| 4946 |
-- if (OpInfo.numFields() != 1) |
| 4947 |
--- o.indent(Indentation) << "tmp = 0;\n"; |
| 4948 |
--+ o.indent(Indentation) << "tmp = 0;" EDF_EOL; |
| 4949 |
-- |
| 4950 |
-- for (const EncodingField &EF : OpInfo) { |
| 4951 |
-- o.indent(Indentation) << "tmp "; |
| 4952 |
-- if (OpInfo.numFields() != 1) o << '|'; |
| 4953 |
--- o << "= fieldFromInstruction" |
| 4954 |
--+ o << "= " |
| 4955 |
--+#ifdef CAPSTONE |
| 4956 |
--+ << "fieldname" |
| 4957 |
--+#else |
| 4958 |
--+ << "fieldFromInstruction" |
| 4959 |
--+#endif |
| 4960 |
-- << "(insn, " << EF.Base << ", " << EF.Width << ')'; |
| 4961 |
-- if (OpInfo.numFields() != 1 || EF.Offset != 0) |
| 4962 |
-- o << " << " << EF.Offset; |
| 4963 |
--- o << ";\n"; |
| 4964 |
--+ o << ";" EDF_EOL; |
| 4965 |
-- } |
| 4966 |
-- |
| 4967 |
-- if (Decoder != "") { |
| 4968 |
--@@ -1071,8 +1156,12 @@ void FilterChooser::emitBinaryParser(raw_ostream &o, unsigned &Indentation, |
| 4969 |
-- o.indent(Indentation) << Emitter->GuardPrefix << Decoder |
| 4970 |
-- << "(MI, tmp, Address, Decoder)" |
| 4971 |
-- << Emitter->GuardPostfix |
| 4972 |
--+#ifdef CAPSTONE |
| 4973 |
--+ << " return MCDisassembler_Fail; \\\n"; |
| 4974 |
--+#else |
| 4975 |
-- << " { " << (OpHasCompleteDecoder ? "" : "DecodeComplete = false; ") |
| 4976 |
-- << "return MCDisassembler::Fail; }\n"; |
| 4977 |
--+#endif |
| 4978 |
-- } else { |
| 4979 |
-- OpHasCompleteDecoder = true; |
| 4980 |
-- o.indent(Indentation) << "MI.addOperand(MCOperand::createImm(tmp));\n"; |
| 4981 |
--@@ -1091,7 +1180,13 @@ void FilterChooser::emitDecoder(raw_ostream &OS, unsigned Indentation, |
| 4982 |
-- << "(MI, insn, Address, Decoder)" |
| 4983 |
-- << Emitter->GuardPostfix |
| 4984 |
-- << " { " << (HasCompleteDecoder ? "" : "DecodeComplete = false; ") |
| 4985 |
--- << "return MCDisassembler::Fail; }\n"; |
| 4986 |
--+ << "return " |
| 4987 |
--+#ifdef CAPSTONE |
| 4988 |
--+ << "MCDisassembler_Fail" |
| 4989 |
--+#else |
| 4990 |
--+ << "MCDisassembler::Fail" |
| 4991 |
--+#endif |
| 4992 |
--+ << "; }\n"; |
| 4993 |
-- break; |
| 4994 |
-- } |
| 4995 |
-- |
| 4996 |
--@@ -1129,10 +1224,19 @@ unsigned FilterChooser::getDecoderIndex(DecoderSet &Decoders, |
| 4997 |
-- static void emitSinglePredicateMatch(raw_ostream &o, StringRef str, |
| 4998 |
-- const std::string &PredicateNamespace) { |
| 4999 |
-- if (str[0] == '!') |
| 5000 |
--+#ifdef CAPSTONE |
| 5001 |
--+ o << "~(Bits & " << PredicateNamespace << "_" |
| 5002 |
--+ << str.slice(1,str.size()) << ")"; |
| 5003 |
--+#else |
| 5004 |
-- o << "!Bits[" << PredicateNamespace << "::" |
| 5005 |
-- << str.slice(1,str.size()) << "]"; |
| 5006 |
--+#endif |
| 5007 |
-- else |
| 5008 |
--+#ifdef CAPSTONE |
| 5009 |
--+ o << "(Bits & " << PredicateNamespace << "_" << str << ")"; |
| 5010 |
--+#else |
| 5011 |
-- o << "Bits[" << PredicateNamespace << "::" << str << "]"; |
| 5012 |
--+#endif |
| 5013 |
-- } |
| 5014 |
-- |
| 5015 |
-- bool FilterChooser::emitPredicateMatch(raw_ostream &o, unsigned &Indentation, |
| 5016 |
--@@ -2047,6 +2151,17 @@ static bool populateInstruction(CodeGenTarget &Target, |
| 5017 |
-- // fieldFromInstruction(). |
| 5018 |
-- static void emitFieldFromInstruction(formatted_raw_ostream &OS) { |
| 5019 |
-- OS << "// Helper function for extracting fields from encoded instructions.\n" |
| 5020 |
--+#ifdef CAPSTONE |
| 5021 |
--+ << "#define FieldFromInstruction(fname, InsnType) \\\n" |
| 5022 |
--+ << "static InsnType fname(InsnType insn, unsigned startBit, unsigned numBits) \\\n" |
| 5023 |
--+ << "{ \\\n" |
| 5024 |
--+ << " InsnType fieldMask; \\\n" |
| 5025 |
--+ << " if (numBits == sizeof(InsnType)*8) \\\n" |
| 5026 |
--+ << " fieldMask = (InsnType)(-1LL); \\\n" |
| 5027 |
--+ << " else \\\n" |
| 5028 |
--+ << " fieldMask = (((InsnType)1 << numBits) - 1) << startBit; \\\n" |
| 5029 |
--+ << " return (insn & fieldMask) >> startBit; \\\n" |
| 5030 |
--+#else |
| 5031 |
-- << "template<typename InsnType>\n" |
| 5032 |
-- << "static InsnType fieldFromInstruction(InsnType insn, unsigned startBit,\n" |
| 5033 |
-- << " unsigned numBits) {\n" |
| 5034 |
--@@ -2058,12 +2173,92 @@ static void emitFieldFromInstruction(formatted_raw_ostream &OS) { |
| 5035 |
-- << " else\n" |
| 5036 |
-- << " fieldMask = (((InsnType)1 << numBits) - 1) << startBit;\n" |
| 5037 |
-- << " return (insn & fieldMask) >> startBit;\n" |
| 5038 |
--+#endif |
| 5039 |
-- << "}\n\n"; |
| 5040 |
-- } |
| 5041 |
-- |
| 5042 |
-- // emitDecodeInstruction - Emit the templated helper function |
| 5043 |
-- // decodeInstruction(). |
| 5044 |
-- static void emitDecodeInstruction(formatted_raw_ostream &OS) { |
| 5045 |
--+#ifdef CAPSTONE |
| 5046 |
--+ OS << "#define DecodeInstruction(fname, fieldname, decoder, InsnType) \\\n" |
| 5047 |
--+ << "static DecodeStatus fname(const uint8_t DecodeTable[], MCInst *MI, \\\n" |
| 5048 |
--+ << " InsnType insn, uint64_t Address, const MCRegisterInfo *MRI, int feature) \\\n" |
| 5049 |
--+ << "{ \\\n" |
| 5050 |
--+ << " uint64_t Bits = getFeatureBits(feature); \\\n" |
| 5051 |
--+ << " const uint8_t *Ptr = DecodeTable; \\\n" |
| 5052 |
--+ << " uint32_t CurFieldValue = 0, ExpectedValue; \\\n" |
| 5053 |
--+ << " DecodeStatus S = MCDisassembler_Success; \\\n" |
| 5054 |
--+ << " unsigned Start, Len, NumToSkip, PIdx, Opc, DecodeIdx; \\\n" |
| 5055 |
--+ << " InsnType Val, FieldValue, PositiveMask, NegativeMask; \\\n" |
| 5056 |
--+ << " bool Pred, Fail; \\\n" |
| 5057 |
--+ << " for (;;) { \\\n" |
| 5058 |
--+ << " switch (*Ptr) { \\\n" |
| 5059 |
--+ << " default: \\\n" |
| 5060 |
--+ << " return MCDisassembler_Fail; \\\n" |
| 5061 |
--+ << " case MCD_OPC_ExtractField: { \\\n" |
| 5062 |
--+ << " Start = *++Ptr; \\\n" |
| 5063 |
--+ << " Len = *++Ptr; \\\n" |
| 5064 |
--+ << " ++Ptr; \\\n" |
| 5065 |
--+ << " CurFieldValue = (uint32_t)fieldname(insn, Start, Len); \\\n" |
| 5066 |
--+ << " break; \\\n" |
| 5067 |
--+ << " } \\\n" |
| 5068 |
--+ << " case MCD_OPC_FilterValue: { \\\n" |
| 5069 |
--+ << " Val = (InsnType)decodeULEB128(++Ptr, &Len); \\\n" |
| 5070 |
--+ << " Ptr += Len; \\\n" |
| 5071 |
--+ << " NumToSkip = *Ptr++; \\\n" |
| 5072 |
--+ << " NumToSkip |= (*Ptr++) << 8; \\\n" |
| 5073 |
--+ << " if (Val != CurFieldValue) \\\n" |
| 5074 |
--+ << " Ptr += NumToSkip; \\\n" |
| 5075 |
--+ << " break; \\\n" |
| 5076 |
--+ << " } \\\n" |
| 5077 |
--+ << " case MCD_OPC_CheckField: { \\\n" |
| 5078 |
--+ << " Start = *++Ptr; \\\n" |
| 5079 |
--+ << " Len = *++Ptr; \\\n" |
| 5080 |
--+ << " FieldValue = fieldname(insn, Start, Len); \\\n" |
| 5081 |
--+ << " ExpectedValue = (uint32_t)decodeULEB128(++Ptr, &Len); \\\n" |
| 5082 |
--+ << " Ptr += Len; \\\n" |
| 5083 |
--+ << " NumToSkip = *Ptr++; \\\n" |
| 5084 |
--+ << " NumToSkip |= (*Ptr++) << 8; \\\n" |
| 5085 |
--+ << " if (ExpectedValue != FieldValue) \\\n" |
| 5086 |
--+ << " Ptr += NumToSkip; \\\n" |
| 5087 |
--+ << " break; \\\n" |
| 5088 |
--+ << " } \\\n" |
| 5089 |
--+ << " case MCD_OPC_CheckPredicate: { \\\n" |
| 5090 |
--+ << " PIdx = (uint32_t)decodeULEB128(++Ptr, &Len); \\\n" |
| 5091 |
--+ << " Ptr += Len; \\\n" |
| 5092 |
--+ << " NumToSkip = *Ptr++; \\\n" |
| 5093 |
--+ << " NumToSkip |= (*Ptr++) << 8; \\\n" |
| 5094 |
--+ << " Pred = checkDecoderPredicate(PIdx, Bits); \\\n" |
| 5095 |
--+ << " if (!Pred) \\\n" |
| 5096 |
--+ << " Ptr += NumToSkip; \\\n" |
| 5097 |
--+ << " (void)Pred; \\\n" |
| 5098 |
--+ << " break; \\\n" |
| 5099 |
--+ << " } \\\n" |
| 5100 |
--+ << " case MCD_OPC_Decode: { \\\n" |
| 5101 |
--+ << " Opc = (unsigned)decodeULEB128(++Ptr, &Len); \\\n" |
| 5102 |
--+ << " Ptr += Len; \\\n" |
| 5103 |
--+ << " DecodeIdx = (unsigned)decodeULEB128(Ptr, &Len); \\\n" |
| 5104 |
--+ << " Ptr += Len; \\\n" |
| 5105 |
--+ << " MCInst_setOpcode(MI, Opc); \\\n" |
| 5106 |
--+ << " return decoder(S, DecodeIdx, insn, MI, Address, MRI); \\\n" |
| 5107 |
--+ << " } \\\n" |
| 5108 |
--+ << " case MCD_OPC_SoftFail: { \\\n" |
| 5109 |
--+ << " PositiveMask = (InsnType)decodeULEB128(++Ptr, &Len); \\\n" |
| 5110 |
--+ << " Ptr += Len; \\\n" |
| 5111 |
--+ << " NegativeMask = (InsnType)decodeULEB128(Ptr, &Len); \\\n" |
| 5112 |
--+ << " Ptr += Len; \\\n" |
| 5113 |
--+ << " Fail = (insn & PositiveMask) || (~insn & NegativeMask); \\\n" |
| 5114 |
--+ << " if (Fail) \\\n" |
| 5115 |
--+ << " S = MCDisassembler_SoftFail; \\\n" |
| 5116 |
--+ << " break; \\\n" |
| 5117 |
--+ << " } \\\n" |
| 5118 |
--+ << " case MCD_OPC_Fail: { \\\n" |
| 5119 |
--+ << " return MCDisassembler_Fail; \\\n" |
| 5120 |
--+ << " } \\\n" |
| 5121 |
--+ << " } \\\n" |
| 5122 |
--+ << " } \\\n" |
| 5123 |
--+#else |
| 5124 |
-- OS << "template<typename InsnType>\n" |
| 5125 |
-- << "static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], " |
| 5126 |
-- "MCInst &MI,\n" |
| 5127 |
--@@ -2240,12 +2435,18 @@ static void emitDecodeInstruction(formatted_raw_ostream &OS) { |
| 5128 |
-- << " }\n" |
| 5129 |
-- << " llvm_unreachable(\"bogosity detected in disassembler state " |
| 5130 |
-- "machine!\");\n" |
| 5131 |
--+#endif |
| 5132 |
-- << "}\n\n"; |
| 5133 |
-- } |
| 5134 |
-- |
| 5135 |
-- // Emits disassembler code for instruction decoding. |
| 5136 |
-- void FixedLenDecoderEmitter::run(raw_ostream &o) { |
| 5137 |
-- formatted_raw_ostream OS(o); |
| 5138 |
--+#ifdef CAPSTONE |
| 5139 |
--+ OS << "#include \"../../MCInst.h\"\n"; |
| 5140 |
--+ OS << "#include \"../../LEB128.h\"\n"; |
| 5141 |
--+ OS << "\n"; |
| 5142 |
--+#else |
| 5143 |
-- OS << "#include \"llvm/MC/MCInst.h\"\n"; |
| 5144 |
-- OS << "#include \"llvm/Support/Debug.h\"\n"; |
| 5145 |
-- OS << "#include \"llvm/Support/DataTypes.h\"\n"; |
| 5146 |
--@@ -2254,6 +2455,7 @@ void FixedLenDecoderEmitter::run(raw_ostream &o) { |
| 5147 |
-- OS << "#include <assert.h>\n"; |
| 5148 |
-- OS << '\n'; |
| 5149 |
-- OS << "namespace llvm {\n\n"; |
| 5150 |
--+#endif |
| 5151 |
-- |
| 5152 |
-- emitFieldFromInstruction(OS); |
| 5153 |
-- |
| 5154 |
--@@ -2322,7 +2524,13 @@ void FixedLenDecoderEmitter::run(raw_ostream &o) { |
| 5155 |
-- // Emit the main entry point for the decoder, decodeInstruction(). |
| 5156 |
-- emitDecodeInstruction(OS); |
| 5157 |
-- |
| 5158 |
--+#ifdef CAPSTONE |
| 5159 |
--+ OS << "FieldFromInstruction(fieldFromInstruction, uint64_t)\n"; |
| 5160 |
--+ OS << "DecodeToMCInst(decodeToMCInst, fieldFromInstruction, uint64_t)\n"; |
| 5161 |
--+ OS << "DecodeInstruction(decodeInstruction, fieldFromInstruction, decodeToMCInst, uint64_t)\n"; |
| 5162 |
--+#else |
| 5163 |
-- OS << "\n} // End llvm namespace\n"; |
| 5164 |
--+#endif |
| 5165 |
-- } |
| 5166 |
-- |
| 5167 |
-- namespace llvm { |
| 5168 |
---- |
| 5169 |
--2.19.1 |
| 5170 |
-- |
| 5171 |
-diff --git a/llvm/0005-capstone-generate-GenAsmWriter.inc.patch b/llvm/0005-capstone-generate-GenAsmWriter.inc.patch |
| 5172 |
-deleted file mode 100644 |
| 5173 |
-index cd1353eb7..000000000 |
| 5174 |
---- a/llvm/0005-capstone-generate-GenAsmWriter.inc.patch |
| 5175 |
-+++ /dev/null |
| 5176 |
-@@ -1,225 +0,0 @@ |
| 5177 |
--From 5569e48b9cb34a33910e1e850fbfabc999f016a2 Mon Sep 17 00:00:00 2001 |
| 5178 |
--From: mephi42 <[email protected]> |
| 5179 |
--Date: Tue, 7 Aug 2018 20:00:08 +0200 |
| 5180 |
--Subject: [PATCH 5/7] capstone: generate *GenAsmWriter.inc |
| 5181 |
-- |
| 5182 |
----- |
| 5183 |
-- utils/TableGen/AsmWriterEmitter.cpp | 89 +++++++++++++++++++++++++++-- |
| 5184 |
-- utils/TableGen/AsmWriterInst.cpp | 4 ++ |
| 5185 |
-- 2 files changed, 87 insertions(+), 6 deletions(-) |
| 5186 |
-- |
| 5187 |
--diff --git a/utils/TableGen/AsmWriterEmitter.cpp b/utils/TableGen/AsmWriterEmitter.cpp |
| 5188 |
--index 3c4c9c8e5c6..133800d217c 100644 |
| 5189 |
----- a/utils/TableGen/AsmWriterEmitter.cpp |
| 5190 |
--+++ b/utils/TableGen/AsmWriterEmitter.cpp |
| 5191 |
--@@ -272,16 +272,22 @@ static void UnescapeString(std::string &Str) { |
| 5192 |
-- /// clearing the Instructions vector. |
| 5193 |
-- void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { |
| 5194 |
-- Record *AsmWriter = Target.getAsmWriter(); |
| 5195 |
--+#ifndef CAPSTONE |
| 5196 |
-- StringRef ClassName = AsmWriter->getValueAsString("AsmWriterClassName"); |
| 5197 |
--+#endif |
| 5198 |
-- bool PassSubtarget = AsmWriter->getValueAsInt("PassSubtarget"); |
| 5199 |
-- |
| 5200 |
-- O << |
| 5201 |
-- "/// printInstruction - This method is automatically generated by tablegen\n" |
| 5202 |
-- "/// from the instruction set description.\n" |
| 5203 |
--+#ifdef CAPSTONE |
| 5204 |
--+ "static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)\n{\n"; |
| 5205 |
--+#else |
| 5206 |
-- "void " << Target.getName() << ClassName |
| 5207 |
-- << "::printInstruction(const MCInst *MI, " |
| 5208 |
-- << (PassSubtarget ? "const MCSubtargetInfo &STI, " : "") |
| 5209 |
-- << "raw_ostream &O) {\n"; |
| 5210 |
--+#endif |
| 5211 |
-- |
| 5212 |
-- // Build an aggregate string, and build a table of offsets into it. |
| 5213 |
-- SequenceToOffsetTable<std::string> StringTable; |
| 5214 |
--@@ -379,9 +385,16 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { |
| 5215 |
-- } |
| 5216 |
-- |
| 5217 |
-- // Emit the string table itself. |
| 5218 |
--+#ifdef CAPSTONE |
| 5219 |
--+ O << "#ifndef CAPSTONE_DIET\n"; |
| 5220 |
--+#endif |
| 5221 |
-- O << " static const char AsmStrs[] = {\n"; |
| 5222 |
-- StringTable.emit(O, printChar); |
| 5223 |
--- O << " };\n\n"; |
| 5224 |
--+ O << " };\n" |
| 5225 |
--+#ifdef CAPSTONE |
| 5226 |
--+ << "#endif\n" |
| 5227 |
--+#endif |
| 5228 |
--+ << "\n"; |
| 5229 |
-- |
| 5230 |
-- // Emit the lookup tables in pieces to minimize wasted bytes. |
| 5231 |
-- unsigned BytesNeeded = ((OpcodeInfoBits - BitsLeft) + 7) / 8; |
| 5232 |
--@@ -409,21 +422,45 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { |
| 5233 |
-- // If the total bits is more than 32-bits we need to use a 64-bit type. |
| 5234 |
-- if (BitsLeft < (OpcodeInfoBits - 32)) |
| 5235 |
-- BitsOS << "(uint64_t)"; |
| 5236 |
--- BitsOS << "OpInfo" << Table << "[MI->getOpcode()] << " << Shift << ";\n"; |
| 5237 |
--+ BitsOS << "OpInfo" << Table << "[" |
| 5238 |
--+#ifdef CAPSTONE |
| 5239 |
--+ << "MCInst_getOpcode(MI)" |
| 5240 |
--+#else |
| 5241 |
--+ << "MI->getOpcode()" |
| 5242 |
--+#endif |
| 5243 |
--+ << "] << " << Shift << ";\n"; |
| 5244 |
-- // Prepare the shift for the next iteration and increment the table count. |
| 5245 |
-- Shift += TableSize; |
| 5246 |
-- ++Table; |
| 5247 |
-- } |
| 5248 |
-- |
| 5249 |
-- // Emit the initial tab character. |
| 5250 |
--+#ifndef CAPSTONE |
| 5251 |
-- O << " O << \"\\t\";\n\n"; |
| 5252 |
--+#endif |
| 5253 |
-- |
| 5254 |
-- O << " // Emit the opcode for the instruction.\n"; |
| 5255 |
-- O << BitsString; |
| 5256 |
-- |
| 5257 |
-- // Emit the starting string. |
| 5258 |
--- O << " assert(Bits != 0 && \"Cannot print this instruction.\");\n" |
| 5259 |
--- << " O << AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << ")-1;\n\n"; |
| 5260 |
--+ O << " " |
| 5261 |
--+#ifdef CAPSTONE |
| 5262 |
--+ << "// " |
| 5263 |
--+#endif |
| 5264 |
--+ << "assert(Bits != 0 && \"Cannot print this instruction.\");\n" |
| 5265 |
--+#ifdef CAPSTONE |
| 5266 |
--+ << "#ifndef CAPSTONE_DIET\n" |
| 5267 |
--+ << " SStream_concat0(O, " |
| 5268 |
--+#else |
| 5269 |
--+ << " O << " |
| 5270 |
--+#endif |
| 5271 |
--+ << "AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << ")-1" |
| 5272 |
--+#ifdef CAPSTONE |
| 5273 |
--+ << ");\n" |
| 5274 |
--+ << "#endif\n\n"; |
| 5275 |
--+#else |
| 5276 |
--+ << ");\n\n"; |
| 5277 |
--+#endif |
| 5278 |
-- |
| 5279 |
-- // Output the table driven operand information. |
| 5280 |
-- BitsLeft = OpcodeInfoBits-AsmStrBits; |
| 5281 |
--@@ -455,7 +492,11 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { |
| 5282 |
-- O << " switch ((Bits >> " |
| 5283 |
-- << (OpcodeInfoBits-BitsLeft) << ") & " |
| 5284 |
-- << ((1 << NumBits)-1) << ") {\n" |
| 5285 |
--- << " default: llvm_unreachable(\"Invalid command number.\");\n"; |
| 5286 |
--+ << " default: " |
| 5287 |
--+#ifdef CAPSTONE |
| 5288 |
--+ << "// " |
| 5289 |
--+#endif |
| 5290 |
--+ << "llvm_unreachable(\"Invalid command number.\");\n"; |
| 5291 |
-- |
| 5292 |
-- // Print out all the cases. |
| 5293 |
-- for (unsigned j = 0, e = Commands.size(); j != e; ++j) { |
| 5294 |
--@@ -536,6 +577,9 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName, |
| 5295 |
-- } |
| 5296 |
-- |
| 5297 |
-- StringTable.layout(); |
| 5298 |
--+#ifdef CAPSTONE |
| 5299 |
--+ O << "#ifndef CAPSTONE_DIET\n"; |
| 5300 |
--+#endif |
| 5301 |
-- O << " static const char AsmStrs" << AltName << "[] = {\n"; |
| 5302 |
-- StringTable.emit(O, printChar); |
| 5303 |
-- O << " };\n\n"; |
| 5304 |
--@@ -552,8 +596,10 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName, |
| 5305 |
-- } |
| 5306 |
-- |
| 5307 |
-- void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) { |
| 5308 |
--+#ifndef CAPSTONE |
| 5309 |
-- Record *AsmWriter = Target.getAsmWriter(); |
| 5310 |
-- StringRef ClassName = AsmWriter->getValueAsString("AsmWriterClassName"); |
| 5311 |
--+#endif |
| 5312 |
-- const auto &Registers = Target.getRegBank().getRegisters(); |
| 5313 |
-- const std::vector<Record*> &AltNameIndices = Target.getRegAltNameIndices(); |
| 5314 |
-- bool hasAltNames = AltNameIndices.size() > 1; |
| 5315 |
--@@ -563,12 +609,20 @@ void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) { |
| 5316 |
-- "\n\n/// getRegisterName - This method is automatically generated by tblgen\n" |
| 5317 |
-- "/// from the register set description. This returns the assembler name\n" |
| 5318 |
-- "/// for the specified register.\n" |
| 5319 |
--+#ifdef CAPSTONE |
| 5320 |
--+ "static const char *getRegisterName(unsigned RegNo)\n{\n"; |
| 5321 |
--+#else |
| 5322 |
-- "const char *" << Target.getName() << ClassName << "::"; |
| 5323 |
-- if (hasAltNames) |
| 5324 |
-- O << "\ngetRegisterName(unsigned RegNo, unsigned AltIdx) {\n"; |
| 5325 |
-- else |
| 5326 |
-- O << "getRegisterName(unsigned RegNo) {\n"; |
| 5327 |
--- O << " assert(RegNo && RegNo < " << (Registers.size()+1) |
| 5328 |
--+#endif |
| 5329 |
--+ O << " " |
| 5330 |
--+#ifdef CAPSTONE |
| 5331 |
--+ << "// " |
| 5332 |
--+#endif |
| 5333 |
--+ << "assert(RegNo && RegNo < " << (Registers.size()+1) |
| 5334 |
-- << " && \"Invalid register number!\");\n" |
| 5335 |
-- << "\n"; |
| 5336 |
-- |
| 5337 |
--@@ -595,10 +649,22 @@ void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) { |
| 5338 |
-- } |
| 5339 |
-- O << " }\n"; |
| 5340 |
-- } else { |
| 5341 |
--+#ifdef CAPSTONE |
| 5342 |
--+ O << " //int i;\n" |
| 5343 |
--+ << " //for (i = 0; i < sizeof(RegAsmOffset); i++)\n" |
| 5344 |
--+ << " // printf(\"%s = %u\\n\", AsmStrs+RegAsmOffset[i], i + 1);\n" |
| 5345 |
--+ << " //printf(\"*************************\\n\");\n" |
| 5346 |
--+#else |
| 5347 |
-- O << " assert (*(AsmStrs+RegAsmOffset[RegNo-1]) &&\n" |
| 5348 |
-- << " \"Invalid alt name index for register!\");\n" |
| 5349 |
--+#endif |
| 5350 |
-- << " return AsmStrs+RegAsmOffset[RegNo-1];\n"; |
| 5351 |
-- } |
| 5352 |
--+#ifdef CAPSTONE |
| 5353 |
--+ O << "#else\n" |
| 5354 |
--+ << " return NULL;\n" |
| 5355 |
--+ << "#endif\n"; |
| 5356 |
--+#endif |
| 5357 |
-- O << "}\n"; |
| 5358 |
-- } |
| 5359 |
-- |
| 5360 |
--@@ -1135,9 +1201,20 @@ AsmWriterEmitter::AsmWriterEmitter(RecordKeeper &R) : Records(R), Target(R) { |
| 5361 |
-- } |
| 5362 |
-- |
| 5363 |
-- void AsmWriterEmitter::run(raw_ostream &O) { |
| 5364 |
--+#ifdef CAPSTONE |
| 5365 |
--+ O << "/* Capstone Disassembly Engine */\n" |
| 5366 |
--+ "/* By Nguyen Anh Quynh <[email protected]>, 2013-2015 */\n" |
| 5367 |
--+ "\n" |
| 5368 |
--+ "#include <stdio.h>\t// debug\n" |
| 5369 |
--+ "#include <capstone/platform.h>\n" |
| 5370 |
--+ "\n" |
| 5371 |
--+ "\n"; |
| 5372 |
--+#endif |
| 5373 |
-- EmitPrintInstruction(O); |
| 5374 |
-- EmitGetRegisterName(O); |
| 5375 |
--+#ifndef CAPSTONE |
| 5376 |
-- EmitPrintAliasInstruction(O); |
| 5377 |
--+#endif |
| 5378 |
-- } |
| 5379 |
-- |
| 5380 |
-- namespace llvm { |
| 5381 |
--diff --git a/utils/TableGen/AsmWriterInst.cpp b/utils/TableGen/AsmWriterInst.cpp |
| 5382 |
--index 2c19e5d663d..6fa751e50df 100644 |
| 5383 |
----- a/utils/TableGen/AsmWriterInst.cpp |
| 5384 |
--+++ b/utils/TableGen/AsmWriterInst.cpp |
| 5385 |
--@@ -28,9 +28,13 @@ static bool isIdentChar(char C) { |
| 5386 |
-- |
| 5387 |
-- std::string AsmWriterOperand::getCode(bool PassSubtarget) const { |
| 5388 |
-- if (OperandType == isLiteralTextOperand) { |
| 5389 |
--+#ifdef CAPSTONE |
| 5390 |
--+ return "SStream_concat0(O, \"" + Str + "\");"; |
| 5391 |
--+#else |
| 5392 |
-- if (Str.size() == 1) |
| 5393 |
-- return "O << '" + Str + "';"; |
| 5394 |
-- return "O << \"" + Str + "\";"; |
| 5395 |
--+#endif |
| 5396 |
-- } |
| 5397 |
-- |
| 5398 |
-- if (OperandType == isLiteralStatementOperand) |
| 5399 |
---- |
| 5400 |
--2.19.1 |
| 5401 |
-- |
| 5402 |
-diff --git a/llvm/0006-capstone-generate-MappingInsn.inc.patch b/llvm/0006-capstone-generate-MappingInsn.inc.patch |
| 5403 |
-deleted file mode 100644 |
| 5404 |
-index 7ee22d787..000000000 |
| 5405 |
---- a/llvm/0006-capstone-generate-MappingInsn.inc.patch |
| 5406 |
-+++ /dev/null |
| 5407 |
-@@ -1,174 +0,0 @@ |
| 5408 |
--From 7a436110ef15c803dc8524af2fb5612bcacbb126 Mon Sep 17 00:00:00 2001 |
| 5409 |
--From: mephi42 <[email protected]> |
| 5410 |
--Date: Tue, 7 Aug 2018 20:55:32 +0200 |
| 5411 |
--Subject: [PATCH 6/7] capstone: generate *MappingInsn.inc |
| 5412 |
-- |
| 5413 |
----- |
| 5414 |
-- lib/Target/SystemZ/CMakeLists.txt | 1 + |
| 5415 |
-- utils/TableGen/InstrInfoEmitter.cpp | 95 +++++++++++++++++++++++++++++ |
| 5416 |
-- utils/TableGen/TableGen.cpp | 6 ++ |
| 5417 |
-- utils/TableGen/TableGenBackends.h | 1 + |
| 5418 |
-- 4 files changed, 103 insertions(+) |
| 5419 |
-- |
| 5420 |
--diff --git a/lib/Target/SystemZ/CMakeLists.txt b/lib/Target/SystemZ/CMakeLists.txt |
| 5421 |
--index f83b4242fb4..4b5d9c4a3b2 100644 |
| 5422 |
----- a/lib/Target/SystemZ/CMakeLists.txt |
| 5423 |
--+++ b/lib/Target/SystemZ/CMakeLists.txt |
| 5424 |
--@@ -6,6 +6,7 @@ tablegen(LLVM SystemZGenCallingConv.inc -gen-callingconv) |
| 5425 |
-- tablegen(LLVM SystemZGenDAGISel.inc -gen-dag-isel) |
| 5426 |
-- tablegen(LLVM SystemZGenDisassemblerTables.inc -gen-disassembler) |
| 5427 |
-- tablegen(LLVM SystemZGenInstrInfo.inc -gen-instr-info) |
| 5428 |
--+tablegen(LLVM SystemZMappingInsn.inc -mapping-insn) |
| 5429 |
-- tablegen(LLVM SystemZGenMCCodeEmitter.inc -gen-emitter) |
| 5430 |
-- tablegen(LLVM SystemZGenRegisterInfo.inc -gen-register-info) |
| 5431 |
-- tablegen(LLVM SystemZGenSubtargetInfo.inc -gen-subtarget) |
| 5432 |
--diff --git a/utils/TableGen/InstrInfoEmitter.cpp b/utils/TableGen/InstrInfoEmitter.cpp |
| 5433 |
--index 2f3a2729262..14ab1ea8a72 100644 |
| 5434 |
----- a/utils/TableGen/InstrInfoEmitter.cpp |
| 5435 |
--+++ b/utils/TableGen/InstrInfoEmitter.cpp |
| 5436 |
--@@ -744,4 +744,99 @@ void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) { |
| 5437 |
-- #endif |
| 5438 |
-- } |
| 5439 |
-- |
| 5440 |
--+#ifdef CAPSTONE |
| 5441 |
--+std::string GetPublicName(const CodeGenInstruction *Inst) { |
| 5442 |
--+ std::string Name = Inst->TheDef->getName(); |
| 5443 |
--+ // Apply backward compatibility fixups. |
| 5444 |
--+ // BRNLE -> BNLER. |
| 5445 |
--+ if (Name.length() >= 5 && Name.substr(0, 5) == "BRAsm") { |
| 5446 |
--+ Name = "B" + Name.substr(5, Name.length() - 5) + "R"; |
| 5447 |
--+ } |
| 5448 |
--+ // SSKEOpt -> SSKE. |
| 5449 |
--+ while (Name.length() >= 3 && Name.substr(Name.length() - 3, 3) == "Opt") { |
| 5450 |
--+ Name = Name.substr(0, Name.length() - 3); |
| 5451 |
--+ } |
| 5452 |
--+ // BRCLAsm -> BRCL. |
| 5453 |
--+ while (true) { |
| 5454 |
--+ size_t pos = Name.find("Asm"); |
| 5455 |
--+ if (pos == std::string::npos) { |
| 5456 |
--+ break; |
| 5457 |
--+ } |
| 5458 |
--+ Name = Name.substr(0, pos) + Name.substr(pos + 3); |
| 5459 |
--+ } |
| 5460 |
--+ // CPSDRxx -> CPSDR. |
| 5461 |
--+ if (Name.length() >= 2) { |
| 5462 |
--+ std::string Suffix2 = Name.substr(Name.length() - 2, 2); |
| 5463 |
--+ if (Suffix2 == "dd" || Suffix2 == "ds" || |
| 5464 |
--+ Suffix2 == "sd" || Suffix2 == "ss") { |
| 5465 |
--+ Name = Name.substr(0, Name.length() - 2); |
| 5466 |
--+ } |
| 5467 |
--+ } |
| 5468 |
--+ return "SYSZ_INS_" + Name; |
| 5469 |
--+} |
| 5470 |
--+ |
| 5471 |
--+std::string GetRegisterName(Record *Reg) { |
| 5472 |
--+ std::string Name = Reg->getName(); |
| 5473 |
--+ for (char& c : Name) { |
| 5474 |
--+ c = toupper(c); |
| 5475 |
--+ } |
| 5476 |
--+ // R0L, R0D -> R0. |
| 5477 |
--+ if (Name.length() >= 3 && |
| 5478 |
--+ Name[Name.length() - 3] == 'R' && |
| 5479 |
--+ (Name[Name.length() - 1] == 'L' || |
| 5480 |
--+ Name[Name.length() - 1] == 'D')) { |
| 5481 |
--+ Name = Name.substr(0, Name.length() - 3) + Name[Name.length() - 2]; |
| 5482 |
--+ } |
| 5483 |
--+ return "SYSZ_REG_" + Name; |
| 5484 |
--+} |
| 5485 |
--+ |
| 5486 |
--+std::string GetGroupName(Record *Pred) { |
| 5487 |
--+ std::string Name = Pred->getName(); |
| 5488 |
--+ for (char& c : Name) { |
| 5489 |
--+ c = toupper(c); |
| 5490 |
--+ } |
| 5491 |
--+ if (Name.length() >= 7 && Name.substr(0, 7) == "FEATURE") { |
| 5492 |
--+ Name = Name.substr(7); |
| 5493 |
--+ } |
| 5494 |
--+ return "SYSZ_GRP_" + Name; |
| 5495 |
--+} |
| 5496 |
--+ |
| 5497 |
--+void EmitMappingInsn(RecordKeeper &RK, raw_ostream &OS) { |
| 5498 |
--+ OS << "// This is auto-gen data for Capstone engine (www.capstone-engine.org)\n" |
| 5499 |
--+ "// By Nguyen Anh Quynh <[email protected]>\n" |
| 5500 |
--+ "\n"; |
| 5501 |
--+ CodeGenTarget Target(RK); |
| 5502 |
--+ for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) { |
| 5503 |
--+ if (Inst->TheDef->getValueAsBit("isPseudo") || |
| 5504 |
--+ Inst->TheDef->getValueAsBit("isCodeGenOnly")) { |
| 5505 |
--+ continue; |
| 5506 |
--+ } |
| 5507 |
--+ OS << "{\n" |
| 5508 |
--+ << "\t" << Target.getName() << "_" << Inst->TheDef->getName() << ", " |
| 5509 |
--+ << GetPublicName(Inst) << ",\n" |
| 5510 |
--+ << "#ifndef CAPSTONE_DIET\n" |
| 5511 |
--+ << "\t{ "; |
| 5512 |
--+ for (Record *Use : Inst->TheDef->getValueAsListOfDefs("Uses")) { |
| 5513 |
--+ OS << GetRegisterName(Use) << ", "; |
| 5514 |
--+ } |
| 5515 |
--+ OS << "0 }, { "; |
| 5516 |
--+ for (Record *Def : Inst->TheDef->getValueAsListOfDefs("Defs")) { |
| 5517 |
--+ OS << GetRegisterName(Def) << ", "; |
| 5518 |
--+ } |
| 5519 |
--+ OS << "0 }, { "; |
| 5520 |
--+ ListInit *Predicates = Inst->TheDef->getValueAsListInit("Predicates"); |
| 5521 |
--+ for (unsigned i = 0; i < Predicates->size(); ++i) { |
| 5522 |
--+ OS << GetGroupName(Predicates->getElementAsRecord(i)) << ", "; |
| 5523 |
--+ } |
| 5524 |
--+ OS << "0 }, " |
| 5525 |
--+ << Inst->TheDef->getValueAsBit("isBranch") |
| 5526 |
--+ << ", " |
| 5527 |
--+ << Inst->TheDef->getValueAsBit("isIndirectBranch") |
| 5528 |
--+ << "\n" |
| 5529 |
--+ << "#endif\n" |
| 5530 |
--+ << "},\n"; |
| 5531 |
--+ } |
| 5532 |
--+} |
| 5533 |
--+#endif |
| 5534 |
--+ |
| 5535 |
-- } // end llvm namespace |
| 5536 |
--diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp |
| 5537 |
--index cf1404d8769..bbb4e860536 100644 |
| 5538 |
----- a/utils/TableGen/TableGen.cpp |
| 5539 |
--+++ b/utils/TableGen/TableGen.cpp |
| 5540 |
--@@ -27,6 +27,7 @@ enum ActionType { |
| 5541 |
-- GenEmitter, |
| 5542 |
-- GenRegisterInfo, |
| 5543 |
-- GenInstrInfo, |
| 5544 |
--+ MappingInsn, |
| 5545 |
-- GenInstrDocs, |
| 5546 |
-- GenAsmWriter, |
| 5547 |
-- GenAsmMatcher, |
| 5548 |
--@@ -65,6 +66,8 @@ namespace { |
| 5549 |
-- "Generate registers and register classes info"), |
| 5550 |
-- clEnumValN(GenInstrInfo, "gen-instr-info", |
| 5551 |
-- "Generate instruction descriptions"), |
| 5552 |
--+ clEnumValN(MappingInsn, "mapping-insn", |
| 5553 |
--+ ""), |
| 5554 |
-- clEnumValN(GenInstrDocs, "gen-instr-docs", |
| 5555 |
-- "Generate instruction documentation"), |
| 5556 |
-- clEnumValN(GenCallingConv, "gen-callingconv", |
| 5557 |
--@@ -135,6 +138,9 @@ bool LLVMTableGenMain(raw_ostream &OS, RecordKeeper &Records) { |
| 5558 |
-- case GenInstrInfo: |
| 5559 |
-- EmitInstrInfo(Records, OS); |
| 5560 |
-- break; |
| 5561 |
--+ case MappingInsn: |
| 5562 |
--+ EmitMappingInsn(Records, OS); |
| 5563 |
--+ break; |
| 5564 |
-- case GenInstrDocs: |
| 5565 |
-- EmitInstrDocs(Records, OS); |
| 5566 |
-- break; |
| 5567 |
--diff --git a/utils/TableGen/TableGenBackends.h b/utils/TableGen/TableGenBackends.h |
| 5568 |
--index 1329a6d833f..a41e46b1db0 100644 |
| 5569 |
----- a/utils/TableGen/TableGenBackends.h |
| 5570 |
--+++ b/utils/TableGen/TableGenBackends.h |
| 5571 |
--@@ -75,6 +75,7 @@ void EmitDFAPacketizer(RecordKeeper &RK, raw_ostream &OS); |
| 5572 |
-- void EmitDisassembler(RecordKeeper &RK, raw_ostream &OS); |
| 5573 |
-- void EmitFastISel(RecordKeeper &RK, raw_ostream &OS); |
| 5574 |
-- void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS); |
| 5575 |
--+void EmitMappingInsn(RecordKeeper &RK, raw_ostream &OS); |
| 5576 |
-- void EmitInstrDocs(RecordKeeper &RK, raw_ostream &OS); |
| 5577 |
-- void EmitPseudoLowering(RecordKeeper &RK, raw_ostream &OS); |
| 5578 |
-- void EmitCompressInst(RecordKeeper &RK, raw_ostream &OS); |
| 5579 |
---- |
| 5580 |
--2.19.1 |
| 5581 |
-- |
| 5582 |
-diff --git a/llvm/0007-capstone-generate-GenInsnNameMaps.inc.patch b/llvm/0007-capstone-generate-GenInsnNameMaps.inc.patch |
| 5583 |
-deleted file mode 100644 |
| 5584 |
-index 019540d65..000000000 |
| 5585 |
---- a/llvm/0007-capstone-generate-GenInsnNameMaps.inc.patch |
| 5586 |
-+++ /dev/null |
| 5587 |
-@@ -1,110 +0,0 @@ |
| 5588 |
--From b42f9f2014ec49a22077b6610863d9341a74e142 Mon Sep 17 00:00:00 2001 |
| 5589 |
--From: mephi42 <[email protected]> |
| 5590 |
--Date: Fri, 17 Aug 2018 11:07:39 +0200 |
| 5591 |
--Subject: [PATCH 7/7] capstone: generate *GenInsnNameMaps.inc |
| 5592 |
-- |
| 5593 |
----- |
| 5594 |
-- lib/Target/SystemZ/CMakeLists.txt | 1 + |
| 5595 |
-- utils/TableGen/InstrInfoEmitter.cpp | 29 +++++++++++++++++++++++++++++ |
| 5596 |
-- utils/TableGen/TableGen.cpp | 6 ++++++ |
| 5597 |
-- utils/TableGen/TableGenBackends.h | 1 + |
| 5598 |
-- 4 files changed, 37 insertions(+) |
| 5599 |
-- |
| 5600 |
--diff --git a/lib/Target/SystemZ/CMakeLists.txt b/lib/Target/SystemZ/CMakeLists.txt |
| 5601 |
--index 4b5d9c4a3b2..2c64e0a94b8 100644 |
| 5602 |
----- a/lib/Target/SystemZ/CMakeLists.txt |
| 5603 |
--+++ b/lib/Target/SystemZ/CMakeLists.txt |
| 5604 |
--@@ -7,6 +7,7 @@ tablegen(LLVM SystemZGenDAGISel.inc -gen-dag-isel) |
| 5605 |
-- tablegen(LLVM SystemZGenDisassemblerTables.inc -gen-disassembler) |
| 5606 |
-- tablegen(LLVM SystemZGenInstrInfo.inc -gen-instr-info) |
| 5607 |
-- tablegen(LLVM SystemZMappingInsn.inc -mapping-insn) |
| 5608 |
--+tablegen(LLVM SystemZGenInsnNameMaps.inc -gen-insn-name-maps) |
| 5609 |
-- tablegen(LLVM SystemZGenMCCodeEmitter.inc -gen-emitter) |
| 5610 |
-- tablegen(LLVM SystemZGenRegisterInfo.inc -gen-register-info) |
| 5611 |
-- tablegen(LLVM SystemZGenSubtargetInfo.inc -gen-subtarget) |
| 5612 |
--diff --git a/utils/TableGen/InstrInfoEmitter.cpp b/utils/TableGen/InstrInfoEmitter.cpp |
| 5613 |
--index 14ab1ea8a72..ccf8170ca62 100644 |
| 5614 |
----- a/utils/TableGen/InstrInfoEmitter.cpp |
| 5615 |
--+++ b/utils/TableGen/InstrInfoEmitter.cpp |
| 5616 |
--@@ -837,6 +837,35 @@ void EmitMappingInsn(RecordKeeper &RK, raw_ostream &OS) { |
| 5617 |
-- << "},\n"; |
| 5618 |
-- } |
| 5619 |
-- } |
| 5620 |
--+ |
| 5621 |
--+std::string GetMnemonic(const CodeGenInstruction *Inst) { |
| 5622 |
--+ std::string Mnemonic = Inst->AsmString; |
| 5623 |
--+ |
| 5624 |
--+ for (size_t i = 0; i < Mnemonic.length(); i++) { |
| 5625 |
--+ if (Mnemonic[i] == '\t') { |
| 5626 |
--+ return Mnemonic.substr(0, i); |
| 5627 |
--+ } |
| 5628 |
--+ } |
| 5629 |
--+ return Mnemonic; |
| 5630 |
--+} |
| 5631 |
--+ |
| 5632 |
--+void EmitInsnNameMaps(RecordKeeper &RK, raw_ostream &OS) { |
| 5633 |
--+ OS << "// This is auto-gen data for Capstone engine (www.capstone-engine.org)\n" |
| 5634 |
--+ "// By Nguyen Anh Quynh <[email protected]>\n" |
| 5635 |
--+ "\n"; |
| 5636 |
--+ CodeGenTarget Target(RK); |
| 5637 |
--+ std::map<std::string, std::string> M; |
| 5638 |
--+ for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) { |
| 5639 |
--+ if (Inst->TheDef->getValueAsBit("isPseudo") || |
| 5640 |
--+ Inst->TheDef->getValueAsBit("isCodeGenOnly")) { |
| 5641 |
--+ continue; |
| 5642 |
--+ } |
| 5643 |
--+ M[GetPublicName(Inst)] = GetMnemonic(Inst); |
| 5644 |
--+ } |
| 5645 |
--+ for (auto &P : M) { |
| 5646 |
--+ OS << "\t{ " << P.first << ", \"" << P.second << "\" },\n"; |
| 5647 |
--+ } |
| 5648 |
--+} |
| 5649 |
-- #endif |
| 5650 |
-- |
| 5651 |
-- } // end llvm namespace |
| 5652 |
--diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp |
| 5653 |
--index bbb4e860536..27c6603de5a 100644 |
| 5654 |
----- a/utils/TableGen/TableGen.cpp |
| 5655 |
--+++ b/utils/TableGen/TableGen.cpp |
| 5656 |
--@@ -28,6 +28,7 @@ enum ActionType { |
| 5657 |
-- GenRegisterInfo, |
| 5658 |
-- GenInstrInfo, |
| 5659 |
-- MappingInsn, |
| 5660 |
--+ GenInsnNameMaps, |
| 5661 |
-- GenInstrDocs, |
| 5662 |
-- GenAsmWriter, |
| 5663 |
-- GenAsmMatcher, |
| 5664 |
--@@ -68,6 +69,8 @@ namespace { |
| 5665 |
-- "Generate instruction descriptions"), |
| 5666 |
-- clEnumValN(MappingInsn, "mapping-insn", |
| 5667 |
-- ""), |
| 5668 |
--+ clEnumValN(GenInsnNameMaps, "gen-insn-name-maps", |
| 5669 |
--+ ""), |
| 5670 |
-- clEnumValN(GenInstrDocs, "gen-instr-docs", |
| 5671 |
-- "Generate instruction documentation"), |
| 5672 |
-- clEnumValN(GenCallingConv, "gen-callingconv", |
| 5673 |
--@@ -141,6 +144,9 @@ bool LLVMTableGenMain(raw_ostream &OS, RecordKeeper &Records) { |
| 5674 |
-- case MappingInsn: |
| 5675 |
-- EmitMappingInsn(Records, OS); |
| 5676 |
-- break; |
| 5677 |
--+ case GenInsnNameMaps: |
| 5678 |
--+ EmitInsnNameMaps(Records, OS); |
| 5679 |
--+ break; |
| 5680 |
-- case GenInstrDocs: |
| 5681 |
-- EmitInstrDocs(Records, OS); |
| 5682 |
-- break; |
| 5683 |
--diff --git a/utils/TableGen/TableGenBackends.h b/utils/TableGen/TableGenBackends.h |
| 5684 |
--index a41e46b1db0..5656e5be849 100644 |
| 5685 |
----- a/utils/TableGen/TableGenBackends.h |
| 5686 |
--+++ b/utils/TableGen/TableGenBackends.h |
| 5687 |
--@@ -76,6 +76,7 @@ void EmitDisassembler(RecordKeeper &RK, raw_ostream &OS); |
| 5688 |
-- void EmitFastISel(RecordKeeper &RK, raw_ostream &OS); |
| 5689 |
-- void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS); |
| 5690 |
-- void EmitMappingInsn(RecordKeeper &RK, raw_ostream &OS); |
| 5691 |
--+void EmitInsnNameMaps(RecordKeeper &RK, raw_ostream &OS); |
| 5692 |
-- void EmitInstrDocs(RecordKeeper &RK, raw_ostream &OS); |
| 5693 |
-- void EmitPseudoLowering(RecordKeeper &RK, raw_ostream &OS); |
| 5694 |
-- void EmitCompressInst(RecordKeeper &RK, raw_ostream &OS); |
| 5695 |
---- |
| 5696 |
--2.19.1 |
| 5697 |
-- |
| 5698 |
--- |
| 5699 |
-2.20.1 |
| 5700 |
- |
| 5701 |
-- |
| 5702 |
2.20.1 |
| 5703 |
|