asmjit 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/Rakefile +5 -3
  4. data/asmjit.gemspec +1 -3
  5. data/ext/asmjit/asmjit/.editorconfig +10 -0
  6. data/ext/asmjit/asmjit/.github/FUNDING.yml +1 -0
  7. data/ext/asmjit/asmjit/.github/workflows/build-config.json +47 -0
  8. data/ext/asmjit/asmjit/.github/workflows/build.yml +156 -0
  9. data/ext/asmjit/asmjit/.gitignore +6 -0
  10. data/ext/asmjit/asmjit/CMakeLists.txt +611 -0
  11. data/ext/asmjit/asmjit/LICENSE.md +17 -0
  12. data/ext/asmjit/asmjit/README.md +69 -0
  13. data/ext/asmjit/asmjit/src/asmjit/a64.h +62 -0
  14. data/ext/asmjit/asmjit/src/asmjit/arm/a64archtraits_p.h +81 -0
  15. data/ext/asmjit/asmjit/src/asmjit/arm/a64assembler.cpp +5115 -0
  16. data/ext/asmjit/asmjit/src/asmjit/arm/a64assembler.h +72 -0
  17. data/ext/asmjit/asmjit/src/asmjit/arm/a64builder.cpp +51 -0
  18. data/ext/asmjit/asmjit/src/asmjit/arm/a64builder.h +57 -0
  19. data/ext/asmjit/asmjit/src/asmjit/arm/a64compiler.cpp +60 -0
  20. data/ext/asmjit/asmjit/src/asmjit/arm/a64compiler.h +247 -0
  21. data/ext/asmjit/asmjit/src/asmjit/arm/a64emithelper.cpp +464 -0
  22. data/ext/asmjit/asmjit/src/asmjit/arm/a64emithelper_p.h +50 -0
  23. data/ext/asmjit/asmjit/src/asmjit/arm/a64emitter.h +1228 -0
  24. data/ext/asmjit/asmjit/src/asmjit/arm/a64formatter.cpp +298 -0
  25. data/ext/asmjit/asmjit/src/asmjit/arm/a64formatter_p.h +59 -0
  26. data/ext/asmjit/asmjit/src/asmjit/arm/a64func.cpp +189 -0
  27. data/ext/asmjit/asmjit/src/asmjit/arm/a64func_p.h +33 -0
  28. data/ext/asmjit/asmjit/src/asmjit/arm/a64globals.h +1894 -0
  29. data/ext/asmjit/asmjit/src/asmjit/arm/a64instapi.cpp +278 -0
  30. data/ext/asmjit/asmjit/src/asmjit/arm/a64instapi_p.h +41 -0
  31. data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb.cpp +1957 -0
  32. data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb.h +74 -0
  33. data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb_p.h +876 -0
  34. data/ext/asmjit/asmjit/src/asmjit/arm/a64operand.cpp +85 -0
  35. data/ext/asmjit/asmjit/src/asmjit/arm/a64operand.h +312 -0
  36. data/ext/asmjit/asmjit/src/asmjit/arm/a64rapass.cpp +852 -0
  37. data/ext/asmjit/asmjit/src/asmjit/arm/a64rapass_p.h +105 -0
  38. data/ext/asmjit/asmjit/src/asmjit/arm/a64utils.h +179 -0
  39. data/ext/asmjit/asmjit/src/asmjit/arm/armformatter.cpp +143 -0
  40. data/ext/asmjit/asmjit/src/asmjit/arm/armformatter_p.h +44 -0
  41. data/ext/asmjit/asmjit/src/asmjit/arm/armglobals.h +21 -0
  42. data/ext/asmjit/asmjit/src/asmjit/arm/armoperand.h +621 -0
  43. data/ext/asmjit/asmjit/src/asmjit/arm.h +62 -0
  44. data/ext/asmjit/asmjit/src/asmjit/asmjit-scope-begin.h +17 -0
  45. data/ext/asmjit/asmjit/src/asmjit/asmjit-scope-end.h +9 -0
  46. data/ext/asmjit/asmjit/src/asmjit/asmjit.h +33 -0
  47. data/ext/asmjit/asmjit/src/asmjit/core/api-build_p.h +55 -0
  48. data/ext/asmjit/asmjit/src/asmjit/core/api-config.h +613 -0
  49. data/ext/asmjit/asmjit/src/asmjit/core/archcommons.h +229 -0
  50. data/ext/asmjit/asmjit/src/asmjit/core/archtraits.cpp +160 -0
  51. data/ext/asmjit/asmjit/src/asmjit/core/archtraits.h +290 -0
  52. data/ext/asmjit/asmjit/src/asmjit/core/assembler.cpp +406 -0
  53. data/ext/asmjit/asmjit/src/asmjit/core/assembler.h +129 -0
  54. data/ext/asmjit/asmjit/src/asmjit/core/builder.cpp +889 -0
  55. data/ext/asmjit/asmjit/src/asmjit/core/builder.h +1391 -0
  56. data/ext/asmjit/asmjit/src/asmjit/core/codebuffer.h +113 -0
  57. data/ext/asmjit/asmjit/src/asmjit/core/codeholder.cpp +1149 -0
  58. data/ext/asmjit/asmjit/src/asmjit/core/codeholder.h +1035 -0
  59. data/ext/asmjit/asmjit/src/asmjit/core/codewriter.cpp +175 -0
  60. data/ext/asmjit/asmjit/src/asmjit/core/codewriter_p.h +179 -0
  61. data/ext/asmjit/asmjit/src/asmjit/core/compiler.cpp +582 -0
  62. data/ext/asmjit/asmjit/src/asmjit/core/compiler.h +737 -0
  63. data/ext/asmjit/asmjit/src/asmjit/core/compilerdefs.h +173 -0
  64. data/ext/asmjit/asmjit/src/asmjit/core/constpool.cpp +363 -0
  65. data/ext/asmjit/asmjit/src/asmjit/core/constpool.h +250 -0
  66. data/ext/asmjit/asmjit/src/asmjit/core/cpuinfo.cpp +1162 -0
  67. data/ext/asmjit/asmjit/src/asmjit/core/cpuinfo.h +813 -0
  68. data/ext/asmjit/asmjit/src/asmjit/core/emithelper.cpp +323 -0
  69. data/ext/asmjit/asmjit/src/asmjit/core/emithelper_p.h +58 -0
  70. data/ext/asmjit/asmjit/src/asmjit/core/emitter.cpp +333 -0
  71. data/ext/asmjit/asmjit/src/asmjit/core/emitter.h +741 -0
  72. data/ext/asmjit/asmjit/src/asmjit/core/emitterutils.cpp +129 -0
  73. data/ext/asmjit/asmjit/src/asmjit/core/emitterutils_p.h +89 -0
  74. data/ext/asmjit/asmjit/src/asmjit/core/environment.cpp +46 -0
  75. data/ext/asmjit/asmjit/src/asmjit/core/environment.h +508 -0
  76. data/ext/asmjit/asmjit/src/asmjit/core/errorhandler.cpp +14 -0
  77. data/ext/asmjit/asmjit/src/asmjit/core/errorhandler.h +228 -0
  78. data/ext/asmjit/asmjit/src/asmjit/core/formatter.cpp +584 -0
  79. data/ext/asmjit/asmjit/src/asmjit/core/formatter.h +247 -0
  80. data/ext/asmjit/asmjit/src/asmjit/core/formatter_p.h +34 -0
  81. data/ext/asmjit/asmjit/src/asmjit/core/func.cpp +286 -0
  82. data/ext/asmjit/asmjit/src/asmjit/core/func.h +1445 -0
  83. data/ext/asmjit/asmjit/src/asmjit/core/funcargscontext.cpp +293 -0
  84. data/ext/asmjit/asmjit/src/asmjit/core/funcargscontext_p.h +199 -0
  85. data/ext/asmjit/asmjit/src/asmjit/core/globals.cpp +133 -0
  86. data/ext/asmjit/asmjit/src/asmjit/core/globals.h +393 -0
  87. data/ext/asmjit/asmjit/src/asmjit/core/inst.cpp +113 -0
  88. data/ext/asmjit/asmjit/src/asmjit/core/inst.h +772 -0
  89. data/ext/asmjit/asmjit/src/asmjit/core/jitallocator.cpp +1242 -0
  90. data/ext/asmjit/asmjit/src/asmjit/core/jitallocator.h +261 -0
  91. data/ext/asmjit/asmjit/src/asmjit/core/jitruntime.cpp +80 -0
  92. data/ext/asmjit/asmjit/src/asmjit/core/jitruntime.h +89 -0
  93. data/ext/asmjit/asmjit/src/asmjit/core/logger.cpp +69 -0
  94. data/ext/asmjit/asmjit/src/asmjit/core/logger.h +198 -0
  95. data/ext/asmjit/asmjit/src/asmjit/core/misc_p.h +33 -0
  96. data/ext/asmjit/asmjit/src/asmjit/core/operand.cpp +132 -0
  97. data/ext/asmjit/asmjit/src/asmjit/core/operand.h +1611 -0
  98. data/ext/asmjit/asmjit/src/asmjit/core/osutils.cpp +84 -0
  99. data/ext/asmjit/asmjit/src/asmjit/core/osutils.h +61 -0
  100. data/ext/asmjit/asmjit/src/asmjit/core/osutils_p.h +68 -0
  101. data/ext/asmjit/asmjit/src/asmjit/core/raassignment_p.h +418 -0
  102. data/ext/asmjit/asmjit/src/asmjit/core/rabuilders_p.h +612 -0
  103. data/ext/asmjit/asmjit/src/asmjit/core/radefs_p.h +1204 -0
  104. data/ext/asmjit/asmjit/src/asmjit/core/ralocal.cpp +1166 -0
  105. data/ext/asmjit/asmjit/src/asmjit/core/ralocal_p.h +254 -0
  106. data/ext/asmjit/asmjit/src/asmjit/core/rapass.cpp +1969 -0
  107. data/ext/asmjit/asmjit/src/asmjit/core/rapass_p.h +1183 -0
  108. data/ext/asmjit/asmjit/src/asmjit/core/rastack.cpp +184 -0
  109. data/ext/asmjit/asmjit/src/asmjit/core/rastack_p.h +171 -0
  110. data/ext/asmjit/asmjit/src/asmjit/core/string.cpp +559 -0
  111. data/ext/asmjit/asmjit/src/asmjit/core/string.h +372 -0
  112. data/ext/asmjit/asmjit/src/asmjit/core/support.cpp +494 -0
  113. data/ext/asmjit/asmjit/src/asmjit/core/support.h +1773 -0
  114. data/ext/asmjit/asmjit/src/asmjit/core/target.cpp +14 -0
  115. data/ext/asmjit/asmjit/src/asmjit/core/target.h +53 -0
  116. data/ext/asmjit/asmjit/src/asmjit/core/type.cpp +74 -0
  117. data/ext/asmjit/asmjit/src/asmjit/core/type.h +419 -0
  118. data/ext/asmjit/asmjit/src/asmjit/core/virtmem.cpp +722 -0
  119. data/ext/asmjit/asmjit/src/asmjit/core/virtmem.h +242 -0
  120. data/ext/asmjit/asmjit/src/asmjit/core/zone.cpp +353 -0
  121. data/ext/asmjit/asmjit/src/asmjit/core/zone.h +615 -0
  122. data/ext/asmjit/asmjit/src/asmjit/core/zonehash.cpp +309 -0
  123. data/ext/asmjit/asmjit/src/asmjit/core/zonehash.h +186 -0
  124. data/ext/asmjit/asmjit/src/asmjit/core/zonelist.cpp +163 -0
  125. data/ext/asmjit/asmjit/src/asmjit/core/zonelist.h +209 -0
  126. data/ext/asmjit/asmjit/src/asmjit/core/zonestack.cpp +176 -0
  127. data/ext/asmjit/asmjit/src/asmjit/core/zonestack.h +239 -0
  128. data/ext/asmjit/asmjit/src/asmjit/core/zonestring.h +120 -0
  129. data/ext/asmjit/asmjit/src/asmjit/core/zonetree.cpp +99 -0
  130. data/ext/asmjit/asmjit/src/asmjit/core/zonetree.h +380 -0
  131. data/ext/asmjit/asmjit/src/asmjit/core/zonevector.cpp +356 -0
  132. data/ext/asmjit/asmjit/src/asmjit/core/zonevector.h +690 -0
  133. data/ext/asmjit/asmjit/src/asmjit/core.h +1861 -0
  134. data/ext/asmjit/asmjit/src/asmjit/x86/x86archtraits_p.h +148 -0
  135. data/ext/asmjit/asmjit/src/asmjit/x86/x86assembler.cpp +5110 -0
  136. data/ext/asmjit/asmjit/src/asmjit/x86/x86assembler.h +685 -0
  137. data/ext/asmjit/asmjit/src/asmjit/x86/x86builder.cpp +52 -0
  138. data/ext/asmjit/asmjit/src/asmjit/x86/x86builder.h +351 -0
  139. data/ext/asmjit/asmjit/src/asmjit/x86/x86compiler.cpp +61 -0
  140. data/ext/asmjit/asmjit/src/asmjit/x86/x86compiler.h +721 -0
  141. data/ext/asmjit/asmjit/src/asmjit/x86/x86emithelper.cpp +619 -0
  142. data/ext/asmjit/asmjit/src/asmjit/x86/x86emithelper_p.h +60 -0
  143. data/ext/asmjit/asmjit/src/asmjit/x86/x86emitter.h +4315 -0
  144. data/ext/asmjit/asmjit/src/asmjit/x86/x86formatter.cpp +944 -0
  145. data/ext/asmjit/asmjit/src/asmjit/x86/x86formatter_p.h +58 -0
  146. data/ext/asmjit/asmjit/src/asmjit/x86/x86func.cpp +503 -0
  147. data/ext/asmjit/asmjit/src/asmjit/x86/x86func_p.h +33 -0
  148. data/ext/asmjit/asmjit/src/asmjit/x86/x86globals.h +2169 -0
  149. data/ext/asmjit/asmjit/src/asmjit/x86/x86instapi.cpp +1732 -0
  150. data/ext/asmjit/asmjit/src/asmjit/x86/x86instapi_p.h +41 -0
  151. data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb.cpp +4427 -0
  152. data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb.h +563 -0
  153. data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb_p.h +311 -0
  154. data/ext/asmjit/asmjit/src/asmjit/x86/x86opcode_p.h +436 -0
  155. data/ext/asmjit/asmjit/src/asmjit/x86/x86operand.cpp +231 -0
  156. data/ext/asmjit/asmjit/src/asmjit/x86/x86operand.h +1085 -0
  157. data/ext/asmjit/asmjit/src/asmjit/x86/x86rapass.cpp +1509 -0
  158. data/ext/asmjit/asmjit/src/asmjit/x86/x86rapass_p.h +94 -0
  159. data/ext/asmjit/asmjit/src/asmjit/x86.h +93 -0
  160. data/ext/asmjit/asmjit/src/asmjit.natvis +245 -0
  161. data/ext/asmjit/asmjit/test/asmjit_test_assembler.cpp +84 -0
  162. data/ext/asmjit/asmjit/test/asmjit_test_assembler.h +85 -0
  163. data/ext/asmjit/asmjit/test/asmjit_test_assembler_a64.cpp +4006 -0
  164. data/ext/asmjit/asmjit/test/asmjit_test_assembler_x64.cpp +17833 -0
  165. data/ext/asmjit/asmjit/test/asmjit_test_assembler_x86.cpp +8300 -0
  166. data/ext/asmjit/asmjit/test/asmjit_test_compiler.cpp +253 -0
  167. data/ext/asmjit/asmjit/test/asmjit_test_compiler.h +73 -0
  168. data/ext/asmjit/asmjit/test/asmjit_test_compiler_a64.cpp +690 -0
  169. data/ext/asmjit/asmjit/test/asmjit_test_compiler_x86.cpp +4317 -0
  170. data/ext/asmjit/asmjit/test/asmjit_test_emitters.cpp +197 -0
  171. data/ext/asmjit/asmjit/test/asmjit_test_instinfo.cpp +181 -0
  172. data/ext/asmjit/asmjit/test/asmjit_test_misc.h +257 -0
  173. data/ext/asmjit/asmjit/test/asmjit_test_perf.cpp +62 -0
  174. data/ext/asmjit/asmjit/test/asmjit_test_perf.h +61 -0
  175. data/ext/asmjit/asmjit/test/asmjit_test_perf_a64.cpp +699 -0
  176. data/ext/asmjit/asmjit/test/asmjit_test_perf_x86.cpp +5032 -0
  177. data/ext/asmjit/asmjit/test/asmjit_test_unit.cpp +172 -0
  178. data/ext/asmjit/asmjit/test/asmjit_test_x86_sections.cpp +172 -0
  179. data/ext/asmjit/asmjit/test/asmjitutils.h +38 -0
  180. data/ext/asmjit/asmjit/test/broken.cpp +312 -0
  181. data/ext/asmjit/asmjit/test/broken.h +148 -0
  182. data/ext/asmjit/asmjit/test/cmdline.h +61 -0
  183. data/ext/asmjit/asmjit/test/performancetimer.h +41 -0
  184. data/ext/asmjit/asmjit/tools/configure-makefiles.sh +13 -0
  185. data/ext/asmjit/asmjit/tools/configure-ninja.sh +13 -0
  186. data/ext/asmjit/asmjit/tools/configure-sanitizers.sh +13 -0
  187. data/ext/asmjit/asmjit/tools/configure-vs2019-x64.bat +2 -0
  188. data/ext/asmjit/asmjit/tools/configure-vs2019-x86.bat +2 -0
  189. data/ext/asmjit/asmjit/tools/configure-vs2022-x64.bat +2 -0
  190. data/ext/asmjit/asmjit/tools/configure-vs2022-x86.bat +2 -0
  191. data/ext/asmjit/asmjit/tools/configure-xcode.sh +8 -0
  192. data/ext/asmjit/asmjit/tools/enumgen.js +417 -0
  193. data/ext/asmjit/asmjit/tools/enumgen.sh +3 -0
  194. data/ext/asmjit/asmjit/tools/tablegen-arm.js +365 -0
  195. data/ext/asmjit/asmjit/tools/tablegen-arm.sh +3 -0
  196. data/ext/asmjit/asmjit/tools/tablegen-x86.js +2638 -0
  197. data/ext/asmjit/asmjit/tools/tablegen-x86.sh +3 -0
  198. data/ext/asmjit/asmjit/tools/tablegen.js +947 -0
  199. data/ext/asmjit/asmjit/tools/tablegen.sh +4 -0
  200. data/ext/asmjit/asmjit.cc +167 -30
  201. data/ext/asmjit/extconf.rb +9 -9
  202. data/lib/asmjit/version.rb +1 -1
  203. data/lib/asmjit.rb +14 -4
  204. metadata +198 -17
