asmjit 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/asmjit.gemspec +1 -1
  4. data/ext/asmjit/asmjit/.editorconfig +10 -0
  5. data/ext/asmjit/asmjit/.github/FUNDING.yml +1 -0
  6. data/ext/asmjit/asmjit/.github/workflows/build-config.json +47 -0
  7. data/ext/asmjit/asmjit/.github/workflows/build.yml +156 -0
  8. data/ext/asmjit/asmjit/.gitignore +6 -0
  9. data/ext/asmjit/asmjit/CMakeLists.txt +611 -0
  10. data/ext/asmjit/asmjit/LICENSE.md +17 -0
  11. data/ext/asmjit/asmjit/README.md +69 -0
  12. data/ext/asmjit/asmjit/src/asmjit/a64.h +62 -0
  13. data/ext/asmjit/asmjit/src/asmjit/arm/a64archtraits_p.h +81 -0
  14. data/ext/asmjit/asmjit/src/asmjit/arm/a64assembler.cpp +5115 -0
  15. data/ext/asmjit/asmjit/src/asmjit/arm/a64assembler.h +72 -0
  16. data/ext/asmjit/asmjit/src/asmjit/arm/a64builder.cpp +51 -0
  17. data/ext/asmjit/asmjit/src/asmjit/arm/a64builder.h +57 -0
  18. data/ext/asmjit/asmjit/src/asmjit/arm/a64compiler.cpp +60 -0
  19. data/ext/asmjit/asmjit/src/asmjit/arm/a64compiler.h +247 -0
  20. data/ext/asmjit/asmjit/src/asmjit/arm/a64emithelper.cpp +464 -0
  21. data/ext/asmjit/asmjit/src/asmjit/arm/a64emithelper_p.h +50 -0
  22. data/ext/asmjit/asmjit/src/asmjit/arm/a64emitter.h +1228 -0
  23. data/ext/asmjit/asmjit/src/asmjit/arm/a64formatter.cpp +298 -0
  24. data/ext/asmjit/asmjit/src/asmjit/arm/a64formatter_p.h +59 -0
  25. data/ext/asmjit/asmjit/src/asmjit/arm/a64func.cpp +189 -0
  26. data/ext/asmjit/asmjit/src/asmjit/arm/a64func_p.h +33 -0
  27. data/ext/asmjit/asmjit/src/asmjit/arm/a64globals.h +1894 -0
  28. data/ext/asmjit/asmjit/src/asmjit/arm/a64instapi.cpp +278 -0
  29. data/ext/asmjit/asmjit/src/asmjit/arm/a64instapi_p.h +41 -0
  30. data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb.cpp +1957 -0
  31. data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb.h +74 -0
  32. data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb_p.h +876 -0
  33. data/ext/asmjit/asmjit/src/asmjit/arm/a64operand.cpp +85 -0
  34. data/ext/asmjit/asmjit/src/asmjit/arm/a64operand.h +312 -0
  35. data/ext/asmjit/asmjit/src/asmjit/arm/a64rapass.cpp +852 -0
  36. data/ext/asmjit/asmjit/src/asmjit/arm/a64rapass_p.h +105 -0
  37. data/ext/asmjit/asmjit/src/asmjit/arm/a64utils.h +179 -0
  38. data/ext/asmjit/asmjit/src/asmjit/arm/armformatter.cpp +143 -0
  39. data/ext/asmjit/asmjit/src/asmjit/arm/armformatter_p.h +44 -0
  40. data/ext/asmjit/asmjit/src/asmjit/arm/armglobals.h +21 -0
  41. data/ext/asmjit/asmjit/src/asmjit/arm/armoperand.h +621 -0
  42. data/ext/asmjit/asmjit/src/asmjit/arm.h +62 -0
  43. data/ext/asmjit/asmjit/src/asmjit/asmjit-scope-begin.h +17 -0
  44. data/ext/asmjit/asmjit/src/asmjit/asmjit-scope-end.h +9 -0
  45. data/ext/asmjit/asmjit/src/asmjit/asmjit.h +33 -0
  46. data/ext/asmjit/asmjit/src/asmjit/core/api-build_p.h +55 -0
  47. data/ext/asmjit/asmjit/src/asmjit/core/api-config.h +613 -0
  48. data/ext/asmjit/asmjit/src/asmjit/core/archcommons.h +229 -0
  49. data/ext/asmjit/asmjit/src/asmjit/core/archtraits.cpp +160 -0
  50. data/ext/asmjit/asmjit/src/asmjit/core/archtraits.h +290 -0
  51. data/ext/asmjit/asmjit/src/asmjit/core/assembler.cpp +406 -0
  52. data/ext/asmjit/asmjit/src/asmjit/core/assembler.h +129 -0
  53. data/ext/asmjit/asmjit/src/asmjit/core/builder.cpp +889 -0
  54. data/ext/asmjit/asmjit/src/asmjit/core/builder.h +1391 -0
  55. data/ext/asmjit/asmjit/src/asmjit/core/codebuffer.h +113 -0
  56. data/ext/asmjit/asmjit/src/asmjit/core/codeholder.cpp +1149 -0
  57. data/ext/asmjit/asmjit/src/asmjit/core/codeholder.h +1035 -0
  58. data/ext/asmjit/asmjit/src/asmjit/core/codewriter.cpp +175 -0
  59. data/ext/asmjit/asmjit/src/asmjit/core/codewriter_p.h +179 -0
  60. data/ext/asmjit/asmjit/src/asmjit/core/compiler.cpp +582 -0
  61. data/ext/asmjit/asmjit/src/asmjit/core/compiler.h +737 -0
  62. data/ext/asmjit/asmjit/src/asmjit/core/compilerdefs.h +173 -0
  63. data/ext/asmjit/asmjit/src/asmjit/core/constpool.cpp +363 -0
  64. data/ext/asmjit/asmjit/src/asmjit/core/constpool.h +250 -0
  65. data/ext/asmjit/asmjit/src/asmjit/core/cpuinfo.cpp +1162 -0
  66. data/ext/asmjit/asmjit/src/asmjit/core/cpuinfo.h +813 -0
  67. data/ext/asmjit/asmjit/src/asmjit/core/emithelper.cpp +323 -0
  68. data/ext/asmjit/asmjit/src/asmjit/core/emithelper_p.h +58 -0
  69. data/ext/asmjit/asmjit/src/asmjit/core/emitter.cpp +333 -0
  70. data/ext/asmjit/asmjit/src/asmjit/core/emitter.h +741 -0
  71. data/ext/asmjit/asmjit/src/asmjit/core/emitterutils.cpp +129 -0
  72. data/ext/asmjit/asmjit/src/asmjit/core/emitterutils_p.h +89 -0
  73. data/ext/asmjit/asmjit/src/asmjit/core/environment.cpp +46 -0
  74. data/ext/asmjit/asmjit/src/asmjit/core/environment.h +508 -0
  75. data/ext/asmjit/asmjit/src/asmjit/core/errorhandler.cpp +14 -0
  76. data/ext/asmjit/asmjit/src/asmjit/core/errorhandler.h +228 -0
  77. data/ext/asmjit/asmjit/src/asmjit/core/formatter.cpp +584 -0
  78. data/ext/asmjit/asmjit/src/asmjit/core/formatter.h +247 -0
  79. data/ext/asmjit/asmjit/src/asmjit/core/formatter_p.h +34 -0
  80. data/ext/asmjit/asmjit/src/asmjit/core/func.cpp +286 -0
  81. data/ext/asmjit/asmjit/src/asmjit/core/func.h +1445 -0
  82. data/ext/asmjit/asmjit/src/asmjit/core/funcargscontext.cpp +293 -0
  83. data/ext/asmjit/asmjit/src/asmjit/core/funcargscontext_p.h +199 -0
  84. data/ext/asmjit/asmjit/src/asmjit/core/globals.cpp +133 -0
  85. data/ext/asmjit/asmjit/src/asmjit/core/globals.h +393 -0
  86. data/ext/asmjit/asmjit/src/asmjit/core/inst.cpp +113 -0
  87. data/ext/asmjit/asmjit/src/asmjit/core/inst.h +772 -0
  88. data/ext/asmjit/asmjit/src/asmjit/core/jitallocator.cpp +1242 -0
  89. data/ext/asmjit/asmjit/src/asmjit/core/jitallocator.h +261 -0
  90. data/ext/asmjit/asmjit/src/asmjit/core/jitruntime.cpp +80 -0
  91. data/ext/asmjit/asmjit/src/asmjit/core/jitruntime.h +89 -0
  92. data/ext/asmjit/asmjit/src/asmjit/core/logger.cpp +69 -0
  93. data/ext/asmjit/asmjit/src/asmjit/core/logger.h +198 -0
  94. data/ext/asmjit/asmjit/src/asmjit/core/misc_p.h +33 -0
  95. data/ext/asmjit/asmjit/src/asmjit/core/operand.cpp +132 -0
  96. data/ext/asmjit/asmjit/src/asmjit/core/operand.h +1611 -0
  97. data/ext/asmjit/asmjit/src/asmjit/core/osutils.cpp +84 -0
  98. data/ext/asmjit/asmjit/src/asmjit/core/osutils.h +61 -0
  99. data/ext/asmjit/asmjit/src/asmjit/core/osutils_p.h +68 -0
  100. data/ext/asmjit/asmjit/src/asmjit/core/raassignment_p.h +418 -0
  101. data/ext/asmjit/asmjit/src/asmjit/core/rabuilders_p.h +612 -0
  102. data/ext/asmjit/asmjit/src/asmjit/core/radefs_p.h +1204 -0
  103. data/ext/asmjit/asmjit/src/asmjit/core/ralocal.cpp +1166 -0
  104. data/ext/asmjit/asmjit/src/asmjit/core/ralocal_p.h +254 -0
  105. data/ext/asmjit/asmjit/src/asmjit/core/rapass.cpp +1969 -0
  106. data/ext/asmjit/asmjit/src/asmjit/core/rapass_p.h +1183 -0
  107. data/ext/asmjit/asmjit/src/asmjit/core/rastack.cpp +184 -0
  108. data/ext/asmjit/asmjit/src/asmjit/core/rastack_p.h +171 -0
  109. data/ext/asmjit/asmjit/src/asmjit/core/string.cpp +559 -0
  110. data/ext/asmjit/asmjit/src/asmjit/core/string.h +372 -0
  111. data/ext/asmjit/asmjit/src/asmjit/core/support.cpp +494 -0
  112. data/ext/asmjit/asmjit/src/asmjit/core/support.h +1773 -0
  113. data/ext/asmjit/asmjit/src/asmjit/core/target.cpp +14 -0
  114. data/ext/asmjit/asmjit/src/asmjit/core/target.h +53 -0
  115. data/ext/asmjit/asmjit/src/asmjit/core/type.cpp +74 -0
  116. data/ext/asmjit/asmjit/src/asmjit/core/type.h +419 -0
  117. data/ext/asmjit/asmjit/src/asmjit/core/virtmem.cpp +722 -0
  118. data/ext/asmjit/asmjit/src/asmjit/core/virtmem.h +242 -0
  119. data/ext/asmjit/asmjit/src/asmjit/core/zone.cpp +353 -0
  120. data/ext/asmjit/asmjit/src/asmjit/core/zone.h +615 -0
  121. data/ext/asmjit/asmjit/src/asmjit/core/zonehash.cpp +309 -0
  122. data/ext/asmjit/asmjit/src/asmjit/core/zonehash.h +186 -0
  123. data/ext/asmjit/asmjit/src/asmjit/core/zonelist.cpp +163 -0
  124. data/ext/asmjit/asmjit/src/asmjit/core/zonelist.h +209 -0
  125. data/ext/asmjit/asmjit/src/asmjit/core/zonestack.cpp +176 -0
  126. data/ext/asmjit/asmjit/src/asmjit/core/zonestack.h +239 -0
  127. data/ext/asmjit/asmjit/src/asmjit/core/zonestring.h +120 -0
  128. data/ext/asmjit/asmjit/src/asmjit/core/zonetree.cpp +99 -0
  129. data/ext/asmjit/asmjit/src/asmjit/core/zonetree.h +380 -0
  130. data/ext/asmjit/asmjit/src/asmjit/core/zonevector.cpp +356 -0
  131. data/ext/asmjit/asmjit/src/asmjit/core/zonevector.h +690 -0
  132. data/ext/asmjit/asmjit/src/asmjit/core.h +1861 -0
  133. data/ext/asmjit/asmjit/src/asmjit/x86/x86archtraits_p.h +148 -0
  134. data/ext/asmjit/asmjit/src/asmjit/x86/x86assembler.cpp +5110 -0
  135. data/ext/asmjit/asmjit/src/asmjit/x86/x86assembler.h +685 -0
  136. data/ext/asmjit/asmjit/src/asmjit/x86/x86builder.cpp +52 -0
  137. data/ext/asmjit/asmjit/src/asmjit/x86/x86builder.h +351 -0
  138. data/ext/asmjit/asmjit/src/asmjit/x86/x86compiler.cpp +61 -0
  139. data/ext/asmjit/asmjit/src/asmjit/x86/x86compiler.h +721 -0
  140. data/ext/asmjit/asmjit/src/asmjit/x86/x86emithelper.cpp +619 -0
  141. data/ext/asmjit/asmjit/src/asmjit/x86/x86emithelper_p.h +60 -0
  142. data/ext/asmjit/asmjit/src/asmjit/x86/x86emitter.h +4315 -0
  143. data/ext/asmjit/asmjit/src/asmjit/x86/x86formatter.cpp +944 -0
  144. data/ext/asmjit/asmjit/src/asmjit/x86/x86formatter_p.h +58 -0
  145. data/ext/asmjit/asmjit/src/asmjit/x86/x86func.cpp +503 -0
  146. data/ext/asmjit/asmjit/src/asmjit/x86/x86func_p.h +33 -0
  147. data/ext/asmjit/asmjit/src/asmjit/x86/x86globals.h +2169 -0
  148. data/ext/asmjit/asmjit/src/asmjit/x86/x86instapi.cpp +1732 -0
  149. data/ext/asmjit/asmjit/src/asmjit/x86/x86instapi_p.h +41 -0
  150. data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb.cpp +4427 -0
  151. data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb.h +563 -0
  152. data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb_p.h +311 -0
  153. data/ext/asmjit/asmjit/src/asmjit/x86/x86opcode_p.h +436 -0
  154. data/ext/asmjit/asmjit/src/asmjit/x86/x86operand.cpp +231 -0
  155. data/ext/asmjit/asmjit/src/asmjit/x86/x86operand.h +1085 -0
  156. data/ext/asmjit/asmjit/src/asmjit/x86/x86rapass.cpp +1509 -0
  157. data/ext/asmjit/asmjit/src/asmjit/x86/x86rapass_p.h +94 -0
  158. data/ext/asmjit/asmjit/src/asmjit/x86.h +93 -0
  159. data/ext/asmjit/asmjit/src/asmjit.natvis +245 -0
  160. data/ext/asmjit/asmjit/test/asmjit_test_assembler.cpp +84 -0
  161. data/ext/asmjit/asmjit/test/asmjit_test_assembler.h +85 -0
  162. data/ext/asmjit/asmjit/test/asmjit_test_assembler_a64.cpp +4006 -0
  163. data/ext/asmjit/asmjit/test/asmjit_test_assembler_x64.cpp +17833 -0
  164. data/ext/asmjit/asmjit/test/asmjit_test_assembler_x86.cpp +8300 -0
  165. data/ext/asmjit/asmjit/test/asmjit_test_compiler.cpp +253 -0
  166. data/ext/asmjit/asmjit/test/asmjit_test_compiler.h +73 -0
  167. data/ext/asmjit/asmjit/test/asmjit_test_compiler_a64.cpp +690 -0
  168. data/ext/asmjit/asmjit/test/asmjit_test_compiler_x86.cpp +4317 -0
  169. data/ext/asmjit/asmjit/test/asmjit_test_emitters.cpp +197 -0
  170. data/ext/asmjit/asmjit/test/asmjit_test_instinfo.cpp +181 -0
  171. data/ext/asmjit/asmjit/test/asmjit_test_misc.h +257 -0
  172. data/ext/asmjit/asmjit/test/asmjit_test_perf.cpp +62 -0
  173. data/ext/asmjit/asmjit/test/asmjit_test_perf.h +61 -0
  174. data/ext/asmjit/asmjit/test/asmjit_test_perf_a64.cpp +699 -0
  175. data/ext/asmjit/asmjit/test/asmjit_test_perf_x86.cpp +5032 -0
  176. data/ext/asmjit/asmjit/test/asmjit_test_unit.cpp +172 -0
  177. data/ext/asmjit/asmjit/test/asmjit_test_x86_sections.cpp +172 -0
  178. data/ext/asmjit/asmjit/test/asmjitutils.h +38 -0
  179. data/ext/asmjit/asmjit/test/broken.cpp +312 -0
  180. data/ext/asmjit/asmjit/test/broken.h +148 -0
  181. data/ext/asmjit/asmjit/test/cmdline.h +61 -0
  182. data/ext/asmjit/asmjit/test/performancetimer.h +41 -0
  183. data/ext/asmjit/asmjit/tools/configure-makefiles.sh +13 -0
  184. data/ext/asmjit/asmjit/tools/configure-ninja.sh +13 -0
  185. data/ext/asmjit/asmjit/tools/configure-sanitizers.sh +13 -0
  186. data/ext/asmjit/asmjit/tools/configure-vs2019-x64.bat +2 -0
  187. data/ext/asmjit/asmjit/tools/configure-vs2019-x86.bat +2 -0
  188. data/ext/asmjit/asmjit/tools/configure-vs2022-x64.bat +2 -0
  189. data/ext/asmjit/asmjit/tools/configure-vs2022-x86.bat +2 -0
  190. data/ext/asmjit/asmjit/tools/configure-xcode.sh +8 -0
  191. data/ext/asmjit/asmjit/tools/enumgen.js +417 -0
  192. data/ext/asmjit/asmjit/tools/enumgen.sh +3 -0
  193. data/ext/asmjit/asmjit/tools/tablegen-arm.js +365 -0
  194. data/ext/asmjit/asmjit/tools/tablegen-arm.sh +3 -0
  195. data/ext/asmjit/asmjit/tools/tablegen-x86.js +2638 -0
  196. data/ext/asmjit/asmjit/tools/tablegen-x86.sh +3 -0
  197. data/ext/asmjit/asmjit/tools/tablegen.js +947 -0
  198. data/ext/asmjit/asmjit/tools/tablegen.sh +4 -0
  199. data/ext/asmjit/asmjit.cc +18 -0
  200. data/lib/asmjit/version.rb +1 -1
  201. metadata +197 -2
