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,393 @@
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_CORE_GLOBALS_H_INCLUDED
7
+ #define ASMJIT_CORE_GLOBALS_H_INCLUDED
8
+
9
+ #include "../core/api-config.h"
10
+
11
+ ASMJIT_BEGIN_NAMESPACE
12
+
13
+ //! \cond INTERNAL
14
+ //! \addtogroup asmjit_utilities
15
+ //! \{
16
+ namespace Support {
17
+ //! Cast designed to cast between function and void* pointers.
18
+ template<typename Dst, typename Src>
19
+ static inline Dst ptr_cast_impl(Src p) noexcept { return (Dst)p; }
20
+ } // {Support}
21
+
22
+ #if defined(ASMJIT_NO_STDCXX)
23
+ namespace Support {
24
+ ASMJIT_FORCE_INLINE void* operatorNew(size_t n) noexcept { return malloc(n); }
25
+ ASMJIT_FORCE_INLINE void operatorDelete(void* p) noexcept { if (p) free(p); }
26
+ } // {Support}
27
+
28
+ #define ASMJIT_BASE_CLASS(TYPE) \
29
+ ASMJIT_FORCE_INLINE void* operator new(size_t n) noexcept { \
30
+ return Support::operatorNew(n); \
31
+ } \
32
+ \
33
+ ASMJIT_FORCE_INLINE void operator delete(void* p) noexcept { \
34
+ Support::operatorDelete(p); \
35
+ } \
36
+ \
37
+ ASMJIT_FORCE_INLINE void* operator new(size_t, void* p) noexcept { return p; } \
38
+ ASMJIT_FORCE_INLINE void operator delete(void*, void*) noexcept {}
39
+ #else
40
+ #define ASMJIT_BASE_CLASS(TYPE)
41
+ #endif
42
+
43
+ //! \}
44
+ //! \endcond
45
+
46
+ //! \addtogroup asmjit_core
47
+ //! \{
48
+
49
+ //! Byte order.
50
+ enum class ByteOrder {
51
+ //! Little endian.
52
+ kLE = 0,
53
+ //! Big endian.
54
+ kBE = 1,
55
+ //! Native byte order of the target architecture.
56
+ kNative = ASMJIT_ARCH_LE ? kLE : kBE,
57
+ //! Swapped byte order of the target architecture.
58
+ kSwapped = ASMJIT_ARCH_LE ? kBE : kLE
59
+ };
60
+
61
+ //! A policy that can be used with some `reset()` member functions.
62
+ enum class ResetPolicy : uint32_t {
63
+ //! Soft reset, doesn't deallocate memory (default).
64
+ kSoft = 0,
65
+ //! Hard reset, releases all memory used, if any.
66
+ kHard = 1
67
+ };
68
+
69
+ //! Contains typedefs, constants, and variables used globally by AsmJit.
70
+ namespace Globals {
71
+
72
+ //! Host memory allocator overhead.
73
+ static constexpr uint32_t kAllocOverhead = uint32_t(sizeof(intptr_t) * 4);
74
+
75
+ //! Host memory allocator alignment.
76
+ static constexpr uint32_t kAllocAlignment = 8;
77
+
78
+ //! Aggressive growing strategy threshold.
79
+ static constexpr uint32_t kGrowThreshold = 1024 * 1024 * 16;
80
+
81
+ //! Maximum depth of RB-Tree is:
82
+ //!
83
+ //! `2 * log2(n + 1)`
84
+ //!
85
+ //! Size of RB node is at least two pointers (without data), so a theoretical architecture limit would be:
86
+ //!
87
+ //! `2 * log2(addressableMemorySize / sizeof(Node) + 1)`
88
+ //!
89
+ //! Which yields 30 on 32-bit arch and 61 on 64-bit arch. The final value was adjusted by +1 for safety reasons.
90
+ static constexpr uint32_t kMaxTreeHeight = (ASMJIT_ARCH_BITS == 32 ? 30 : 61) + 1;
91
+
92
+ //! Maximum number of operands per a single instruction.
93
+ static constexpr uint32_t kMaxOpCount = 6;
94
+
95
+ //! Maximum arguments of a function supported by the Compiler / Function API.
96
+ static constexpr uint32_t kMaxFuncArgs = 16;
97
+
98
+ //! The number of values that can be assigned to a single function argument or
99
+ //! return value.
100
+ static constexpr uint32_t kMaxValuePack = 4;
101
+
102
+ //! Maximum number of physical registers AsmJit can use per register group.
103
+ static constexpr uint32_t kMaxPhysRegs = 32;
104
+
105
+ //! Maximum alignment.
106
+ static constexpr uint32_t kMaxAlignment = 64;
107
+
108
+ //! Maximum label or symbol size in bytes.
109
+ static constexpr uint32_t kMaxLabelNameSize = 2048;
110
+
111
+ //! Maximum section name size.
112
+ static constexpr uint32_t kMaxSectionNameSize = 35;
113
+
114
+ //! Maximum size of comment.
115
+ static constexpr uint32_t kMaxCommentSize = 1024;
116
+
117
+ //! Invalid identifier.
118
+ static constexpr uint32_t kInvalidId = 0xFFFFFFFFu;
119
+
120
+ //! Returned by `indexOf()` and similar when working with containers that use 32-bit index/size.
121
+ static constexpr uint32_t kNotFound = 0xFFFFFFFFu;
122
+
123
+ //! Invalid base address.
124
+ static constexpr uint64_t kNoBaseAddress = ~uint64_t(0);
125
+
126
+ //! Number of virtual register groups.
127
+ static constexpr uint32_t kNumVirtGroups = 4;
128
+
129
+ struct Init_ {};
130
+ struct NoInit_ {};
131
+
132
+ static const constexpr Init_ Init {};
133
+ static const constexpr NoInit_ NoInit {};
134
+
135
+ } // {Globals}
136
+
137
+ template<typename Func>
138
+ static inline Func ptr_as_func(void* func) noexcept { return Support::ptr_cast_impl<Func, void*>(func); }
139
+
140
+ template<typename Func>
141
+ static inline void* func_as_ptr(Func func) noexcept { return Support::ptr_cast_impl<void*, Func>(func); }
142
+
143
+ //! \}
144
+
145
+ //! \addtogroup asmjit_error_handling
146
+ //! \{
147
+
148
+ //! AsmJit error type (uint32_t).
149
+ typedef uint32_t Error;
150
+
151
+ //! AsmJit error codes.
152
+ enum ErrorCode : uint32_t {
153
+ // @EnumValuesBegin{"enum": "ErrorCode"}@
154
+
155
+ //! No error (success).
156
+ kErrorOk = 0,
157
+
158
+ //! Out of memory.
159
+ kErrorOutOfMemory,
160
+
161
+ //! Invalid argument.
162
+ kErrorInvalidArgument,
163
+
164
+ //! Invalid state.
165
+ //!
166
+ //! If this error is returned it means that either you are doing something wrong or AsmJit caught itself by
167
+ //! doing something wrong. This error should never be ignored.
168
+ kErrorInvalidState,
169
+
170
+ //! Invalid or incompatible architecture.
171
+ kErrorInvalidArch,
172
+
173
+ //! The object is not initialized.
174
+ kErrorNotInitialized,
175
+ //! The object is already initialized.
176
+ kErrorAlreadyInitialized,
177
+
178
+ //! Built-in feature was disabled at compile time and it's not available.
179
+ kErrorFeatureNotEnabled,
180
+
181
+ //! Too many handles (Windows) or file descriptors (Unix/Posix).
182
+ kErrorTooManyHandles,
183
+ //! Code generated is larger than allowed.
184
+ kErrorTooLarge,
185
+
186
+ //! No code generated.
187
+ //!
188
+ //! Returned by runtime if the \ref CodeHolder contains no code.
189
+ kErrorNoCodeGenerated,
190
+
191
+ //! Invalid directive.
192
+ kErrorInvalidDirective,
193
+ //! Attempt to use uninitialized label.
194
+ kErrorInvalidLabel,
195
+ //! Label index overflow - a single \ref BaseAssembler instance can hold almost 2^32 (4 billion) labels. If
196
+ //! there is an attempt to create more labels then this error is returned.
197
+ kErrorTooManyLabels,
198
+ //! Label is already bound.
199
+ kErrorLabelAlreadyBound,
200
+ //! Label is already defined (named labels).
201
+ kErrorLabelAlreadyDefined,
202
+ //! Label name is too long.
203
+ kErrorLabelNameTooLong,
204
+ //! Label must always be local if it's anonymous (without a name).
205
+ kErrorInvalidLabelName,
206
+ //! Parent id passed to \ref CodeHolder::newNamedLabelEntry() was either invalid or parent is not supported
207
+ //! by the requested `LabelType`.
208
+ kErrorInvalidParentLabel,
209
+
210
+ //! Invalid section.
211
+ kErrorInvalidSection,
212
+ //! Too many sections (section index overflow).
213
+ kErrorTooManySections,
214
+ //! Invalid section name (most probably too long).
215
+ kErrorInvalidSectionName,
216
+
217
+ //! Relocation index overflow (too many relocations).
218
+ kErrorTooManyRelocations,
219
+ //! Invalid relocation entry.
220
+ kErrorInvalidRelocEntry,
221
+ //! Reloc entry contains address that is out of range (unencodable).
222
+ kErrorRelocOffsetOutOfRange,
223
+
224
+ //! Invalid assignment to a register, function argument, or function return value.
225
+ kErrorInvalidAssignment,
226
+ //! Invalid instruction.
227
+ kErrorInvalidInstruction,
228
+ //! Invalid register type.
229
+ kErrorInvalidRegType,
230
+ //! Invalid register group.
231
+ kErrorInvalidRegGroup,
232
+ //! Invalid physical register id.
233
+ kErrorInvalidPhysId,
234
+ //! Invalid virtual register id.
235
+ kErrorInvalidVirtId,
236
+ //! Invalid element index (ARM).
237
+ kErrorInvalidElementIndex,
238
+ //! Invalid prefix combination (X86|X64).
239
+ kErrorInvalidPrefixCombination,
240
+ //! Invalid LOCK prefix (X86|X64).
241
+ kErrorInvalidLockPrefix,
242
+ //! Invalid XACQUIRE prefix (X86|X64).
243
+ kErrorInvalidXAcquirePrefix,
244
+ //! Invalid XRELEASE prefix (X86|X64).
245
+ kErrorInvalidXReleasePrefix,
246
+ //! Invalid REP prefix (X86|X64).
247
+ kErrorInvalidRepPrefix,
248
+ //! Invalid REX prefix (X86|X64).
249
+ kErrorInvalidRexPrefix,
250
+ //! Invalid {...} register (X86|X64).
251
+ kErrorInvalidExtraReg,
252
+ //! Invalid {k} use (not supported by the instruction) (X86|X64).
253
+ kErrorInvalidKMaskUse,
254
+ //! Invalid {k}{z} use (not supported by the instruction) (X86|X64).
255
+ kErrorInvalidKZeroUse,
256
+ //! Invalid broadcast - Currently only related to invalid use of AVX-512 {1tox} (X86|X64).
257
+ kErrorInvalidBroadcast,
258
+ //! Invalid 'embedded-rounding' {er} or 'suppress-all-exceptions' {sae} (AVX-512) (X86|X64).
259
+ kErrorInvalidEROrSAE,
260
+ //! Invalid address used (not encodable).
261
+ kErrorInvalidAddress,
262
+ //! Invalid index register used in memory address (not encodable).
263
+ kErrorInvalidAddressIndex,
264
+ //! Invalid address scale (not encodable).
265
+ kErrorInvalidAddressScale,
266
+ //! Invalid use of 64-bit address.
267
+ kErrorInvalidAddress64Bit,
268
+ //! Invalid use of 64-bit address that require 32-bit zero-extension (X64).
269
+ kErrorInvalidAddress64BitZeroExtension,
270
+ //! Invalid displacement (not encodable).
271
+ kErrorInvalidDisplacement,
272
+ //! Invalid segment (X86).
273
+ kErrorInvalidSegment,
274
+
275
+ //! Invalid immediate (out of bounds on X86 and invalid pattern on ARM).
276
+ kErrorInvalidImmediate,
277
+
278
+ //! Invalid operand size.
279
+ kErrorInvalidOperandSize,
280
+ //! Ambiguous operand size (memory has zero size while it's required to determine the operation type.
281
+ kErrorAmbiguousOperandSize,
282
+ //! Mismatching operand size (size of multiple operands doesn't match the operation size).
283
+ kErrorOperandSizeMismatch,
284
+
285
+ //! Invalid option.
286
+ kErrorInvalidOption,
287
+ //! Option already defined.
288
+ kErrorOptionAlreadyDefined,
289
+
290
+ //! Invalid TypeId.
291
+ kErrorInvalidTypeId,
292
+ //! Invalid use of a 8-bit GPB-HIGH register.
293
+ kErrorInvalidUseOfGpbHi,
294
+ //! Invalid use of a 64-bit GPQ register in 32-bit mode.
295
+ kErrorInvalidUseOfGpq,
296
+ //! Invalid use of an 80-bit float (\ref TypeId::kFloat80).
297
+ kErrorInvalidUseOfF80,
298
+ //! Instruction requires the use of consecutive registers, but registers in operands weren't (AVX512, ASIMD load/store, etc...).
299
+ kErrorNotConsecutiveRegs,
300
+ //! Failed to allocate consecutive registers - allocable registers either too restricted or a bug in RW info.
301
+ kErrorConsecutiveRegsAllocation,
302
+
303
+ //! Illegal virtual register - reported by instruction validation.
304
+ kErrorIllegalVirtReg,
305
+ //! AsmJit cannot create more virtual registers.
306
+ kErrorTooManyVirtRegs,
307
+
308
+ //! AsmJit requires a physical register, but no one is available.
309
+ kErrorNoMorePhysRegs,
310
+ //! A variable has been assigned more than once to a function argument (BaseCompiler).
311
+ kErrorOverlappedRegs,
312
+ //! Invalid register to hold stack arguments offset.
313
+ kErrorOverlappingStackRegWithRegArg,
314
+
315
+ //! Unbound label cannot be evaluated by expression.
316
+ kErrorExpressionLabelNotBound,
317
+ //! Arithmetic overflow during expression evaluation.
318
+ kErrorExpressionOverflow,
319
+
320
+ //! Failed to open anonymous memory handle or file descriptor.
321
+ kErrorFailedToOpenAnonymousMemory,
322
+
323
+ // @EnumValuesEnd@
324
+
325
+ //! Count of AsmJit error codes.
326
+ kErrorCount
327
+ };
328
+
329
+ //! Debugging utilities.
330
+ namespace DebugUtils {
331
+
332
+ //! \cond INTERNAL
333
+ //! Used to silence warnings about unused arguments or variables.
334
+ template<typename... Args>
335
+ static inline void unused(Args&&...) noexcept {}
336
+ //! \endcond
337
+
338
+ //! Returns the error `err` passed.
339
+ //!
340
+ //! Provided for debugging purposes. Putting a breakpoint inside `errored` can help with tracing the origin of any
341
+ //! error reported / returned by AsmJit.
342
+ static constexpr Error errored(Error err) noexcept { return err; }
343
+
344
+ //! Returns a printable version of `asmjit::Error` code.
345
+ ASMJIT_API const char* errorAsString(Error err) noexcept;
346
+
347
+ //! Called to output debugging message(s).
348
+ ASMJIT_API void debugOutput(const char* str) noexcept;
349
+
350
+ //! Called on assertion failure.
351
+ //!
352
+ //! \param file Source file name where it happened.
353
+ //! \param line Line in the source file.
354
+ //! \param msg Message to display.
355
+ //!
356
+ //! If you have problems with assertion failures a breakpoint can be put at \ref assertionFailed() function
357
+ //! (asmjit/core/globals.cpp). A call stack will be available when such assertion failure is triggered. AsmJit
358
+ //! always returns errors on failures, assertions are a last resort and usually mean unrecoverable state due to out
359
+ //! of range array access or totally invalid arguments like nullptr where a valid pointer should be provided, etc...
360
+ ASMJIT_API void ASMJIT_NORETURN assertionFailed(const char* file, int line, const char* msg) noexcept;
361
+
362
+ } // {DebugUtils}
363
+
364
+ //! \def ASMJIT_ASSERT(...)
365
+ //!
366
+ //! AsmJit's own assert macro used in AsmJit code-base.
367
+ #if defined(ASMJIT_BUILD_DEBUG)
368
+ #define ASMJIT_ASSERT(...) \
369
+ do { \
370
+ if (ASMJIT_LIKELY(__VA_ARGS__)) \
371
+ break; \
372
+ ::asmjit::DebugUtils::assertionFailed(__FILE__, __LINE__, #__VA_ARGS__); \
373
+ } while (0)
374
+ #else
375
+ #define ASMJIT_ASSERT(...) ((void)0)
376
+ #endif
377
+
378
+ //! \def ASMJIT_PROPAGATE(...)
379
+ //!
380
+ //! Propagates a possible `Error` produced by `...` to the caller by returning the error immediately. Used by AsmJit
381
+ //! internally, but kept public for users that want to use the same technique to propagate errors to the caller.
382
+ #define ASMJIT_PROPAGATE(...) \
383
+ do { \
384
+ ::asmjit::Error _err = __VA_ARGS__; \
385
+ if (ASMJIT_UNLIKELY(_err)) \
386
+ return _err; \
387
+ } while (0)
388
+
389
+ //! \}
390
+
391
+ ASMJIT_END_NAMESPACE
392
+
393
+ #endif // ASMJIT_CORE_GLOBALS_H_INCLUDED
@@ -0,0 +1,113 @@
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 "../core/api-build_p.h"
7
+ #include "../core/archtraits.h"
8
+ #include "../core/inst.h"
9
+
10
+ #if !defined(ASMJIT_NO_X86)
11
+ #include "../x86/x86instapi_p.h"
12
+ #endif
13
+
14
+ #if !defined(ASMJIT_NO_AARCH64)
15
+ #include "../arm/a64instapi_p.h"
16
+ #endif
17
+
18
+ ASMJIT_BEGIN_NAMESPACE
19
+
20
+ // InstAPI - InstId <-> String
21
+ // ===========================
22
+
23
+ #ifndef ASMJIT_NO_TEXT
24
+ Error InstAPI::instIdToString(Arch arch, InstId instId, String& output) noexcept {
25
+ #if !defined(ASMJIT_NO_X86)
26
+ if (Environment::isFamilyX86(arch))
27
+ return x86::InstInternal::instIdToString(arch, instId, output);
28
+ #endif
29
+
30
+ #if !defined(ASMJIT_NO_AARCH64)
31
+ if (Environment::isFamilyAArch64(arch))
32
+ return a64::InstInternal::instIdToString(arch, instId, output);
33
+ #endif
34
+
35
+ return DebugUtils::errored(kErrorInvalidArch);
36
+ }
37
+
38
+ InstId InstAPI::stringToInstId(Arch arch, const char* s, size_t len) noexcept {
39
+ #if !defined(ASMJIT_NO_X86)
40
+ if (Environment::isFamilyX86(arch))
41
+ return x86::InstInternal::stringToInstId(arch, s, len);
42
+ #endif
43
+
44
+ #if !defined(ASMJIT_NO_AARCH64)
45
+ if (Environment::isFamilyAArch64(arch))
46
+ return a64::InstInternal::stringToInstId(arch, s, len);
47
+ #endif
48
+
49
+ return 0;
50
+ }
51
+ #endif // !ASMJIT_NO_TEXT
52
+
53
+ // InstAPI - Validate
54
+ // ==================
55
+
56
+ #ifndef ASMJIT_NO_VALIDATION
57
+ Error InstAPI::validate(Arch arch, const BaseInst& inst, const Operand_* operands, size_t opCount, ValidationFlags validationFlags) noexcept {
58
+ #if !defined(ASMJIT_NO_X86)
59
+ if (Environment::isFamilyX86(arch))
60
+ return x86::InstInternal::validate(arch, inst, operands, opCount, validationFlags);
61
+ #endif
62
+
63
+ #if !defined(ASMJIT_NO_AARCH64)
64
+ if (Environment::isFamilyAArch64(arch))
65
+ return a64::InstInternal::validate(arch, inst, operands, opCount, validationFlags);
66
+ #endif
67
+
68
+ return DebugUtils::errored(kErrorInvalidArch);
69
+ }
70
+ #endif // !ASMJIT_NO_VALIDATION
71
+
72
+ // InstAPI - QueryRWInfo
73
+ // =====================
74
+
75
+ #ifndef ASMJIT_NO_INTROSPECTION
76
+ Error InstAPI::queryRWInfo(Arch arch, const BaseInst& inst, const Operand_* operands, size_t opCount, InstRWInfo* out) noexcept {
77
+ if (ASMJIT_UNLIKELY(opCount > Globals::kMaxOpCount))
78
+ return DebugUtils::errored(kErrorInvalidArgument);
79
+
80
+ #if !defined(ASMJIT_NO_X86)
81
+ if (Environment::isFamilyX86(arch))
82
+ return x86::InstInternal::queryRWInfo(arch, inst, operands, opCount, out);
83
+ #endif
84
+
85
+ #if !defined(ASMJIT_NO_AARCH64)
86
+ if (Environment::isFamilyAArch64(arch))
87
+ return a64::InstInternal::queryRWInfo(arch, inst, operands, opCount, out);
88
+ #endif
89
+
90
+ return DebugUtils::errored(kErrorInvalidArch);
91
+ }
92
+ #endif // !ASMJIT_NO_INTROSPECTION
93
+
94
+ // InstAPI - QueryFeatures
95
+ // =======================
96
+
97
+ #ifndef ASMJIT_NO_INTROSPECTION
98
+ Error InstAPI::queryFeatures(Arch arch, const BaseInst& inst, const Operand_* operands, size_t opCount, CpuFeatures* out) noexcept {
99
+ #if !defined(ASMJIT_NO_X86)
100
+ if (Environment::isFamilyX86(arch))
101
+ return x86::InstInternal::queryFeatures(arch, inst, operands, opCount, out);
102
+ #endif
103
+
104
+ #if !defined(ASMJIT_NO_AARCH64)
105
+ if (Environment::isFamilyAArch64(arch))
106
+ return a64::InstInternal::queryFeatures(arch, inst, operands, opCount, out);
107
+ #endif
108
+
109
+ return DebugUtils::errored(kErrorInvalidArch);
110
+ }
111
+ #endif // !ASMJIT_NO_INTROSPECTION
112
+
113
+ ASMJIT_END_NAMESPACE