asmjit 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/asmjit.gemspec +1 -1
- data/ext/asmjit/asmjit/.editorconfig +10 -0
- data/ext/asmjit/asmjit/.github/FUNDING.yml +1 -0
- data/ext/asmjit/asmjit/.github/workflows/build-config.json +47 -0
- data/ext/asmjit/asmjit/.github/workflows/build.yml +156 -0
- data/ext/asmjit/asmjit/.gitignore +6 -0
- data/ext/asmjit/asmjit/CMakeLists.txt +611 -0
- data/ext/asmjit/asmjit/LICENSE.md +17 -0
- data/ext/asmjit/asmjit/README.md +69 -0
- data/ext/asmjit/asmjit/src/asmjit/a64.h +62 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64archtraits_p.h +81 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64assembler.cpp +5115 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64assembler.h +72 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64builder.cpp +51 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64builder.h +57 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64compiler.cpp +60 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64compiler.h +247 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64emithelper.cpp +464 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64emithelper_p.h +50 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64emitter.h +1228 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64formatter.cpp +298 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64formatter_p.h +59 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64func.cpp +189 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64func_p.h +33 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64globals.h +1894 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64instapi.cpp +278 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64instapi_p.h +41 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb.cpp +1957 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb.h +74 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb_p.h +876 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64operand.cpp +85 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64operand.h +312 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64rapass.cpp +852 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64rapass_p.h +105 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64utils.h +179 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/armformatter.cpp +143 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/armformatter_p.h +44 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/armglobals.h +21 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/armoperand.h +621 -0
- data/ext/asmjit/asmjit/src/asmjit/arm.h +62 -0
- data/ext/asmjit/asmjit/src/asmjit/asmjit-scope-begin.h +17 -0
- data/ext/asmjit/asmjit/src/asmjit/asmjit-scope-end.h +9 -0
- data/ext/asmjit/asmjit/src/asmjit/asmjit.h +33 -0
- data/ext/asmjit/asmjit/src/asmjit/core/api-build_p.h +55 -0
- data/ext/asmjit/asmjit/src/asmjit/core/api-config.h +613 -0
- data/ext/asmjit/asmjit/src/asmjit/core/archcommons.h +229 -0
- data/ext/asmjit/asmjit/src/asmjit/core/archtraits.cpp +160 -0
- data/ext/asmjit/asmjit/src/asmjit/core/archtraits.h +290 -0
- data/ext/asmjit/asmjit/src/asmjit/core/assembler.cpp +406 -0
- data/ext/asmjit/asmjit/src/asmjit/core/assembler.h +129 -0
- data/ext/asmjit/asmjit/src/asmjit/core/builder.cpp +889 -0
- data/ext/asmjit/asmjit/src/asmjit/core/builder.h +1391 -0
- data/ext/asmjit/asmjit/src/asmjit/core/codebuffer.h +113 -0
- data/ext/asmjit/asmjit/src/asmjit/core/codeholder.cpp +1149 -0
- data/ext/asmjit/asmjit/src/asmjit/core/codeholder.h +1035 -0
- data/ext/asmjit/asmjit/src/asmjit/core/codewriter.cpp +175 -0
- data/ext/asmjit/asmjit/src/asmjit/core/codewriter_p.h +179 -0
- data/ext/asmjit/asmjit/src/asmjit/core/compiler.cpp +582 -0
- data/ext/asmjit/asmjit/src/asmjit/core/compiler.h +737 -0
- data/ext/asmjit/asmjit/src/asmjit/core/compilerdefs.h +173 -0
- data/ext/asmjit/asmjit/src/asmjit/core/constpool.cpp +363 -0
- data/ext/asmjit/asmjit/src/asmjit/core/constpool.h +250 -0
- data/ext/asmjit/asmjit/src/asmjit/core/cpuinfo.cpp +1162 -0
- data/ext/asmjit/asmjit/src/asmjit/core/cpuinfo.h +813 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emithelper.cpp +323 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emithelper_p.h +58 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emitter.cpp +333 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emitter.h +741 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emitterutils.cpp +129 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emitterutils_p.h +89 -0
- data/ext/asmjit/asmjit/src/asmjit/core/environment.cpp +46 -0
- data/ext/asmjit/asmjit/src/asmjit/core/environment.h +508 -0
- data/ext/asmjit/asmjit/src/asmjit/core/errorhandler.cpp +14 -0
- data/ext/asmjit/asmjit/src/asmjit/core/errorhandler.h +228 -0
- data/ext/asmjit/asmjit/src/asmjit/core/formatter.cpp +584 -0
- data/ext/asmjit/asmjit/src/asmjit/core/formatter.h +247 -0
- data/ext/asmjit/asmjit/src/asmjit/core/formatter_p.h +34 -0
- data/ext/asmjit/asmjit/src/asmjit/core/func.cpp +286 -0
- data/ext/asmjit/asmjit/src/asmjit/core/func.h +1445 -0
- data/ext/asmjit/asmjit/src/asmjit/core/funcargscontext.cpp +293 -0
- data/ext/asmjit/asmjit/src/asmjit/core/funcargscontext_p.h +199 -0
- data/ext/asmjit/asmjit/src/asmjit/core/globals.cpp +133 -0
- data/ext/asmjit/asmjit/src/asmjit/core/globals.h +393 -0
- data/ext/asmjit/asmjit/src/asmjit/core/inst.cpp +113 -0
- data/ext/asmjit/asmjit/src/asmjit/core/inst.h +772 -0
- data/ext/asmjit/asmjit/src/asmjit/core/jitallocator.cpp +1242 -0
- data/ext/asmjit/asmjit/src/asmjit/core/jitallocator.h +261 -0
- data/ext/asmjit/asmjit/src/asmjit/core/jitruntime.cpp +80 -0
- data/ext/asmjit/asmjit/src/asmjit/core/jitruntime.h +89 -0
- data/ext/asmjit/asmjit/src/asmjit/core/logger.cpp +69 -0
- data/ext/asmjit/asmjit/src/asmjit/core/logger.h +198 -0
- data/ext/asmjit/asmjit/src/asmjit/core/misc_p.h +33 -0
- data/ext/asmjit/asmjit/src/asmjit/core/operand.cpp +132 -0
- data/ext/asmjit/asmjit/src/asmjit/core/operand.h +1611 -0
- data/ext/asmjit/asmjit/src/asmjit/core/osutils.cpp +84 -0
- data/ext/asmjit/asmjit/src/asmjit/core/osutils.h +61 -0
- data/ext/asmjit/asmjit/src/asmjit/core/osutils_p.h +68 -0
- data/ext/asmjit/asmjit/src/asmjit/core/raassignment_p.h +418 -0
- data/ext/asmjit/asmjit/src/asmjit/core/rabuilders_p.h +612 -0
- data/ext/asmjit/asmjit/src/asmjit/core/radefs_p.h +1204 -0
- data/ext/asmjit/asmjit/src/asmjit/core/ralocal.cpp +1166 -0
- data/ext/asmjit/asmjit/src/asmjit/core/ralocal_p.h +254 -0
- data/ext/asmjit/asmjit/src/asmjit/core/rapass.cpp +1969 -0
- data/ext/asmjit/asmjit/src/asmjit/core/rapass_p.h +1183 -0
- data/ext/asmjit/asmjit/src/asmjit/core/rastack.cpp +184 -0
- data/ext/asmjit/asmjit/src/asmjit/core/rastack_p.h +171 -0
- data/ext/asmjit/asmjit/src/asmjit/core/string.cpp +559 -0
- data/ext/asmjit/asmjit/src/asmjit/core/string.h +372 -0
- data/ext/asmjit/asmjit/src/asmjit/core/support.cpp +494 -0
- data/ext/asmjit/asmjit/src/asmjit/core/support.h +1773 -0
- data/ext/asmjit/asmjit/src/asmjit/core/target.cpp +14 -0
- data/ext/asmjit/asmjit/src/asmjit/core/target.h +53 -0
- data/ext/asmjit/asmjit/src/asmjit/core/type.cpp +74 -0
- data/ext/asmjit/asmjit/src/asmjit/core/type.h +419 -0
- data/ext/asmjit/asmjit/src/asmjit/core/virtmem.cpp +722 -0
- data/ext/asmjit/asmjit/src/asmjit/core/virtmem.h +242 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zone.cpp +353 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zone.h +615 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonehash.cpp +309 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonehash.h +186 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonelist.cpp +163 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonelist.h +209 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonestack.cpp +176 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonestack.h +239 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonestring.h +120 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonetree.cpp +99 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonetree.h +380 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonevector.cpp +356 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonevector.h +690 -0
- data/ext/asmjit/asmjit/src/asmjit/core.h +1861 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86archtraits_p.h +148 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86assembler.cpp +5110 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86assembler.h +685 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86builder.cpp +52 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86builder.h +351 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86compiler.cpp +61 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86compiler.h +721 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86emithelper.cpp +619 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86emithelper_p.h +60 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86emitter.h +4315 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86formatter.cpp +944 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86formatter_p.h +58 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86func.cpp +503 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86func_p.h +33 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86globals.h +2169 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86instapi.cpp +1732 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86instapi_p.h +41 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb.cpp +4427 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb.h +563 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb_p.h +311 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86opcode_p.h +436 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86operand.cpp +231 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86operand.h +1085 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86rapass.cpp +1509 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86rapass_p.h +94 -0
- data/ext/asmjit/asmjit/src/asmjit/x86.h +93 -0
- data/ext/asmjit/asmjit/src/asmjit.natvis +245 -0
- data/ext/asmjit/asmjit/test/asmjit_test_assembler.cpp +84 -0
- data/ext/asmjit/asmjit/test/asmjit_test_assembler.h +85 -0
- data/ext/asmjit/asmjit/test/asmjit_test_assembler_a64.cpp +4006 -0
- data/ext/asmjit/asmjit/test/asmjit_test_assembler_x64.cpp +17833 -0
- data/ext/asmjit/asmjit/test/asmjit_test_assembler_x86.cpp +8300 -0
- data/ext/asmjit/asmjit/test/asmjit_test_compiler.cpp +253 -0
- data/ext/asmjit/asmjit/test/asmjit_test_compiler.h +73 -0
- data/ext/asmjit/asmjit/test/asmjit_test_compiler_a64.cpp +690 -0
- data/ext/asmjit/asmjit/test/asmjit_test_compiler_x86.cpp +4317 -0
- data/ext/asmjit/asmjit/test/asmjit_test_emitters.cpp +197 -0
- data/ext/asmjit/asmjit/test/asmjit_test_instinfo.cpp +181 -0
- data/ext/asmjit/asmjit/test/asmjit_test_misc.h +257 -0
- data/ext/asmjit/asmjit/test/asmjit_test_perf.cpp +62 -0
- data/ext/asmjit/asmjit/test/asmjit_test_perf.h +61 -0
- data/ext/asmjit/asmjit/test/asmjit_test_perf_a64.cpp +699 -0
- data/ext/asmjit/asmjit/test/asmjit_test_perf_x86.cpp +5032 -0
- data/ext/asmjit/asmjit/test/asmjit_test_unit.cpp +172 -0
- data/ext/asmjit/asmjit/test/asmjit_test_x86_sections.cpp +172 -0
- data/ext/asmjit/asmjit/test/asmjitutils.h +38 -0
- data/ext/asmjit/asmjit/test/broken.cpp +312 -0
- data/ext/asmjit/asmjit/test/broken.h +148 -0
- data/ext/asmjit/asmjit/test/cmdline.h +61 -0
- data/ext/asmjit/asmjit/test/performancetimer.h +41 -0
- data/ext/asmjit/asmjit/tools/configure-makefiles.sh +13 -0
- data/ext/asmjit/asmjit/tools/configure-ninja.sh +13 -0
- data/ext/asmjit/asmjit/tools/configure-sanitizers.sh +13 -0
- data/ext/asmjit/asmjit/tools/configure-vs2019-x64.bat +2 -0
- data/ext/asmjit/asmjit/tools/configure-vs2019-x86.bat +2 -0
- data/ext/asmjit/asmjit/tools/configure-vs2022-x64.bat +2 -0
- data/ext/asmjit/asmjit/tools/configure-vs2022-x86.bat +2 -0
- data/ext/asmjit/asmjit/tools/configure-xcode.sh +8 -0
- data/ext/asmjit/asmjit/tools/enumgen.js +417 -0
- data/ext/asmjit/asmjit/tools/enumgen.sh +3 -0
- data/ext/asmjit/asmjit/tools/tablegen-arm.js +365 -0
- data/ext/asmjit/asmjit/tools/tablegen-arm.sh +3 -0
- data/ext/asmjit/asmjit/tools/tablegen-x86.js +2638 -0
- data/ext/asmjit/asmjit/tools/tablegen-x86.sh +3 -0
- data/ext/asmjit/asmjit/tools/tablegen.js +947 -0
- data/ext/asmjit/asmjit/tools/tablegen.sh +4 -0
- data/ext/asmjit/asmjit.cc +18 -0
- data/lib/asmjit/version.rb +1 -1
- metadata +197 -2
@@ -0,0 +1,584 @@
|
|
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
|
+
#ifndef ASMJIT_NO_LOGGING
|
8
|
+
|
9
|
+
#include "../core/archtraits.h"
|
10
|
+
#include "../core/builder.h"
|
11
|
+
#include "../core/codeholder.h"
|
12
|
+
#include "../core/compiler.h"
|
13
|
+
#include "../core/emitter.h"
|
14
|
+
#include "../core/formatter_p.h"
|
15
|
+
#include "../core/string.h"
|
16
|
+
#include "../core/support.h"
|
17
|
+
#include "../core/type.h"
|
18
|
+
|
19
|
+
#if !defined(ASMJIT_NO_X86)
|
20
|
+
#include "../x86/x86formatter_p.h"
|
21
|
+
#endif
|
22
|
+
|
23
|
+
#if !defined(ASMJIT_NO_AARCH64)
|
24
|
+
#include "../arm/a64formatter_p.h"
|
25
|
+
#endif
|
26
|
+
|
27
|
+
ASMJIT_BEGIN_NAMESPACE
|
28
|
+
|
29
|
+
#if defined(ASMJIT_NO_COMPILER)
|
30
|
+
class VirtReg;
|
31
|
+
#endif
|
32
|
+
|
33
|
+
namespace Formatter {
|
34
|
+
|
35
|
+
static const char wordNameTable[][8] = {
|
36
|
+
"db",
|
37
|
+
"dw",
|
38
|
+
"dd",
|
39
|
+
"dq",
|
40
|
+
"byte",
|
41
|
+
"half",
|
42
|
+
"word",
|
43
|
+
"hword",
|
44
|
+
"dword",
|
45
|
+
"qword",
|
46
|
+
"xword",
|
47
|
+
"short",
|
48
|
+
"long",
|
49
|
+
"quad"
|
50
|
+
};
|
51
|
+
|
52
|
+
|
53
|
+
Error formatTypeId(String& sb, TypeId typeId) noexcept {
|
54
|
+
if (typeId == TypeId::kVoid)
|
55
|
+
return sb.append("void");
|
56
|
+
|
57
|
+
if (!TypeUtils::isValid(typeId))
|
58
|
+
return sb.append("unknown");
|
59
|
+
|
60
|
+
const char* typeName = "unknown";
|
61
|
+
uint32_t typeSize = TypeUtils::sizeOf(typeId);
|
62
|
+
TypeId scalarType = TypeUtils::scalarOf(typeId);
|
63
|
+
|
64
|
+
switch (scalarType) {
|
65
|
+
case TypeId::kIntPtr : typeName = "intptr" ; break;
|
66
|
+
case TypeId::kUIntPtr: typeName = "uintptr"; break;
|
67
|
+
case TypeId::kInt8 : typeName = "int8" ; break;
|
68
|
+
case TypeId::kUInt8 : typeName = "uint8" ; break;
|
69
|
+
case TypeId::kInt16 : typeName = "int16" ; break;
|
70
|
+
case TypeId::kUInt16 : typeName = "uint16" ; break;
|
71
|
+
case TypeId::kInt32 : typeName = "int32" ; break;
|
72
|
+
case TypeId::kUInt32 : typeName = "uint32" ; break;
|
73
|
+
case TypeId::kInt64 : typeName = "int64" ; break;
|
74
|
+
case TypeId::kUInt64 : typeName = "uint64" ; break;
|
75
|
+
case TypeId::kFloat32: typeName = "float32"; break;
|
76
|
+
case TypeId::kFloat64: typeName = "float64"; break;
|
77
|
+
case TypeId::kFloat80: typeName = "float80"; break;
|
78
|
+
case TypeId::kMask8 : typeName = "mask8" ; break;
|
79
|
+
case TypeId::kMask16 : typeName = "mask16" ; break;
|
80
|
+
case TypeId::kMask32 : typeName = "mask32" ; break;
|
81
|
+
case TypeId::kMask64 : typeName = "mask64" ; break;
|
82
|
+
case TypeId::kMmx32 : typeName = "mmx32" ; break;
|
83
|
+
case TypeId::kMmx64 : typeName = "mmx64" ; break;
|
84
|
+
|
85
|
+
default:
|
86
|
+
typeName = "unknown";
|
87
|
+
break;
|
88
|
+
}
|
89
|
+
|
90
|
+
uint32_t baseSize = TypeUtils::sizeOf(scalarType);
|
91
|
+
if (typeSize > baseSize) {
|
92
|
+
uint32_t count = typeSize / baseSize;
|
93
|
+
return sb.appendFormat("%sx%u", typeName, unsigned(count));
|
94
|
+
}
|
95
|
+
else {
|
96
|
+
return sb.append(typeName);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
Error formatFeature(
|
101
|
+
String& sb,
|
102
|
+
Arch arch,
|
103
|
+
uint32_t featureId) noexcept {
|
104
|
+
|
105
|
+
#if !defined(ASMJIT_NO_X86)
|
106
|
+
if (Environment::isFamilyX86(arch))
|
107
|
+
return x86::FormatterInternal::formatFeature(sb, featureId);
|
108
|
+
#endif
|
109
|
+
|
110
|
+
#if !defined(ASMJIT_NO_AARCH32) && !defined(ASMJIT_NO_AARCH64)
|
111
|
+
if (Environment::isFamilyARM(arch))
|
112
|
+
return arm::FormatterInternal::formatFeature(sb, featureId);
|
113
|
+
#endif
|
114
|
+
|
115
|
+
return kErrorInvalidArch;
|
116
|
+
}
|
117
|
+
|
118
|
+
Error formatLabel(
|
119
|
+
String& sb,
|
120
|
+
FormatFlags formatFlags,
|
121
|
+
const BaseEmitter* emitter,
|
122
|
+
uint32_t labelId) noexcept {
|
123
|
+
|
124
|
+
DebugUtils::unused(formatFlags);
|
125
|
+
|
126
|
+
const LabelEntry* le = emitter->code()->labelEntry(labelId);
|
127
|
+
if (ASMJIT_UNLIKELY(!le))
|
128
|
+
return sb.appendFormat("<InvalidLabel:%u>", labelId);
|
129
|
+
|
130
|
+
if (le->hasName()) {
|
131
|
+
if (le->hasParent()) {
|
132
|
+
uint32_t parentId = le->parentId();
|
133
|
+
const LabelEntry* pe = emitter->code()->labelEntry(parentId);
|
134
|
+
|
135
|
+
if (ASMJIT_UNLIKELY(!pe))
|
136
|
+
ASMJIT_PROPAGATE(sb.appendFormat("<InvalidLabel:%u>", labelId));
|
137
|
+
else if (ASMJIT_UNLIKELY(!pe->hasName()))
|
138
|
+
ASMJIT_PROPAGATE(sb.appendFormat("L%u", parentId));
|
139
|
+
else
|
140
|
+
ASMJIT_PROPAGATE(sb.append(pe->name()));
|
141
|
+
|
142
|
+
ASMJIT_PROPAGATE(sb.append('.'));
|
143
|
+
}
|
144
|
+
|
145
|
+
if (le->type() == LabelType::kAnonymous)
|
146
|
+
ASMJIT_PROPAGATE(sb.appendFormat("L%u@", labelId));
|
147
|
+
return sb.append(le->name());
|
148
|
+
}
|
149
|
+
else {
|
150
|
+
return sb.appendFormat("L%u", labelId);
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
Error formatRegister(
|
155
|
+
String& sb,
|
156
|
+
FormatFlags formatFlags,
|
157
|
+
const BaseEmitter* emitter,
|
158
|
+
Arch arch,
|
159
|
+
RegType regType,
|
160
|
+
uint32_t regId) noexcept {
|
161
|
+
|
162
|
+
#if !defined(ASMJIT_NO_X86)
|
163
|
+
if (Environment::isFamilyX86(arch))
|
164
|
+
return x86::FormatterInternal::formatRegister(sb, formatFlags, emitter, arch, regType, regId);
|
165
|
+
#endif
|
166
|
+
|
167
|
+
#if !defined(ASMJIT_NO_AARCH64)
|
168
|
+
if (Environment::isFamilyAArch64(arch))
|
169
|
+
return a64::FormatterInternal::formatRegister(sb, formatFlags, emitter, arch, regType, regId);
|
170
|
+
#endif
|
171
|
+
|
172
|
+
return kErrorInvalidArch;
|
173
|
+
}
|
174
|
+
|
175
|
+
Error formatOperand(
|
176
|
+
String& sb,
|
177
|
+
FormatFlags formatFlags,
|
178
|
+
const BaseEmitter* emitter,
|
179
|
+
Arch arch,
|
180
|
+
const Operand_& op) noexcept {
|
181
|
+
|
182
|
+
#if !defined(ASMJIT_NO_X86)
|
183
|
+
if (Environment::isFamilyX86(arch))
|
184
|
+
return x86::FormatterInternal::formatOperand(sb, formatFlags, emitter, arch, op);
|
185
|
+
#endif
|
186
|
+
|
187
|
+
#if !defined(ASMJIT_NO_AARCH64)
|
188
|
+
if (Environment::isFamilyAArch64(arch))
|
189
|
+
return a64::FormatterInternal::formatOperand(sb, formatFlags, emitter, arch, op);
|
190
|
+
#endif
|
191
|
+
|
192
|
+
return kErrorInvalidArch;
|
193
|
+
}
|
194
|
+
|
195
|
+
ASMJIT_API Error formatDataType(
|
196
|
+
String& sb,
|
197
|
+
FormatFlags formatFlags,
|
198
|
+
Arch arch,
|
199
|
+
TypeId typeId) noexcept
|
200
|
+
{
|
201
|
+
DebugUtils::unused(formatFlags);
|
202
|
+
|
203
|
+
if (ASMJIT_UNLIKELY(uint32_t(arch) > uint32_t(Arch::kMaxValue)))
|
204
|
+
return DebugUtils::errored(kErrorInvalidArch);
|
205
|
+
|
206
|
+
uint32_t typeSize = TypeUtils::sizeOf(typeId);
|
207
|
+
if (typeSize == 0 || typeSize > 8)
|
208
|
+
return DebugUtils::errored(kErrorInvalidState);
|
209
|
+
|
210
|
+
uint32_t typeSizeLog2 = Support::ctz(typeSize);
|
211
|
+
return sb.append(wordNameTable[size_t(ArchTraits::byArch(arch).typeNameIdByIndex(typeSizeLog2))]);
|
212
|
+
}
|
213
|
+
|
214
|
+
static Error formatDataHelper(String& sb, const char* typeName, uint32_t typeSize, const uint8_t* data, size_t itemCount) noexcept {
|
215
|
+
sb.append('.');
|
216
|
+
sb.append(typeName);
|
217
|
+
sb.append(' ');
|
218
|
+
|
219
|
+
for (size_t i = 0; i < itemCount; i++) {
|
220
|
+
uint64_t v = 0;
|
221
|
+
|
222
|
+
if (i != 0)
|
223
|
+
ASMJIT_PROPAGATE(sb.append(", ", 2));
|
224
|
+
|
225
|
+
switch (typeSize) {
|
226
|
+
case 1: v = data[0]; break;
|
227
|
+
case 2: v = Support::readU16u(data); break;
|
228
|
+
case 4: v = Support::readU32u(data); break;
|
229
|
+
case 8: v = Support::readU64u(data); break;
|
230
|
+
}
|
231
|
+
|
232
|
+
ASMJIT_PROPAGATE(sb.appendUInt(v, 16, typeSize * 2, StringFormatFlags::kAlternate));
|
233
|
+
data += typeSize;
|
234
|
+
}
|
235
|
+
|
236
|
+
return kErrorOk;
|
237
|
+
}
|
238
|
+
|
239
|
+
Error formatData(
|
240
|
+
String& sb,
|
241
|
+
FormatFlags formatFlags,
|
242
|
+
Arch arch,
|
243
|
+
TypeId typeId, const void* data, size_t itemCount, size_t repeatCount) noexcept
|
244
|
+
{
|
245
|
+
DebugUtils::unused(formatFlags);
|
246
|
+
|
247
|
+
if (ASMJIT_UNLIKELY(!Environment::isDefinedArch(arch)))
|
248
|
+
return DebugUtils::errored(kErrorInvalidArch);
|
249
|
+
|
250
|
+
uint32_t typeSize = TypeUtils::sizeOf(typeId);
|
251
|
+
if (typeSize == 0)
|
252
|
+
return DebugUtils::errored(kErrorInvalidState);
|
253
|
+
|
254
|
+
if (!Support::isPowerOf2(typeSize)) {
|
255
|
+
itemCount *= typeSize;
|
256
|
+
typeSize = 1;
|
257
|
+
}
|
258
|
+
|
259
|
+
while (typeSize > 8u) {
|
260
|
+
typeSize >>= 1;
|
261
|
+
itemCount <<= 1;
|
262
|
+
}
|
263
|
+
|
264
|
+
uint32_t typeSizeLog2 = Support::ctz(typeSize);
|
265
|
+
const char* wordName = wordNameTable[size_t(ArchTraits::byArch(arch).typeNameIdByIndex(typeSizeLog2))];
|
266
|
+
|
267
|
+
if (repeatCount > 1)
|
268
|
+
ASMJIT_PROPAGATE(sb.appendFormat(".repeat %zu ", repeatCount));
|
269
|
+
|
270
|
+
return formatDataHelper(sb, wordName, typeSize, static_cast<const uint8_t*>(data), itemCount);
|
271
|
+
}
|
272
|
+
|
273
|
+
Error formatInstruction(
|
274
|
+
String& sb,
|
275
|
+
FormatFlags formatFlags,
|
276
|
+
const BaseEmitter* emitter,
|
277
|
+
Arch arch,
|
278
|
+
const BaseInst& inst, const Operand_* operands, size_t opCount) noexcept {
|
279
|
+
|
280
|
+
#if !defined(ASMJIT_NO_X86)
|
281
|
+
if (Environment::isFamilyX86(arch))
|
282
|
+
return x86::FormatterInternal::formatInstruction(sb, formatFlags, emitter, arch, inst, operands, opCount);
|
283
|
+
#endif
|
284
|
+
|
285
|
+
#if !defined(ASMJIT_NO_AARCH64)
|
286
|
+
if (Environment::isFamilyARM(arch))
|
287
|
+
return a64::FormatterInternal::formatInstruction(sb, formatFlags, emitter, arch, inst, operands, opCount);
|
288
|
+
#endif
|
289
|
+
|
290
|
+
return kErrorInvalidArch;
|
291
|
+
}
|
292
|
+
|
293
|
+
#ifndef ASMJIT_NO_BUILDER
|
294
|
+
|
295
|
+
#ifndef ASMJIT_NO_COMPILER
|
296
|
+
static Error formatFuncValue(String& sb, FormatFlags formatFlags, const BaseEmitter* emitter, FuncValue value) noexcept {
|
297
|
+
TypeId typeId = value.typeId();
|
298
|
+
ASMJIT_PROPAGATE(formatTypeId(sb, typeId));
|
299
|
+
|
300
|
+
if (value.isAssigned()) {
|
301
|
+
ASMJIT_PROPAGATE(sb.append('@'));
|
302
|
+
|
303
|
+
if (value.isIndirect())
|
304
|
+
ASMJIT_PROPAGATE(sb.append('['));
|
305
|
+
|
306
|
+
// NOTE: It should be either reg or stack, but never both. We
|
307
|
+
// use two IFs on purpose so if the FuncValue is both it would
|
308
|
+
// show in logs.
|
309
|
+
if (value.isReg()) {
|
310
|
+
ASMJIT_PROPAGATE(formatRegister(sb, formatFlags, emitter, emitter->arch(), value.regType(), value.regId()));
|
311
|
+
}
|
312
|
+
|
313
|
+
if (value.isStack()) {
|
314
|
+
ASMJIT_PROPAGATE(sb.appendFormat("[%d]", int(value.stackOffset())));
|
315
|
+
}
|
316
|
+
|
317
|
+
if (value.isIndirect())
|
318
|
+
ASMJIT_PROPAGATE(sb.append(']'));
|
319
|
+
}
|
320
|
+
|
321
|
+
return kErrorOk;
|
322
|
+
}
|
323
|
+
|
324
|
+
static Error formatFuncValuePack(
|
325
|
+
String& sb,
|
326
|
+
FormatFlags formatFlags,
|
327
|
+
const BaseCompiler* cc,
|
328
|
+
const FuncValuePack& pack,
|
329
|
+
const RegOnly* vRegs) noexcept {
|
330
|
+
|
331
|
+
size_t count = pack.count();
|
332
|
+
if (!count)
|
333
|
+
return sb.append("void");
|
334
|
+
|
335
|
+
if (count > 1)
|
336
|
+
sb.append('[');
|
337
|
+
|
338
|
+
for (uint32_t valueIndex = 0; valueIndex < count; valueIndex++) {
|
339
|
+
const FuncValue& value = pack[valueIndex];
|
340
|
+
if (!value)
|
341
|
+
break;
|
342
|
+
|
343
|
+
if (valueIndex)
|
344
|
+
ASMJIT_PROPAGATE(sb.append(", "));
|
345
|
+
|
346
|
+
ASMJIT_PROPAGATE(formatFuncValue(sb, formatFlags, cc, value));
|
347
|
+
|
348
|
+
if (vRegs) {
|
349
|
+
const VirtReg* virtReg = nullptr;
|
350
|
+
static const char nullReg[] = "<none>";
|
351
|
+
|
352
|
+
if (vRegs[valueIndex].isReg() && cc->isVirtIdValid(vRegs[valueIndex].id()))
|
353
|
+
virtReg = cc->virtRegById(vRegs[valueIndex].id());
|
354
|
+
|
355
|
+
ASMJIT_PROPAGATE(sb.appendFormat(" %s", virtReg ? virtReg->name() : nullReg));
|
356
|
+
}
|
357
|
+
}
|
358
|
+
|
359
|
+
if (count > 1)
|
360
|
+
sb.append(']');
|
361
|
+
|
362
|
+
return kErrorOk;
|
363
|
+
}
|
364
|
+
|
365
|
+
static Error formatFuncRets(
|
366
|
+
String& sb,
|
367
|
+
FormatFlags formatFlags,
|
368
|
+
const BaseCompiler* cc,
|
369
|
+
const FuncDetail& fd) noexcept {
|
370
|
+
|
371
|
+
return formatFuncValuePack(sb, formatFlags, cc, fd.retPack(), nullptr);
|
372
|
+
}
|
373
|
+
|
374
|
+
static Error formatFuncArgs(
|
375
|
+
String& sb,
|
376
|
+
FormatFlags formatFlags,
|
377
|
+
const BaseCompiler* cc,
|
378
|
+
const FuncDetail& fd,
|
379
|
+
const FuncNode::ArgPack* argPacks) noexcept {
|
380
|
+
|
381
|
+
uint32_t argCount = fd.argCount();
|
382
|
+
if (!argCount)
|
383
|
+
return sb.append("void");
|
384
|
+
|
385
|
+
for (uint32_t argIndex = 0; argIndex < argCount; argIndex++) {
|
386
|
+
if (argIndex)
|
387
|
+
ASMJIT_PROPAGATE(sb.append(", "));
|
388
|
+
|
389
|
+
ASMJIT_PROPAGATE(formatFuncValuePack(sb, formatFlags, cc, fd.argPack(argIndex), argPacks[argIndex]._data));
|
390
|
+
}
|
391
|
+
|
392
|
+
return kErrorOk;
|
393
|
+
}
|
394
|
+
#endif
|
395
|
+
|
396
|
+
Error formatNode(
|
397
|
+
String& sb,
|
398
|
+
const FormatOptions& formatOptions,
|
399
|
+
const BaseBuilder* builder,
|
400
|
+
const BaseNode* node) noexcept {
|
401
|
+
|
402
|
+
if (node->hasPosition() && formatOptions.hasFlag(FormatFlags::kPositions))
|
403
|
+
ASMJIT_PROPAGATE(sb.appendFormat("<%05u> ", node->position()));
|
404
|
+
|
405
|
+
size_t startLineIndex = sb.size();
|
406
|
+
|
407
|
+
switch (node->type()) {
|
408
|
+
case NodeType::kInst:
|
409
|
+
case NodeType::kJump: {
|
410
|
+
const InstNode* instNode = node->as<InstNode>();
|
411
|
+
ASMJIT_PROPAGATE(builder->_funcs.formatInstruction(sb, formatOptions.flags(), builder,
|
412
|
+
builder->arch(),
|
413
|
+
instNode->baseInst(), instNode->operands(), instNode->opCount()));
|
414
|
+
break;
|
415
|
+
}
|
416
|
+
|
417
|
+
case NodeType::kSection: {
|
418
|
+
const SectionNode* sectionNode = node->as<SectionNode>();
|
419
|
+
if (builder->_code->isSectionValid(sectionNode->id())) {
|
420
|
+
const Section* section = builder->_code->sectionById(sectionNode->id());
|
421
|
+
ASMJIT_PROPAGATE(sb.appendFormat(".section %s", section->name()));
|
422
|
+
}
|
423
|
+
break;
|
424
|
+
}
|
425
|
+
|
426
|
+
case NodeType::kLabel: {
|
427
|
+
const LabelNode* labelNode = node->as<LabelNode>();
|
428
|
+
ASMJIT_PROPAGATE(formatLabel(sb, formatOptions.flags(), builder, labelNode->labelId()));
|
429
|
+
ASMJIT_PROPAGATE(sb.append(":"));
|
430
|
+
break;
|
431
|
+
}
|
432
|
+
|
433
|
+
case NodeType::kAlign: {
|
434
|
+
const AlignNode* alignNode = node->as<AlignNode>();
|
435
|
+
ASMJIT_PROPAGATE(sb.appendFormat(".align %u (%s)",
|
436
|
+
alignNode->alignment(),
|
437
|
+
alignNode->alignMode() == AlignMode::kCode ? "code" : "data"));
|
438
|
+
break;
|
439
|
+
}
|
440
|
+
|
441
|
+
case NodeType::kEmbedData: {
|
442
|
+
const EmbedDataNode* embedNode = node->as<EmbedDataNode>();
|
443
|
+
ASMJIT_PROPAGATE(sb.append('.'));
|
444
|
+
ASMJIT_PROPAGATE(formatDataType(sb, formatOptions.flags(), builder->arch(), embedNode->typeId()));
|
445
|
+
ASMJIT_PROPAGATE(sb.appendFormat(" {Count=%zu Repeat=%zu TotalSize=%zu}", embedNode->itemCount(), embedNode->repeatCount(), embedNode->dataSize()));
|
446
|
+
break;
|
447
|
+
}
|
448
|
+
|
449
|
+
case NodeType::kEmbedLabel: {
|
450
|
+
const EmbedLabelNode* embedNode = node->as<EmbedLabelNode>();
|
451
|
+
ASMJIT_PROPAGATE(sb.append(".label "));
|
452
|
+
ASMJIT_PROPAGATE(formatLabel(sb, formatOptions.flags(), builder, embedNode->labelId()));
|
453
|
+
break;
|
454
|
+
}
|
455
|
+
|
456
|
+
case NodeType::kEmbedLabelDelta: {
|
457
|
+
const EmbedLabelDeltaNode* embedNode = node->as<EmbedLabelDeltaNode>();
|
458
|
+
ASMJIT_PROPAGATE(sb.append(".label ("));
|
459
|
+
ASMJIT_PROPAGATE(formatLabel(sb, formatOptions.flags(), builder, embedNode->labelId()));
|
460
|
+
ASMJIT_PROPAGATE(sb.append(" - "));
|
461
|
+
ASMJIT_PROPAGATE(formatLabel(sb, formatOptions.flags(), builder, embedNode->baseLabelId()));
|
462
|
+
ASMJIT_PROPAGATE(sb.append(")"));
|
463
|
+
break;
|
464
|
+
}
|
465
|
+
|
466
|
+
case NodeType::kConstPool: {
|
467
|
+
const ConstPoolNode* constPoolNode = node->as<ConstPoolNode>();
|
468
|
+
ASMJIT_PROPAGATE(sb.appendFormat("[ConstPool Size=%zu Alignment=%zu]", constPoolNode->size(), constPoolNode->alignment()));
|
469
|
+
break;
|
470
|
+
};
|
471
|
+
|
472
|
+
case NodeType::kComment: {
|
473
|
+
const CommentNode* commentNode = node->as<CommentNode>();
|
474
|
+
ASMJIT_PROPAGATE(sb.appendFormat("; %s", commentNode->inlineComment()));
|
475
|
+
break;
|
476
|
+
}
|
477
|
+
|
478
|
+
case NodeType::kSentinel: {
|
479
|
+
const SentinelNode* sentinelNode = node->as<SentinelNode>();
|
480
|
+
const char* sentinelName = nullptr;
|
481
|
+
|
482
|
+
switch (sentinelNode->sentinelType()) {
|
483
|
+
case SentinelType::kFuncEnd:
|
484
|
+
sentinelName = "[FuncEnd]";
|
485
|
+
break;
|
486
|
+
|
487
|
+
default:
|
488
|
+
sentinelName = "[Sentinel]";
|
489
|
+
break;
|
490
|
+
}
|
491
|
+
|
492
|
+
ASMJIT_PROPAGATE(sb.append(sentinelName));
|
493
|
+
break;
|
494
|
+
}
|
495
|
+
|
496
|
+
#ifndef ASMJIT_NO_COMPILER
|
497
|
+
case NodeType::kFunc: {
|
498
|
+
const FuncNode* funcNode = node->as<FuncNode>();
|
499
|
+
|
500
|
+
if (builder->isCompiler()) {
|
501
|
+
ASMJIT_PROPAGATE(formatLabel(sb, formatOptions.flags(), builder, funcNode->labelId()));
|
502
|
+
ASMJIT_PROPAGATE(sb.append(": "));
|
503
|
+
|
504
|
+
ASMJIT_PROPAGATE(formatFuncRets(sb, formatOptions.flags(), static_cast<const BaseCompiler*>(builder), funcNode->detail()));
|
505
|
+
ASMJIT_PROPAGATE(sb.append(" Func("));
|
506
|
+
ASMJIT_PROPAGATE(formatFuncArgs(sb, formatOptions.flags(), static_cast<const BaseCompiler*>(builder), funcNode->detail(), funcNode->argPacks()));
|
507
|
+
ASMJIT_PROPAGATE(sb.append(")"));
|
508
|
+
}
|
509
|
+
break;
|
510
|
+
}
|
511
|
+
|
512
|
+
case NodeType::kFuncRet: {
|
513
|
+
const FuncRetNode* retNode = node->as<FuncRetNode>();
|
514
|
+
ASMJIT_PROPAGATE(sb.append("[FuncRet]"));
|
515
|
+
|
516
|
+
for (uint32_t i = 0; i < 2; i++) {
|
517
|
+
const Operand_& op = retNode->_opArray[i];
|
518
|
+
if (!op.isNone()) {
|
519
|
+
ASMJIT_PROPAGATE(sb.append(i == 0 ? " " : ", "));
|
520
|
+
ASMJIT_PROPAGATE(formatOperand(sb, formatOptions.flags(), builder, builder->arch(), op));
|
521
|
+
}
|
522
|
+
}
|
523
|
+
break;
|
524
|
+
}
|
525
|
+
|
526
|
+
case NodeType::kInvoke: {
|
527
|
+
const InvokeNode* invokeNode = node->as<InvokeNode>();
|
528
|
+
ASMJIT_PROPAGATE(builder->_funcs.formatInstruction(sb, formatOptions.flags(), builder,
|
529
|
+
builder->arch(),
|
530
|
+
invokeNode->baseInst(), invokeNode->operands(), invokeNode->opCount()));
|
531
|
+
break;
|
532
|
+
}
|
533
|
+
#endif
|
534
|
+
|
535
|
+
default: {
|
536
|
+
ASMJIT_PROPAGATE(sb.appendFormat("[UserNode:%u]", node->type()));
|
537
|
+
break;
|
538
|
+
}
|
539
|
+
}
|
540
|
+
|
541
|
+
if (node->hasInlineComment()) {
|
542
|
+
size_t requiredPadding = paddingFromOptions(formatOptions, FormatPaddingGroup::kRegularLine);
|
543
|
+
size_t currentPadding = sb.size() - startLineIndex;
|
544
|
+
|
545
|
+
if (currentPadding < requiredPadding)
|
546
|
+
ASMJIT_PROPAGATE(sb.appendChars(' ', requiredPadding - currentPadding));
|
547
|
+
|
548
|
+
ASMJIT_PROPAGATE(sb.append("; "));
|
549
|
+
ASMJIT_PROPAGATE(sb.append(node->inlineComment()));
|
550
|
+
}
|
551
|
+
|
552
|
+
return kErrorOk;
|
553
|
+
}
|
554
|
+
|
555
|
+
Error formatNodeList(
|
556
|
+
String& sb,
|
557
|
+
const FormatOptions& formatOptions,
|
558
|
+
const BaseBuilder* builder) noexcept {
|
559
|
+
|
560
|
+
return formatNodeList(sb, formatOptions, builder, builder->firstNode(), nullptr);
|
561
|
+
}
|
562
|
+
|
563
|
+
Error formatNodeList(
|
564
|
+
String& sb,
|
565
|
+
const FormatOptions& formatOptions,
|
566
|
+
const BaseBuilder* builder,
|
567
|
+
const BaseNode* begin,
|
568
|
+
const BaseNode* end) noexcept {
|
569
|
+
|
570
|
+
const BaseNode* node = begin;
|
571
|
+
while (node != end) {
|
572
|
+
ASMJIT_PROPAGATE(formatNode(sb, formatOptions, builder, node));
|
573
|
+
ASMJIT_PROPAGATE(sb.append('\n'));
|
574
|
+
node = node->next();
|
575
|
+
}
|
576
|
+
return kErrorOk;
|
577
|
+
}
|
578
|
+
#endif
|
579
|
+
|
580
|
+
} // {Formatter}
|
581
|
+
|
582
|
+
ASMJIT_END_NAMESPACE
|
583
|
+
|
584
|
+
#endif
|