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 #ifndef __PLUMED_asmjit_x86assembler_h 21 #define __PLUMED_asmjit_x86assembler_h 22 #ifdef __PLUMED_HAS_ASMJIT 23 #pragma GCC diagnostic push 24 #pragma GCC diagnostic ignored "-Wpedantic" 25 // [AsmJit] 26 // Complete x86/x64 JIT and Remote Assembler for C++. 27 // 28 // [License] 29 // Zlib - See LICENSE.md file in the package. 30 31 // [Guard] 32 #ifndef _ASMJIT_X86_X86ASSEMBLER_H 33 #define _ASMJIT_X86_X86ASSEMBLER_H 34 35 // [Dependencies] 36 #include "./assembler.h" 37 #include "./utils.h" 38 #include "./x86emitter.h" 39 #include "./x86operand.h" 40 41 // [Api-Begin] 42 #include "./asmjit_apibegin.h" 43 44 namespace PLMD { 45 namespace asmjit { 46 47 //! \addtogroup asmjit_x86 48 //! \{ 49 50 // ============================================================================ 51 // [asmjit::X86Assembler] 52 // ============================================================================ 53 54 //! X86/X64 assembler. 55 //! 56 //! X86/X64 assembler emits machine-code into buffers managed by \ref CodeHolder. 57 class ASMJIT_VIRTAPI X86Assembler 58 : public Assembler, 59 public X86EmitterImplicitT<X86Assembler> { 60 61 public: 62 typedef Assembler Base; 63 64 // -------------------------------------------------------------------------- 65 // [Construction / Destruction] 66 // -------------------------------------------------------------------------- 67 68 ASMJIT_API X86Assembler(CodeHolder* code = nullptr) noexcept; 69 ASMJIT_API virtual ~X86Assembler() noexcept; 70 71 // -------------------------------------------------------------------------- 72 // [Compatibility] 73 // -------------------------------------------------------------------------- 74 75 //! Explicit cast to `X86Emitter`. asEmitter()76 ASMJIT_INLINE X86Emitter* asEmitter() noexcept { return reinterpret_cast<X86Emitter*>(this); } 77 //! Explicit cast to `X86Emitter` (const). asEmitter()78 ASMJIT_INLINE const X86Emitter* asEmitter() const noexcept { return reinterpret_cast<const X86Emitter*>(this); } 79 80 //! Implicit cast to `X86Emitter`. 81 ASMJIT_INLINE operator X86Emitter&() noexcept { return *asEmitter(); } 82 //! Implicit cast to `X86Emitter` (const). 83 ASMJIT_INLINE operator const X86Emitter&() const noexcept { return *asEmitter(); } 84 85 // -------------------------------------------------------------------------- 86 // [Accessors] 87 // -------------------------------------------------------------------------- 88 89 // NOTE: X86Assembler uses _privateData to store 'address-override' bit that 90 // is used to decide whether to emit address-override (67H) prefix based on 91 // the memory BASE+INDEX registers. It's either `kX86MemInfo_67H_X86` or 92 // `kX86MemInfo_67H_X64`. _getAddressOverrideMask()93 ASMJIT_INLINE uint32_t _getAddressOverrideMask() const noexcept { return _privateData; } _setAddressOverrideMask(uint32_t m)94 ASMJIT_INLINE void _setAddressOverrideMask(uint32_t m) noexcept { _privateData = m; } 95 96 // -------------------------------------------------------------------------- 97 // [Events] 98 // -------------------------------------------------------------------------- 99 100 ASMJIT_API Error onAttach(CodeHolder* code) noexcept override; 101 ASMJIT_API Error onDetach(CodeHolder* code) noexcept override; 102 103 // -------------------------------------------------------------------------- 104 // [Code-Generation] 105 // -------------------------------------------------------------------------- 106 107 using CodeEmitter::_emit; 108 109 ASMJIT_API Error _emit(uint32_t instId, const Operand_& o0, const Operand_& o1, const Operand_& o2, const Operand_& o3) override; 110 ASMJIT_API Error align(uint32_t mode, uint32_t alignment) override; 111 }; 112 113 //! \} 114 115 } // asmjit namespace 116 } // namespace PLMD 117 118 // [Api-End] 119 #include "./asmjit_apiend.h" 120 121 // [Guard] 122 #endif // _ASMJIT_X86_X86ASSEMBLER_H 123 #pragma GCC diagnostic pop 124 #endif // __PLUMED_HAS_ASMJIT 125 #endif 126