Line data Source code
1 : #ifdef __PLUMED_HAS_ASMJIT 2 : // This file is part of AsmJit project <https://asmjit.com> 3 : // 4 : // See asmjit.h or LICENSE.md for license and copyright information 5 : // SPDX-License-Identifier: Zlib 6 : 7 : #ifndef ASMJIT_CORE_JITRUNTIME_H_INCLUDED 8 : #define ASMJIT_CORE_JITRUNTIME_H_INCLUDED 9 : 10 : #include "api-config.h" 11 : #ifndef ASMJIT_NO_JIT 12 : 13 : #include "codeholder.h" 14 : #include "jitallocator.h" 15 : #include "target.h" 16 : 17 : ASMJIT_BEGIN_NAMESPACE 18 : 19 : class CodeHolder; 20 : 21 : //! \addtogroup asmjit_virtual_memory 22 : //! \{ 23 : 24 : //! JIT execution runtime is a special `Target` that is designed to store and 25 : //! execute the generated code. 26 : class ASMJIT_VIRTAPI JitRuntime : public Target { 27 : public: 28 : ASMJIT_NONCOPYABLE(JitRuntime) 29 : 30 : //! Virtual memory allocator. 31 : JitAllocator _allocator; 32 : 33 : //! \name Construction & Destruction 34 : //! \{ 35 : 36 : //! Creates a `JitRuntime` instance. 37 : ASMJIT_API explicit JitRuntime(const JitAllocator::CreateParams* params = nullptr) noexcept; 38 : //! Destroys the `JitRuntime` instance. 39 : ASMJIT_API virtual ~JitRuntime() noexcept; 40 : 41 : inline void reset(ResetPolicy resetPolicy = ResetPolicy::kSoft) noexcept { 42 : _allocator.reset(resetPolicy); 43 : } 44 : 45 : //! \} 46 : 47 : //! \name Accessors 48 : //! \{ 49 : 50 : //! Returns the associated `JitAllocator`. 51 : inline JitAllocator* allocator() const noexcept { return const_cast<JitAllocator*>(&_allocator); } 52 : 53 : //! \} 54 : 55 : //! \name Utilities 56 : //! \{ 57 : 58 : // NOTE: To allow passing function pointers to `add()` and `release()` the 59 : // virtual methods are prefixed with `_` and called from templates instead. 60 : 61 : //! Allocates memory needed for a code stored in the `CodeHolder` and relocates the code to the pointer allocated. 62 : //! 63 : //! The beginning of the memory allocated for the function is returned in `dst`. If failed `Error` code is returned 64 : //! and `dst` is explicitly set to `nullptr` (this means that you don't have to set it to null before calling `add()`). 65 : template<typename Func> 66 : inline Error add(Func* dst, CodeHolder* code) noexcept { 67 27492 : return _add(Support::ptr_cast_impl<void**, Func*>(dst), code); 68 : } 69 : 70 : //! Releases `p` which was obtained by calling `add()`. 71 : template<typename Func> 72 : inline Error release(Func p) noexcept { 73 100 : return _release(Support::ptr_cast_impl<void*, Func>(p)); 74 : } 75 : 76 : //! Type-unsafe version of `add()`. 77 : ASMJIT_API virtual Error _add(void** dst, CodeHolder* code) noexcept; 78 : 79 : //! Type-unsafe version of `release()`. 80 : ASMJIT_API virtual Error _release(void* p) noexcept; 81 : 82 : //! \} 83 : }; 84 : 85 : //! \} 86 : 87 : ASMJIT_END_NAMESPACE 88 : 89 : #endif 90 : #endif 91 : 92 : #endif // __PLUMED_HAS_ASMJIT