1 // [AsmJit]
2 // Machine Code Generation for C++.
3 //
4 // [License]
5 // Zlib - See LICENSE.md file in the package.
6
7 #define ASMJIT_EXPORTS
8
9 #include "../core/build.h"
10 #ifdef ASMJIT_BUILD_X86
11
12 #include "../core/arch.h"
13 #include "../core/inst.h"
14
15 #ifdef ASMJIT_BUILD_X86
16 #include "../x86/x86instapi_p.h"
17 #endif
18
19 #ifdef ASMJIT_BUILD_ARM
20 #include "../arm/arminstapi_p.h"
21 #endif
22
23 ASMJIT_BEGIN_NAMESPACE
24
25 // ============================================================================
26 // [asmjit::InstAPI - Text]
27 // ============================================================================
28
29 #ifndef ASMJIT_NO_TEXT
instIdToString(uint32_t archId,uint32_t instId,String & output)30 Error InstAPI::instIdToString(uint32_t archId, uint32_t instId, String& output) noexcept {
31 #ifdef ASMJIT_BUILD_X86
32 if (ArchInfo::isX86Family(archId))
33 return x86::InstInternal::instIdToString(archId, instId, output);
34 #endif
35
36 #ifdef ASMJIT_BUILD_ARM
37 if (ArchInfo::isArmFamily(archId))
38 return arm::InstInternal::instIdToString(archId, instId, output);
39 #endif
40
41 return DebugUtils::errored(kErrorInvalidArch);
42 }
43
stringToInstId(uint32_t archId,const char * s,size_t len)44 uint32_t InstAPI::stringToInstId(uint32_t archId, const char* s, size_t len) noexcept {
45 #ifdef ASMJIT_BUILD_X86
46 if (ArchInfo::isX86Family(archId))
47 return x86::InstInternal::stringToInstId(archId, s, len);
48 #endif
49
50 #ifdef ASMJIT_BUILD_ARM
51 if (ArchInfo::isArmFamily(archId))
52 return arm::InstInternal::stringToInstId(archId, s, len);
53 #endif
54
55 return 0;
56 }
57 #endif // !ASMJIT_NO_TEXT
58
59 // ============================================================================
60 // [asmjit::InstAPI - Validate]
61 // ============================================================================
62
63 #ifndef ASMJIT_NO_VALIDATION
validate(uint32_t archId,const BaseInst & inst,const Operand_ * operands,uint32_t opCount)64 Error InstAPI::validate(uint32_t archId, const BaseInst& inst, const Operand_* operands, uint32_t opCount) noexcept {
65 #ifdef ASMJIT_BUILD_X86
66 if (ArchInfo::isX86Family(archId))
67 return x86::InstInternal::validate(archId, inst, operands, opCount);
68 #endif
69
70 #ifdef ASMJIT_BUILD_ARM
71 if (ArchInfo::isArmFamily(archId))
72 return arm::InstInternal::validate(archId, inst, operands, opCount);
73 #endif
74
75 return DebugUtils::errored(kErrorInvalidArch);
76 }
77 #endif // !ASMJIT_NO_VALIDATION
78
79 // ============================================================================
80 // [asmjit::InstAPI - QueryRWInfo]
81 // ============================================================================
82
83 #ifndef ASMJIT_NO_INTROSPECTION
queryRWInfo(uint32_t archId,const BaseInst & inst,const Operand_ * operands,uint32_t opCount,InstRWInfo & out)84 Error InstAPI::queryRWInfo(uint32_t archId, const BaseInst& inst, const Operand_* operands, uint32_t opCount, InstRWInfo& out) noexcept {
85 if (ASMJIT_UNLIKELY(opCount > 6))
86 return DebugUtils::errored(kErrorInvalidArgument);
87
88 #ifdef ASMJIT_BUILD_X86
89 if (ArchInfo::isX86Family(archId))
90 return x86::InstInternal::queryRWInfo(archId, inst, operands, opCount, out);
91 #endif
92
93 #ifdef ASMJIT_BUILD_ARM
94 if (ArchInfo::isArmFamily(archId))
95 return arm::InstInternal::queryRWInfo(archId, inst, operands, opCount, out);
96 #endif
97
98 return DebugUtils::errored(kErrorInvalidArch);
99 }
100 #endif // !ASMJIT_NO_INTROSPECTION
101
102 // ============================================================================
103 // [asmjit::InstAPI - QueryFeatures]
104 // ============================================================================
105
106 #ifndef ASMJIT_NO_INTROSPECTION
queryFeatures(uint32_t archId,const BaseInst & inst,const Operand_ * operands,uint32_t opCount,BaseFeatures & out)107 Error InstAPI::queryFeatures(uint32_t archId, const BaseInst& inst, const Operand_* operands, uint32_t opCount, BaseFeatures& out) noexcept {
108 #ifdef ASMJIT_BUILD_X86
109 if (ArchInfo::isX86Family(archId))
110 return x86::InstInternal::queryFeatures(archId, inst, operands, opCount, out);
111 #endif
112
113 #ifdef ASMJIT_BUILD_ARM
114 if (ArchInfo::isArmFamily(archId))
115 return arm::InstInternal::queryFeatures(archId, inst, operands, opCount, out);
116 #endif
117
118 return DebugUtils::errored(kErrorInvalidArch);
119 }
120 #endif // !ASMJIT_NO_INTROSPECTION
121
122 ASMJIT_END_NAMESPACE
123
124 #endif // ASMJIT_BUILD_X86
125