Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2008-2017, Petr Kobalicek 3 : 4 : This software is provided 'as-is', without any express or implied 5 : warranty. In no event will the authors be held liable for any damages 6 : arising from the use of this software. 7 : 8 : Permission is granted to anyone to use this software for any purpose, 9 : including commercial applications, and to alter it and redistribute it 10 : freely, subject to the following restrictions: 11 : 12 : 1. The origin of this software must not be misrepresented; you must not 13 : claim that you wrote the original software. If you use this software 14 : in a product, an acknowledgment in the product documentation would be 15 : appreciated but is not required. 16 : 2. Altered source versions must be plainly marked as such, and must not be 17 : misrepresented as being the original software. 18 : 3. This notice may not be removed or altered from any source distribution. 19 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 20 : #ifdef __PLUMED_HAS_ASMJIT 21 : #pragma GCC diagnostic push 22 : #pragma GCC diagnostic ignored "-Wpedantic" 23 : // [AsmJit] 24 : // Complete x86/x64 JIT and Remote Assembler for C++. 25 : // 26 : // [License] 27 : // Zlib - See LICENSE.md file in the package. 28 : 29 : // [Export] 30 : #define ASMJIT_EXPORTS 31 : 32 : // [Dependencies] 33 : #include "./arch.h" 34 : #include "./func.h" 35 : 36 : #if defined(ASMJIT_BUILD_X86) 37 : #include "./x86internal_p.h" 38 : #include "./x86operand.h" 39 : #endif // ASMJIT_BUILD_X86 40 : 41 : #if defined(ASMJIT_BUILD_ARM) 42 : #include "./arminternal_p.h" 43 : #include "./armoperand.h" 44 : #endif // ASMJIT_BUILD_ARM 45 : 46 : // [Api-Begin] 47 : #include "./asmjit_apibegin.h" 48 : 49 : namespace PLMD { 50 : namespace asmjit { 51 : 52 : // ============================================================================ 53 : // [asmjit::CallConv - Init / Reset] 54 : // ============================================================================ 55 : 56 45233 : ASMJIT_FAVOR_SIZE Error CallConv::init(uint32_t ccId) noexcept { 57 : reset(); 58 : 59 : #if defined(ASMJIT_BUILD_X86) 60 45233 : if (CallConv::isX86Family(ccId)) 61 45233 : return X86Internal::initCallConv(*this, ccId); 62 : #endif // ASMJIT_BUILD_X86 63 : 64 : #if defined(ASMJIT_BUILD_ARM) 65 : if (CallConv::isArmFamily(ccId)) 66 : return ArmInternal::initCallConv(*this, ccId); 67 : #endif // ASMJIT_BUILD_ARM 68 : 69 : return DebugUtils::errored(kErrorInvalidArgument); 70 : } 71 : 72 : // ============================================================================ 73 : // [asmjit::FuncDetail - Init / Reset] 74 : // ============================================================================ 75 : 76 45233 : ASMJIT_FAVOR_SIZE Error FuncDetail::init(const FuncSignature& sign) { 77 : uint32_t ccId = sign.getCallConv(); 78 45233 : CallConv& cc = _callConv; 79 : 80 : uint32_t argCount = sign.getArgCount(); 81 45233 : if (ASMJIT_UNLIKELY(argCount > kFuncArgCount)) 82 : return DebugUtils::errored(kErrorInvalidArgument); 83 : 84 45233 : ASMJIT_PROPAGATE(cc.init(ccId)); 85 : 86 45233 : uint32_t gpSize = (cc.getArchType() == ArchInfo::kTypeX86) ? 4 : 8; 87 : uint32_t deabstractDelta = TypeId::deabstractDeltaOfSize(gpSize); 88 : 89 : const uint8_t* args = sign.getArgs(); 90 58873 : for (uint32_t i = 0; i < argCount; i++) { 91 : Value& arg = _args[i]; 92 13640 : arg.initTypeId(TypeId::deabstract(args[i], deabstractDelta)); 93 : } 94 45233 : _argCount = static_cast<uint8_t>(argCount); 95 : 96 : uint32_t ret = sign.getRet(); 97 45233 : if (ret != TypeId::kVoid) { 98 : _rets[0].initTypeId(TypeId::deabstract(ret, deabstractDelta)); 99 45233 : _retCount = 1; 100 : } 101 : 102 : #if defined(ASMJIT_BUILD_X86) 103 45233 : if (CallConv::isX86Family(ccId)) 104 45233 : return X86Internal::initFuncDetail(*this, sign, gpSize); 105 : #endif // ASMJIT_BUILD_X86 106 : 107 : #if defined(ASMJIT_BUILD_ARM) 108 : if (CallConv::isArmFamily(ccId)) 109 : return ArmInternal::initFuncDetail(*this, sign, gpSize); 110 : #endif // ASMJIT_BUILD_ARM 111 : 112 : // We should never bubble here as if `cc.init()` succeeded then there has to 113 : // be an implementation for the current architecture. However, stay safe. 114 : return DebugUtils::errored(kErrorInvalidArgument); 115 : } 116 : 117 : // ============================================================================ 118 : // [asmjit::FuncFrameLayout - Init / Reset] 119 : // ============================================================================ 120 : 121 32111 : ASMJIT_FAVOR_SIZE Error FuncFrameLayout::init(const FuncDetail& func, const FuncFrameInfo& ffi) noexcept { 122 : uint32_t ccId = func.getCallConv().getId(); 123 : 124 : #if defined(ASMJIT_BUILD_X86) 125 32111 : if (CallConv::isX86Family(ccId)) 126 32111 : return X86Internal::initFrameLayout(*this, func, ffi); 127 : #endif // ASMJIT_BUILD_X86 128 : 129 : #if defined(ASMJIT_BUILD_ARM) 130 : if (CallConv::isArmFamily(ccId)) 131 : return ArmInternal::initFrameLayout(*this, func, ffi); 132 : #endif // ASMJIT_BUILD_ARM 133 : 134 : return DebugUtils::errored(kErrorInvalidArgument); 135 : } 136 : 137 : // ============================================================================ 138 : // [asmjit::FuncArgsMapper] 139 : // ============================================================================ 140 : 141 0 : ASMJIT_FAVOR_SIZE Error FuncArgsMapper::updateFrameInfo(FuncFrameInfo& ffi) const noexcept { 142 : const FuncDetail* func = getFuncDetail(); 143 0 : if (!func) return DebugUtils::errored(kErrorInvalidState); 144 : 145 : uint32_t ccId = func->getCallConv().getId(); 146 : 147 : #if defined(ASMJIT_BUILD_X86) 148 0 : if (CallConv::isX86Family(ccId)) 149 0 : return X86Internal::argsToFrameInfo(*this, ffi); 150 : #endif // ASMJIT_BUILD_X86 151 : 152 : #if defined(ASMJIT_BUILD_ARM) 153 : if (CallConv::isArmFamily(ccId)) 154 : return ArmInternal::argsToFrameInfo(*this, ffi); 155 : #endif // ASMJIT_BUILD_X86 156 : 157 : return DebugUtils::errored(kErrorInvalidArch); 158 : } 159 : 160 : // ============================================================================ 161 : // [asmjit::FuncUtils] 162 : // ============================================================================ 163 : 164 32111 : ASMJIT_FAVOR_SIZE Error FuncUtils::emitProlog(CodeEmitter* emitter, const FuncFrameLayout& layout) { 165 : #if defined(ASMJIT_BUILD_X86) 166 32111 : if (emitter->getArchInfo().isX86Family()) 167 32111 : return X86Internal::emitProlog(static_cast<X86Emitter*>(emitter), layout); 168 : #endif // ASMJIT_BUILD_X86 169 : 170 : #if defined(ASMJIT_BUILD_ARM) 171 : if (emitter->getArchInfo().isArmFamily()) 172 : return ArmInternal::emitProlog(static_cast<ArmEmitter*>(emitter), layout); 173 : #endif // ASMJIT_BUILD_ARM 174 : 175 : return DebugUtils::errored(kErrorInvalidArch); 176 : } 177 : 178 32111 : ASMJIT_FAVOR_SIZE Error FuncUtils::emitEpilog(CodeEmitter* emitter, const FuncFrameLayout& layout) { 179 : #if defined(ASMJIT_BUILD_X86) 180 32111 : if (emitter->getArchInfo().isX86Family()) 181 32111 : return X86Internal::emitEpilog(static_cast<X86Emitter*>(emitter), layout); 182 : #endif // ASMJIT_BUILD_X86 183 : 184 : #if defined(ASMJIT_BUILD_ARM) 185 : if (emitter->getArchInfo().isArmFamily()) 186 : return ArmInternal::emitEpilog(static_cast<ArmEmitter*>(emitter), layout); 187 : #endif // ASMJIT_BUILD_ARM 188 : 189 : return DebugUtils::errored(kErrorInvalidArch); 190 : } 191 : 192 0 : ASMJIT_FAVOR_SIZE Error FuncUtils::allocArgs(CodeEmitter* emitter, const FuncFrameLayout& layout, const FuncArgsMapper& args) { 193 : #if defined(ASMJIT_BUILD_X86) 194 0 : if (emitter->getArchInfo().isX86Family()) 195 0 : return X86Internal::allocArgs(static_cast<X86Emitter*>(emitter), layout, args); 196 : #endif // ASMJIT_BUILD_X86 197 : 198 : #if defined(ASMJIT_BUILD_ARM) 199 : if (emitter->getArchInfo().isArmFamily()) 200 : return ArmInternal::allocArgs(static_cast<ArmEmitter*>(emitter), layout, args); 201 : #endif // ASMJIT_BUILD_ARM 202 : 203 : return DebugUtils::errored(kErrorInvalidArch); 204 : } 205 : 206 : } // asmjit namespace 207 : } // namespace PLMD 208 : 209 : // [Api-End] 210 : #include "./asmjit_apiend.h" 211 : #pragma GCC diagnostic pop 212 : #endif // __PLUMED_HAS_ASMJIT