@@ -0,0 +1,365 @@
1
+ // [AsmJit]
2
+ // Machine Code Generation for C++.
3
+ //
4
+ // [License]
5
+ // ZLIB - See LICENSE.md file in the package.
6
+
7
+ // ============================================================================
8
+ // tablegen-arm.js
9
+ // ============================================================================
10
+
11
+ "use strict";
12
+
13
+ const { executionAsyncResource } = require("async_hooks");
14
+ const core = require("./tablegen.js");
15
+ const hasOwn = Object.prototype.hasOwnProperty;
16
+
17
+ const asmdb = core.asmdb;
18
+ const kIndent = core.kIndent;
19
+ const IndexedArray = core.IndexedArray;
20
+ const StringUtils = core.StringUtils;
21
+
22
+ const FAIL = core.FAIL;
23
+
24
+ // ============================================================================
25
+ // [ArmDB]
26
+ // ============================================================================
27
+
28
+ // Create ARM ISA.
29
+ const isa = new asmdb.arm.ISA();
30
+
31
+ // ============================================================================
32
+ // [tablegen.arm.GenUtils]
33
+ // ============================================================================
34
+
35
+ class GenUtils {
36
+ // Get a list of instructions based on `name` and optional `mode`.
37
+ static query(name, mode) {
38
+ const insts = isa.query(name);
39
+ return !mode ? insts : insts.filter(function(inst) { return inst.arch === mode; });
40
+ }
41
+
42
+ static archOf(records) {
43
+ var t16Arch = false;
44
+ var t32Arch = false;
45
+ var a32Arch = false;
46
+ var a64Arch = false;
47
+
48
+ for (var i = 0; i < records.length; i++) {
49
+ const record = records[i];
50
+ if (record.encoding === "T16") t16Arch = true;
51
+ if (record.encoding === "T32") t32Arch = true;
52
+ if (record.encoding === "A32") a32Arch = true;
53
+ if (record.encoding === "A64") a64Arch = true;
54
+ }
55
+
56
+ var s = (t16Arch && !t32Arch) ? "T16" :
57
+ (t32Arch && !t16Arch) ? "T32" :
58
+ (t16Arch && t32Arch) ? "Txx" : "---";
59
+ s += " ";
60
+ s += (a32Arch) ? "A32" : "---";
61
+ s += " ";
62
+ s += (a64Arch) ? "A64" : "---";
63
+
64
+ return `[${s}]`;
65
+ }
66
+
67
+ static featuresOf(records) {
68
+ const exts = Object.create(null);
69
+ for (var i = 0; i < records.length; i++) {
70
+ const record = records[i];
71
+ for (var k in record.extensions)
72
+ exts[k] = true;
73
+ }
74
+ const arr = Object.keys(exts);
75
+ arr.sort();
76
+ return arr;
77
+ }
78
+ }
79
+
80
+ // ============================================================================
81
+ // [tablegen.arm.ArmTableGen]
82
+ // ============================================================================
83
+
84
+ class ArmTableGen extends core.TableGen {
85
+ constructor() {
86
+ super("A64");
87
+ }
88
+
89
+ // --------------------------------------------------------------------------
90
+ // [Parse / Merge]
91
+ // --------------------------------------------------------------------------
92
+
93
+ parse() {
94
+ const rawData = this.dataOfFile("src/asmjit/arm/a64instdb.cpp");
95
+ const stringData = StringUtils.extract(rawData, "// ${InstInfo:Begin}", "// ${InstInfo:End");
96
+
97
+ const re = new RegExp(
98
+ "INST\\(\\s*" +
99
+ // [01] Instruction.
100
+ "(" +
101
+ "[A-Za-z0-9_]+" +
102
+ ")\\s*,\\s*" +
103
+
104
+ // [02] Encoding.
105
+ "(" +
106
+ "[^,]+" +
107
+ ")\\s*,\\s*" +
108
+
109
+ // [03] OpcodeData.
110
+ "(" +
111
+ "\\([^\\)]+\\)" +
112
+ ")\\s*,\\s*" +
113
+
114
+ // [04] RWInfo.
115
+ "(" +
116
+ "[^,]+" +
117
+ ")\\s*,\\s*" +
118
+
119
+ // [05] InstructionFlags.
120
+ "(\\s*" +
121
+ "(?:" +
122
+ "(?:" +
123
+ "[\\d]+" +
124
+ "|" +
125
+ "F\\([^\\)]*\\)" +
126
+ ")" +
127
+ "\\s*" +
128
+ "[|]?\\s*" +
129
+ ")+" +
130
+ ")\\s*,\\s*" +
131
+
132
+ // --- autogenerated fields ---
133
+
134
+ // [06] OpcodeDataIndex.
135
+ "([^\\)]+)" +
136
+ "\\s*,\\s*" +
137
+
138
+ // [07] NameDataIndex.
139
+ "([^\\)]+)" +
140
+ "\\s*\\)"
141
+ , "g");
142
+
143
+ var m;
144
+ while ((m = re.exec(stringData)) !== null) {
145
+ var enum_ = m[1];
146
+ var name = enum_ === "None" ? "" : enum_.toLowerCase();
147
+ var encoding = m[2].trim();
148
+ var opcodeData = m[3].trim();
149
+ var rwInfo = m[4].trim();
150
+ var instFlags = m[5].trim();
151
+
152
+ var displayName = name;
153
+ if (name.endsWith("_v"))
154
+ displayName = name.substring(0, name.length - 2);
155
+
156
+ // We have just matched #define INST()
157
+ if (name == "id" &&
158
+ encoding === "encoding" &&
159
+ encodingDataIndex === "encodingDataIndex")
160
+ continue;
161
+
162
+ this.addInst({
163
+ id : 0, // Instruction id (numeric value).
164
+ name : name, // Instruction name.
165
+ displayName : displayName, // Instruction name to display.
166
+ enum : enum_, // Instruction enum without `kId` prefix.
167
+ encoding : encoding, // Opcode encoding.
168
+ opcodeData : opcodeData, // Opcode data.
169
+ opcodeDataIndex : -1, // Opcode data index.
170
+ rwInfo : rwInfo, // RW info.
171
+ flags : instFlags, // Instruction flags.
172
+
173
+ nameIndex : -1 // Index to InstDB::_nameData.
174
+ });
175
+ }
176
+
177
+ if (this.insts.length === 0 || this.insts.length !== StringUtils.countOf(stringData, "INST("))
178
+ FAIL("ARMTableGen.parse(): Invalid parsing regexp (no data parsed)");
179
+
180
+ console.log("Number of Instructions: " + this.insts.length);
181
+ }
182
+
183
+ merge() {
184
+ var s = StringUtils.format(this.insts, "", true, function(inst) {
185
+ return "INST(" +
186
+ String(inst.enum ).padEnd(17) + ", " +
187
+ String(inst.encoding ).padEnd(19) + ", " +
188
+ String(inst.opcodeData ).padEnd(86) + ", " +
189
+ String(inst.rwInfo ).padEnd(10) + ", " +
190
+ String(inst.flags ).padEnd(26) + ", " +
191
+ String(inst.opcodeDataIndex ).padEnd( 3) + ", " +
192
+ String(inst.nameIndex ).padEnd( 4) + ")";
193
+ }) + "\n";
194
+ return this.inject("InstInfo", s, this.insts.length * 4);
195
+ }
196
+
197
+ // --------------------------------------------------------------------------
198
+ // [Hooks]
199
+ // --------------------------------------------------------------------------
200
+
201
+ onBeforeRun() {
202
+ this.load([
203
+ "src/asmjit/arm/a64emitter.h",
204
+ "src/asmjit/arm/a64globals.h",
205
+ "src/asmjit/arm/a64instdb.cpp",
206
+ "src/asmjit/arm/a64instdb.h",
207
+ "src/asmjit/arm/a64instdb_p.h"
208
+ ]);
209
+ this.parse();
210
+ }
211
+
212
+ onAfterRun() {
213
+ this.merge();
214
+ this.save();
215
+ this.dumpTableSizes();
216
+ }
217
+ }
218
+
219
+ // ============================================================================
220
+ // [tablegen.arm.IdEnum]
221
+ // ============================================================================
222
+
223
+ class IdEnum extends core.IdEnum {
224
+ constructor() {
225
+ super("IdEnum");
226
+ }
227
+
228
+ comment(inst) {
229
+ let name = inst.name;
230
+ let ext = [];
231
+
232
+ if (name.endsWith("_v")) {
233
+ name = name.substr(0, name.length - 2);
234
+ ext.push("ASIMD");
235
+ }
236
+
237
+ let exts = "";
238
+ if (ext.length)
239
+ exts = " {" + ext.join("&") + "}";
240
+
241
+ return `Instruction '${name}'${exts}.`;
242
+ }
243
+ }
244
+
245
+ // ============================================================================
246
+ // [tablegen.arm.NameTable]
247
+ // ============================================================================
248
+
249
+ class NameTable extends core.NameTable {
250
+ constructor() {
251
+ super("NameTable");
252
+ }
253
+ }
254
+
255
+ // ============================================================================
256
+ // [tablegen.arm.EncodingTable]
257
+ // ============================================================================
258
+
259
+ class EncodingTable extends core.Task {
260
+ constructor() {
261
+ super("EncodingTable");
262
+ }
263
+
264
+ run() {
265
+ const insts = this.ctx.insts;
266
+ const map = {};
267
+
268
+ for (var i = 0; i < insts.length; i++) {
269
+ const inst = insts[i];
270
+
271
+ const encoding = inst.encoding;
272
+ const opcodeData = inst.opcodeData.replace(/\(/g, "{ ").replace(/\)/g, " }");
273
+
274
+ if (!hasOwn.call(map, encoding))
275
+ map[encoding] = [];
276
+
277
+ if (inst.opcodeData === "(_)") {
278
+ inst.opcodeDataIndex = 0;
279
+ continue;
280
+ }
281
+
282
+ const opcodeTable = map[encoding];
283
+ const opcodeDataIndex = opcodeTable.length;
284
+
285
+ opcodeTable.push({ name: inst.name, data: opcodeData });
286
+ inst.opcodeDataIndex = opcodeDataIndex;
287
+ }
288
+
289
+ const keys = Object.keys(map);
290
+ keys.sort();
291
+
292
+ var tableSource = "";
293
+ var tableHeader = "";
294
+ var encodingIds = "";
295
+
296
+ encodingIds += "enum EncodingId : uint32_t {\n"
297
+ encodingIds += " kEncodingNone = 0";
298
+
299
+ keys.forEach((dataClass) => {
300
+ const dataName = dataClass[0].toLowerCase() + dataClass.substr(1);
301
+ const opcodeTable = map[dataClass];
302
+ const count = opcodeTable.length;
303
+
304
+ if (dataClass !== "None") {
305
+ encodingIds += ",\n"
306
+ encodingIds += " kEncoding" + dataClass;
307
+ }
308
+
309
+ if (count) {
310
+ tableHeader += `extern const ${dataClass} ${dataName}[${count}];\n`;
311
+
312
+ if (tableSource)
313
+ tableSource += "\n";
314
+
315
+ tableSource += `const ${dataClass} ${dataName}[${count}] = {\n`;
316
+ for (var i = 0; i < count; i++) {
317
+ tableSource += ` ${opcodeTable[i].data}` + (i == count - 1 ? " " : ",") + " // " + opcodeTable[i].name + "\n";
318
+ }
319
+ tableSource += `};\n`;
320
+ }
321
+ });
322
+
323
+ encodingIds += "\n};\n";
324
+
325
+ return this.ctx.inject("EncodingId" , StringUtils.disclaimer(encodingIds), 0) +
326
+ this.ctx.inject("EncodingDataForward", StringUtils.disclaimer(tableHeader), 0) +
327
+ this.ctx.inject("EncodingData" , StringUtils.disclaimer(tableSource), 0);
328
+ }
329
+ }
330
+ // ============================================================================
331
+ // [tablegen.arm.CommonTable]
332
+ // ============================================================================
333
+
334
+ class CommonTable extends core.Task {
335
+ constructor() {
336
+ super("CommonTable", [
337
+ "IdEnum",
338
+ "NameTable"
339
+ ]);
340
+ }
341
+
342
+ run() {
343
+ //const table = new IndexedArray();
344
+
345
+ //for (var i = 0; i < insts.length; i++) {
346
+ // const inst = insts[i];
347
+ // const item = "{ " + "0" + "}";
348
+ // inst.commonIndex = table.addIndexed(item);
349
+ //}
350
+
351
+ // return this.ctx.inject("InstInfo", StringUtils.disclaimer(s), 0);
352
+ return 0;
353
+ }
354
+ }
355
+
356
+ // ============================================================================
357
+ // [Main]
358
+ // ============================================================================
359
+
360
+ new ArmTableGen()
361
+ .addTask(new IdEnum())
362
+ .addTask(new NameTable())
363
+ .addTask(new EncodingTable())
364
+ .addTask(new CommonTable())
365
+ .run();
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ node ./tablegen-arm.js