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_ASSEMBLER_H_INCLUDED 8 : #define ASMJIT_CORE_ASSEMBLER_H_INCLUDED 9 : 10 : #include "codeholder.h" 11 : #include "emitter.h" 12 : #include "operand.h" 13 : 14 : ASMJIT_BEGIN_NAMESPACE 15 : 16 : //! \addtogroup asmjit_assembler 17 : //! \{ 18 : 19 : //! Base assembler. 20 : //! 21 : //! This is a base class that provides interface used by architecture specific 22 : //! assembler implementations. Assembler doesn't hold any data, instead it's 23 : //! attached to \ref CodeHolder, which provides all the data that Assembler 24 : //! needs and which can be altered by it. 25 : //! 26 : //! Check out architecture specific assemblers for more details and examples: 27 : //! 28 : //! - \ref x86::Assembler - X86/X64 assembler implementation. 29 : class ASMJIT_VIRTAPI BaseAssembler : public BaseEmitter { 30 : public: 31 : ASMJIT_NONCOPYABLE(BaseAssembler) 32 : typedef BaseEmitter Base; 33 : 34 : //! Current section where the assembling happens. 35 : Section* _section = nullptr; 36 : //! Start of the CodeBuffer of the current section. 37 : uint8_t* _bufferData = nullptr; 38 : //! End (first invalid byte) of the current section. 39 : uint8_t* _bufferEnd = nullptr; 40 : //! Pointer in the CodeBuffer of the current section. 41 : uint8_t* _bufferPtr = nullptr; 42 : 43 : //! \name Construction & Destruction 44 : //! \{ 45 : 46 : //! Creates a new `BaseAssembler` instance. 47 : ASMJIT_API BaseAssembler() noexcept; 48 : //! Destroys the `BaseAssembler` instance. 49 : ASMJIT_API virtual ~BaseAssembler() noexcept; 50 : 51 : //! \} 52 : 53 : //! \name Code-Buffer Management 54 : //! \{ 55 : 56 : //! Returns the capacity of the current CodeBuffer. 57 : inline size_t bufferCapacity() const noexcept { return (size_t)(_bufferEnd - _bufferData); } 58 : //! Returns the number of remaining bytes in the current CodeBuffer. 59 : inline size_t remainingSpace() const noexcept { return (size_t)(_bufferEnd - _bufferPtr); } 60 : 61 : //! Returns the current position in the CodeBuffer. 62 82476 : inline size_t offset() const noexcept { return (size_t)(_bufferPtr - _bufferData); } 63 : 64 : //! Sets the current position in the CodeBuffer to `offset`. 65 : //! 66 : //! \note The `offset` cannot be greater than buffer size even if it's 67 : //! within the buffer's capacity. 68 : ASMJIT_API Error setOffset(size_t offset); 69 : 70 : //! Returns the start of the CodeBuffer in the current section. 71 : inline uint8_t* bufferData() const noexcept { return _bufferData; } 72 : //! Returns the end (first invalid byte) in the current section. 73 : inline uint8_t* bufferEnd() const noexcept { return _bufferEnd; } 74 : //! Returns the current pointer in the CodeBuffer in the current section. 75 0 : inline uint8_t* bufferPtr() const noexcept { return _bufferPtr; } 76 : 77 : //! \} 78 : 79 : //! \name Section Management 80 : //! \{ 81 : 82 : //! Returns the current section. 83 : inline Section* currentSection() const noexcept { return _section; } 84 : 85 : ASMJIT_API Error section(Section* section) override; 86 : 87 : //! \} 88 : 89 : //! \name Label Management 90 : //! \{ 91 : 92 : ASMJIT_API Label newLabel() override; 93 : ASMJIT_API Label newNamedLabel(const char* name, size_t nameSize = SIZE_MAX, LabelType type = LabelType::kGlobal, uint32_t parentId = Globals::kInvalidId) override; 94 : ASMJIT_API Error bind(const Label& label) override; 95 : 96 : //! \} 97 : 98 : //! \name Embed 99 : //! \{ 100 : 101 : ASMJIT_API Error embed(const void* data, size_t dataSize) override; 102 : ASMJIT_API Error embedDataArray(TypeId typeId, const void* data, size_t itemCount, size_t repeatCount = 1) override; 103 : ASMJIT_API Error embedConstPool(const Label& label, const ConstPool& pool) override; 104 : 105 : ASMJIT_API Error embedLabel(const Label& label, size_t dataSize = 0) override; 106 : ASMJIT_API Error embedLabelDelta(const Label& label, const Label& base, size_t dataSize = 0) override; 107 : 108 : //! \} 109 : 110 : //! \name Comment 111 : //! \{ 112 : 113 : ASMJIT_API Error comment(const char* data, size_t size = SIZE_MAX) override; 114 : 115 : //! \} 116 : 117 : //! \name Events 118 : //! \{ 119 : 120 : ASMJIT_API Error onAttach(CodeHolder* code) noexcept override; 121 : ASMJIT_API Error onDetach(CodeHolder* code) noexcept override; 122 : 123 : //! \} 124 : }; 125 : 126 : //! \} 127 : 128 : ASMJIT_END_NAMESPACE 129 : 130 : #endif // ASMJIT_CORE_ASSEMBLER_H_INCLUDED 131 : 132 : #endif // __PLUMED_HAS_ASMJIT