1 // AsmJit - Machine code generation for C++
2 //
3 //  * Official AsmJit Home Page: https://asmjit.com
4 //  * Official Github Repository: https://github.com/asmjit/asmjit
5 //
6 // Copyright (c) 2008-2020 The AsmJit Authors
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 //    claim that you wrote the original software. If you use this software
18 //    in a product, an acknowledgment in the product documentation would be
19 //    appreciated but is not required.
20 // 2. Altered source versions must be plainly marked as such, and must not be
21 //    misrepresented as being the original software.
22 // 3. This notice may not be removed or altered from any source distribution.
23 
24 #include "../core/api-build_p.h"
25 #ifdef ASMJIT_BUILD_X86
26 
27 #include "../core/arch.h"
28 #include "../core/inst.h"
29 
30 #ifdef ASMJIT_BUILD_X86
31   #include "../x86/x86instapi_p.h"
32 #endif
33 
34 #ifdef ASMJIT_BUILD_ARM
35   #include "../arm/arminstapi_p.h"
36 #endif
37 
38 ASMJIT_BEGIN_NAMESPACE
39 
40 // ============================================================================
41 // [asmjit::InstAPI - Text]
42 // ============================================================================
43 
44 #ifndef ASMJIT_NO_TEXT
instIdToString(uint32_t arch,uint32_t instId,String & output)45 Error InstAPI::instIdToString(uint32_t arch, uint32_t instId, String& output) noexcept {
46 #ifdef ASMJIT_BUILD_X86
47   if (Environment::isFamilyX86(arch))
48     return x86::InstInternal::instIdToString(arch, instId, output);
49 #endif
50 
51 #ifdef ASMJIT_BUILD_ARM
52   if (Environment::isFamilyARM(arch))
53     return arm::InstInternal::instIdToString(arch, instId, output);
54 #endif
55 
56   return DebugUtils::errored(kErrorInvalidArch);
57 }
58 
stringToInstId(uint32_t arch,const char * s,size_t len)59 uint32_t InstAPI::stringToInstId(uint32_t arch, const char* s, size_t len) noexcept {
60 #ifdef ASMJIT_BUILD_X86
61   if (Environment::isFamilyX86(arch))
62     return x86::InstInternal::stringToInstId(arch, s, len);
63 #endif
64 
65 #ifdef ASMJIT_BUILD_ARM
66   if (Environment::isFamilyARM(arch))
67     return arm::InstInternal::stringToInstId(arch, s, len);
68 #endif
69 
70   return 0;
71 }
72 #endif // !ASMJIT_NO_TEXT
73 
74 // ============================================================================
75 // [asmjit::InstAPI - Validate]
76 // ============================================================================
77 
78 #ifndef ASMJIT_NO_VALIDATION
validate(uint32_t arch,const BaseInst & inst,const Operand_ * operands,size_t opCount,uint32_t validationFlags)79 Error InstAPI::validate(uint32_t arch, const BaseInst& inst, const Operand_* operands, size_t opCount, uint32_t validationFlags) noexcept {
80 #ifdef ASMJIT_BUILD_X86
81   if (Environment::isFamilyX86(arch))
82     return x86::InstInternal::validate(arch, inst, operands, opCount, validationFlags);
83 #endif
84 
85 #ifdef ASMJIT_BUILD_ARM
86   if (Environment::isFamilyARM(arch))
87     return arm::InstInternal::validate(arch, inst, operands, opCount, validationFlags);
88 #endif
89 
90   return DebugUtils::errored(kErrorInvalidArch);
91 }
92 #endif // !ASMJIT_NO_VALIDATION
93 
94 // ============================================================================
95 // [asmjit::InstAPI - QueryRWInfo]
96 // ============================================================================
97 
98 #ifndef ASMJIT_NO_INTROSPECTION
queryRWInfo(uint32_t arch,const BaseInst & inst,const Operand_ * operands,size_t opCount,InstRWInfo * out)99 Error InstAPI::queryRWInfo(uint32_t arch, const BaseInst& inst, const Operand_* operands, size_t opCount, InstRWInfo* out) noexcept {
100   if (ASMJIT_UNLIKELY(opCount > Globals::kMaxOpCount))
101     return DebugUtils::errored(kErrorInvalidArgument);
102 
103 #ifdef ASMJIT_BUILD_X86
104   if (Environment::isFamilyX86(arch))
105     return x86::InstInternal::queryRWInfo(arch, inst, operands, opCount, out);
106 #endif
107 
108 #ifdef ASMJIT_BUILD_ARM
109   if (Environment::isFamilyARM(arch))
110     return arm::InstInternal::queryRWInfo(arch, inst, operands, opCount, out);
111 #endif
112 
113   return DebugUtils::errored(kErrorInvalidArch);
114 }
115 #endif // !ASMJIT_NO_INTROSPECTION
116 
117 // ============================================================================
118 // [asmjit::InstAPI - QueryFeatures]
119 // ============================================================================
120 
121 #ifndef ASMJIT_NO_INTROSPECTION
queryFeatures(uint32_t arch,const BaseInst & inst,const Operand_ * operands,size_t opCount,BaseFeatures * out)122 Error InstAPI::queryFeatures(uint32_t arch, const BaseInst& inst, const Operand_* operands, size_t opCount, BaseFeatures* out) noexcept {
123 #ifdef ASMJIT_BUILD_X86
124   if (Environment::isFamilyX86(arch))
125     return x86::InstInternal::queryFeatures(arch, inst, operands, opCount, out);
126 #endif
127 
128 #ifdef ASMJIT_BUILD_ARM
129   if (Environment::isFamilyARM(arch))
130     return arm::InstInternal::queryFeatures(arch, inst, operands, opCount, out);
131 #endif
132 
133   return DebugUtils::errored(kErrorInvalidArch);
134 }
135 #endif // !ASMJIT_NO_INTROSPECTION
136 
137 ASMJIT_END_NAMESPACE
138 
139 #endif // ASMJIT_BUILD_X86
140