mirror of
https://github.com/asmjit/asmjit
synced 2026-06-08 13:13:30 +00:00
b56f4176cb
* Denested src folder to root, renamed testing to asmjit-testing
* Refactored how headers are included into <asmjit/...> form. This
is necessary as compilers would never simplify a path once a ..
appears in include directory - then paths such as ../core/../core
appeared in asserts, which was ugly
* Moved support utilities into asmjit/support/... (still included
by asmjit/core.h for convenience and compatibility)
* Added CMakePresets.json for making it easy to develop AsmJit
* Reworked CMakeLists to be shorter and use CMake option(),
etc... This simplifies it and makes it using more standard
features
* ASMJIT_EMBED now creates asmjit_embed INTERFACE library,
which is accessible via asmjit::asmjit target - this simplifies
embedding and makes it the same as library targets from a CMake
perspective
* Removed ASMJIT_DEPS - this is now provided by cmake target
aliases - 'asmjit::asmjit' so users should not need this variable
* Changed meaning of ASMJIT_LIBS - this now contains only AsmJit
dependencies without asmjit::asmjit target alias. Don't rely on
ASMJIT_LIBS anymore as it's only used internally
* Removed ASMJIT_NO_DEPRECATED option - AsmJit is not going
to provide controllable deprecations in the future
* Removed ASMJIT_NO_VALIDATION in favor of ASMJIT_NO_INTROSPECTION,
which now controls query, features, and validation API presence
* Removed ASMJIT_DIR option - it was never really needed
* Removed AMX_TRANSPOSE feature from instruction database (X86).
Intel has removed it as well, so it's a feature that won't
be siliconized
148 lines
4.5 KiB
C++
148 lines
4.5 KiB
C++
// This file is part of AsmJit project <https://asmjit.com>
|
|
//
|
|
// See <asmjit/core.h> or LICENSE.md for license and copyright information
|
|
// SPDX-License-Identifier: Zlib
|
|
|
|
#ifndef ASMJIT_CORE_ASSEMBLER_H_INCLUDED
|
|
#define ASMJIT_CORE_ASSEMBLER_H_INCLUDED
|
|
|
|
#include <asmjit/core/codeholder.h>
|
|
#include <asmjit/core/emitter.h>
|
|
#include <asmjit/core/operand.h>
|
|
|
|
ASMJIT_BEGIN_NAMESPACE
|
|
|
|
//! \addtogroup asmjit_assembler
|
|
//! \{
|
|
|
|
//! Base assembler.
|
|
//!
|
|
//! This is a base class that provides interface used by architecture specific assembler implementations. Assembler
|
|
//! doesn't hold any data, instead it's attached to \ref CodeHolder, which provides all the data that Assembler needs
|
|
//! and which can be altered by it.
|
|
//!
|
|
//! Check out architecture specific assemblers for more details and examples:
|
|
//!
|
|
//! - \ref x86::Assembler - X86/X64 assembler implementation.
|
|
//! - \ref a64::Assembler - AArch64 assembler implementation.
|
|
class ASMJIT_VIRTAPI BaseAssembler : public BaseEmitter {
|
|
public:
|
|
ASMJIT_NONCOPYABLE(BaseAssembler)
|
|
using Base = BaseEmitter;
|
|
|
|
//! \name Members
|
|
//! \{
|
|
|
|
//! Current section where the assembling happens.
|
|
Section* _section = nullptr;
|
|
//! Start of the CodeBuffer of the current section.
|
|
uint8_t* _buffer_data = nullptr;
|
|
//! End (first invalid byte) of the current section.
|
|
uint8_t* _buffer_end = nullptr;
|
|
//! Pointer in the CodeBuffer of the current section.
|
|
uint8_t* _buffer_ptr = nullptr;
|
|
|
|
//! \}
|
|
|
|
//! \name Construction & Destruction
|
|
//! \{
|
|
|
|
//! Creates a new `BaseAssembler` instance.
|
|
ASMJIT_API BaseAssembler() noexcept;
|
|
//! Destroys the `BaseAssembler` instance.
|
|
ASMJIT_API ~BaseAssembler() noexcept override;
|
|
|
|
//! \}
|
|
|
|
//! \name Code-Buffer Management
|
|
//! \{
|
|
|
|
//! Returns the capacity of the current CodeBuffer.
|
|
[[nodiscard]]
|
|
ASMJIT_INLINE_NODEBUG size_t buffer_capacity() const noexcept { return (size_t)(_buffer_end - _buffer_data); }
|
|
|
|
//! Returns the number of remaining bytes in the current CodeBuffer.
|
|
[[nodiscard]]
|
|
ASMJIT_INLINE_NODEBUG size_t remaining_space() const noexcept { return (size_t)(_buffer_end - _buffer_ptr); }
|
|
|
|
//! Returns the current position in the CodeBuffer.
|
|
[[nodiscard]]
|
|
ASMJIT_INLINE_NODEBUG size_t offset() const noexcept { return (size_t)(_buffer_ptr - _buffer_data); }
|
|
|
|
//! Sets the current position in the CodeBuffer to `offset`.
|
|
//!
|
|
//! \note The `offset` cannot be greater than buffer size even if it's within the buffer's capacity.
|
|
ASMJIT_API Error set_offset(size_t offset);
|
|
|
|
//! Returns the start of the CodeBuffer in the current section.
|
|
[[nodiscard]]
|
|
ASMJIT_INLINE_NODEBUG uint8_t* buffer_data() const noexcept { return _buffer_data; }
|
|
|
|
//! Returns the end (first invalid byte) in the current section.
|
|
[[nodiscard]]
|
|
ASMJIT_INLINE_NODEBUG uint8_t* buffer_end() const noexcept { return _buffer_end; }
|
|
|
|
//! Returns the current pointer in the CodeBuffer in the current section.
|
|
[[nodiscard]]
|
|
ASMJIT_INLINE_NODEBUG uint8_t* buffer_ptr() const noexcept { return _buffer_ptr; }
|
|
|
|
//! \}
|
|
|
|
//! \name Section Management
|
|
//! \{
|
|
|
|
//! Returns the current section.
|
|
[[nodiscard]]
|
|
ASMJIT_INLINE_NODEBUG Section* current_section() const noexcept { return _section; }
|
|
|
|
ASMJIT_API Error section(Section* section) override;
|
|
|
|
//! \}
|
|
|
|
//! \name Label Management
|
|
//! \{
|
|
|
|
ASMJIT_API Label new_label() override;
|
|
ASMJIT_API Label new_named_label(const char* name, size_t name_size = SIZE_MAX, LabelType type = LabelType::kGlobal, uint32_t parent_id = Globals::kInvalidId) override;
|
|
|
|
ASMJIT_API Error bind(const Label& label) override;
|
|
|
|
//! \}
|
|
|
|
//! \name Embed
|
|
//! \{
|
|
|
|
ASMJIT_API Error embed(const void* data, size_t data_size) override;
|
|
ASMJIT_API Error embed_data_array(TypeId type_id, const void* data, size_t item_count, size_t repeat_count = 1) override;
|
|
ASMJIT_API Error embed_const_pool(const Label& label, const ConstPool& pool) override;
|
|
|
|
ASMJIT_API Error embed_label(const Label& label, size_t data_size = 0) override;
|
|
ASMJIT_API Error embed_label_delta(const Label& label, const Label& base, size_t data_size = 0) override;
|
|
|
|
//! \}
|
|
|
|
//! \name Comment
|
|
//! \{
|
|
|
|
ASMJIT_API Error comment(const char* data, size_t size = SIZE_MAX) override;
|
|
|
|
ASMJIT_INLINE Error comment(Span<const char> data) { return comment(data.data(), data.size()); }
|
|
|
|
//! \}
|
|
|
|
//! \name Events
|
|
//! \{
|
|
|
|
ASMJIT_API Error on_attach(CodeHolder& code) noexcept override;
|
|
ASMJIT_API Error on_detach(CodeHolder& code) noexcept override;
|
|
ASMJIT_API Error on_reinit(CodeHolder& code) noexcept override;
|
|
|
|
//! \}
|
|
};
|
|
|
|
//! \}
|
|
|
|
ASMJIT_END_NAMESPACE
|
|
|
|
#endif // ASMJIT_CORE_ASSEMBLER_H_INCLUDED
|