@@ -0,0 +1,253 @@
1
+ // This file is part of AsmJit project <https://asmjit.com>
2
+ //
3
+ // See asmjit.h or LICENSE.md for license and copyright information
4
+ // SPDX-License-Identifier: Zlib
5
+
6
+ #include <asmjit/core.h>
7
+
8
+ #include <stdio.h>
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+
12
+ #include <memory>
13
+ #include <vector>
14
+ #include <chrono>
15
+
16
+ #include "cmdline.h"
17
+ #include "asmjitutils.h"
18
+ #include "performancetimer.h"
19
+
20
+ #include "asmjit_test_compiler.h"
21
+
22
+ #if !defined(ASMJIT_NO_X86) && ASMJIT_ARCH_X86
23
+ #include <asmjit/x86.h>
24
+ void compiler_add_x86_tests(TestApp& app);
25
+ #endif
26
+
27
+ #if !defined(ASMJIT_NO_AARCH64) && ASMJIT_ARCH_ARM == 64
28
+ #include <asmjit/a64.h>
29
+ void compiler_add_a64_tests(TestApp& app);
30
+ #endif
31
+
32
+ #if !defined(ASMJIT_NO_X86) && ASMJIT_ARCH_X86
33
+ #define ASMJIT_HAVE_WORKING_JIT
34
+ #endif
35
+
36
+ #if !defined(ASMJIT_NO_AARCH64) && ASMJIT_ARCH_ARM == 64
37
+ #define ASMJIT_HAVE_WORKING_JIT
38
+ #endif
39
+
40
+ using namespace asmjit;
41
+
42
+ int TestApp::handleArgs(int argc, const char* const* argv) {
43
+ CmdLine cmd(argc, argv);
44
+
45
+ if (cmd.hasArg("--verbose")) _verbose = true;
46
+ if (cmd.hasArg("--dump-asm")) _dumpAsm = true;
47
+ if (cmd.hasArg("--dump-hex")) _dumpHex = true;
48
+
49
+ return 0;
50
+ }
51
+
52
+ void TestApp::showInfo() {
53
+ printf("AsmJit Compiler Test-Suite v%u.%u.%u (Arch=%s):\n",
54
+ unsigned((ASMJIT_LIBRARY_VERSION >> 16) ),
55
+ unsigned((ASMJIT_LIBRARY_VERSION >> 8) & 0xFF),
56
+ unsigned((ASMJIT_LIBRARY_VERSION ) & 0xFF),
57
+ asmjitArchAsString(Arch::kHost));
58
+ printf(" [%s] Verbose (use --verbose to turn verbose output ON)\n", _verbose ? "x" : " ");
59
+ printf(" [%s] DumpAsm (use --dump-asm to turn assembler dumps ON)\n", _dumpAsm ? "x" : " ");
60
+ printf(" [%s] DumpHex (use --dump-hex to dump binary in hexadecimal)\n", _dumpHex ? "x" : " ");
61
+ printf("\n");
62
+ }
63
+
64
+ int TestApp::run() {
65
+ #ifndef ASMJIT_HAVE_WORKING_JIT
66
+ return 0;
67
+ #else
68
+ #ifndef ASMJIT_NO_LOGGING
69
+ FormatOptions formatOptions;
70
+ formatOptions.addFlags(
71
+ FormatFlags::kMachineCode |
72
+ FormatFlags::kExplainImms |
73
+ FormatFlags::kRegCasts );
74
+
75
+ FileLogger fileLogger(stdout);
76
+ fileLogger.setOptions(formatOptions);
77
+
78
+ StringLogger stringLogger;
79
+ stringLogger.setOptions(formatOptions);
80
+ #endif
81
+
82
+ JitRuntime runtime;
83
+
84
+ PerformanceTimer compileTimer;
85
+ PerformanceTimer finalizeTimer;
86
+ double compileTime = 0;
87
+ double finalizeTime = 0;
88
+
89
+ for (std::unique_ptr<TestCase>& test : _tests) {
90
+ for (uint32_t pass = 0; pass < 2; pass++) {
91
+ CodeHolder code;
92
+ SimpleErrorHandler errorHandler;
93
+
94
+ code.init(runtime.environment());
95
+ code.setErrorHandler(&errorHandler);
96
+
97
+ if (pass != 0) {
98
+ #ifndef ASMJIT_NO_LOGGING
99
+ if (_verbose) {
100
+ code.setLogger(&fileLogger);
101
+ }
102
+ else {
103
+ stringLogger.clear();
104
+ code.setLogger(&stringLogger);
105
+ }
106
+ #endif
107
+
108
+ printf("[Test] %s", test->name());
109
+
110
+ #ifndef ASMJIT_NO_LOGGING
111
+ if (_verbose)
112
+ printf("\n");
113
+ #endif
114
+ }
115
+
116
+
117
+ #if !defined(ASMJIT_NO_X86) && ASMJIT_ARCH_X86
118
+ x86::Compiler cc(&code);
119
+ #endif
120
+
121
+ #if !defined(ASMJIT_NO_AARCH64) && ASMJIT_ARCH_ARM == 64
122
+ a64::Compiler cc(&code);
123
+ #endif
124
+
125
+ #ifndef ASMJIT_NO_LOGGING
126
+ cc.addDiagnosticOptions(DiagnosticOptions::kRAAnnotate | DiagnosticOptions::kRADebugAll);
127
+ #endif
128
+
129
+ compileTimer.start();
130
+ test->compile(cc);
131
+ compileTimer.stop();
132
+
133
+ void* func = nullptr;
134
+ Error err = errorHandler._err;
135
+
136
+ if (!err) {
137
+ finalizeTimer.start();
138
+ err = cc.finalize();
139
+ finalizeTimer.stop();
140
+ }
141
+
142
+ // The first pass is only for timing serialization and compilation, because otherwise it would be biased by
143
+ // logging, which takes much more time than finalize() does. We want to benchmark Compiler the way it would
144
+ // be used in production.
145
+ if (pass == 0) {
146
+ compileTime += compileTimer.duration();
147
+ finalizeTime += finalizeTimer.duration();
148
+ continue;
149
+ }
150
+
151
+ #ifndef ASMJIT_NO_LOGGING
152
+ if (_dumpAsm) {
153
+ if (!_verbose)
154
+ printf("\n");
155
+
156
+ String sb;
157
+ Formatter::formatNodeList(sb, formatOptions, &cc);
158
+ printf("%s", sb.data());
159
+ }
160
+ #endif
161
+
162
+ if (err == kErrorOk)
163
+ err = runtime.add(&func, &code);
164
+
165
+ if (err == kErrorOk && _dumpHex) {
166
+ String sb;
167
+ sb.appendHex((void*)func, code.codeSize());
168
+ printf("\n (HEX: %s)\n", sb.data());
169
+ }
170
+
171
+ if (_verbose)
172
+ fflush(stdout);
173
+
174
+ if (err == kErrorOk) {
175
+ _outputSize += code.codeSize();
176
+
177
+ StringTmp<128> result;
178
+ StringTmp<128> expect;
179
+
180
+ if (test->run(func, result, expect)) {
181
+ if (!_verbose)
182
+ printf(" [OK]\n");
183
+ }
184
+ else {
185
+ if (!_verbose)
186
+ printf(" [FAILED]\n");
187
+
188
+ #ifndef ASMJIT_NO_LOGGING
189
+ if (!_verbose)
190
+ printf("%s", stringLogger.data());
191
+ #endif
192
+
193
+ printf("[Status]\n");
194
+ printf(" Returned: %s\n", result.data());
195
+ printf(" Expected: %s\n", expect.data());
196
+
197
+ _nFailed++;
198
+ }
199
+
200
+ if (_dumpAsm)
201
+ printf("\n");
202
+
203
+ runtime.release(func);
204
+ }
205
+ else {
206
+ if (!_verbose)
207
+ printf(" [FAILED]\n");
208
+
209
+ #ifndef ASMJIT_NO_LOGGING
210
+ if (!_verbose)
211
+ printf("%s", stringLogger.data());
212
+ #endif
213
+
214
+ printf("[Status]\n");
215
+ printf(" ERROR 0x%08X: %s\n", unsigned(err), errorHandler._message.data());
216
+
217
+ _nFailed++;
218
+ }
219
+ }
220
+ }
221
+
222
+ printf("\n");
223
+ printf("Summary:\n");
224
+ printf(" OutputSize: %zu bytes\n", _outputSize);
225
+ printf(" CompileTime: %.2f ms\n", compileTime);
226
+ printf(" FinalizeTime: %.2f ms\n", finalizeTime);
227
+ printf("\n");
228
+
229
+ if (_nFailed == 0)
230
+ printf("** SUCCESS: All %u tests passed **\n", unsigned(_tests.size()));
231
+ else
232
+ printf("** FAILURE: %u of %u tests failed **\n", _nFailed, unsigned(_tests.size()));
233
+
234
+ return _nFailed == 0 ? 0 : 1;
235
+ #endif
236
+ }
237
+
238
+ int main(int argc, char* argv[]) {
239
+ TestApp app;
240
+
241
+ app.handleArgs(argc, argv);
242
+ app.showInfo();
243
+
244
+ #if !defined(ASMJIT_NO_X86) && ASMJIT_ARCH_X86
245
+ compiler_add_x86_tests(app);
246
+ #endif
247
+
248
+ #if !defined(ASMJIT_NO_AARCH64) && ASMJIT_ARCH_ARM == 64
249
+ compiler_add_a64_tests(app);
250
+ #endif
251
+
252
+ return app.run();
253
+ }
@@ -0,0 +1,73 @@
1
+ // This file is part of AsmJit project <https://asmjit.com>
2
+ //
3
+ // See asmjit.h or LICENSE.md for license and copyright information
4
+ // SPDX-License-Identifier: Zlib
5
+
6
+ #ifndef ASMJIT_TEST_COMPILER_H_INCLUDED
7
+ #define ASMJIT_TEST_COMPILER_H_INCLUDED
8
+
9
+ #include <asmjit/core.h>
10
+
11
+ #include <memory>
12
+ #include <vector>
13
+
14
+ class SimpleErrorHandler : public asmjit::ErrorHandler {
15
+ public:
16
+ SimpleErrorHandler()
17
+ : _err(asmjit::kErrorOk) {}
18
+
19
+ virtual void handleError(asmjit::Error err, const char* message, asmjit::BaseEmitter* origin) {
20
+ asmjit::DebugUtils::unused(origin);
21
+ _err = err;
22
+ _message.assign(message);
23
+ }
24
+
25
+ asmjit::Error _err;
26
+ asmjit::String _message;
27
+ };
28
+
29
+ //! A test case interface for testing AsmJit's Compiler.
30
+ class TestCase {
31
+ public:
32
+ TestCase(const char* name = nullptr) {
33
+ if (name)
34
+ _name.assign(name);
35
+ }
36
+
37
+ virtual ~TestCase() {}
38
+
39
+ inline const char* name() const { return _name.data(); }
40
+
41
+ virtual void compile(asmjit::BaseCompiler& cc) = 0;
42
+ virtual bool run(void* func, asmjit::String& result, asmjit::String& expect) = 0;
43
+
44
+ asmjit::String _name;
45
+ };
46
+
47
+ class TestApp {
48
+ public:
49
+ std::vector<std::unique_ptr<TestCase>> _tests;
50
+
51
+ unsigned _nFailed = 0;
52
+ size_t _outputSize = 0;
53
+
54
+ bool _verbose = false;
55
+ bool _dumpAsm = false;
56
+ bool _dumpHex = false;
57
+
58
+ TestApp() noexcept {}
59
+ ~TestApp() noexcept {}
60
+
61
+ void add(TestCase* test) noexcept {
62
+ _tests.push_back(std::unique_ptr<TestCase>(test));
63
+ }
64
+
65
+ template<class T>
66
+ inline void addT() { T::add(*this); }
67
+
68
+ int handleArgs(int argc, const char* const* argv);
69
+ void showInfo();
70
+ int run();
71
+ };
72
+
73
+ #endif // ASMJIT_TEST_COMPILER_H_INCLUDED