IndexBuilderasmjit::BaseBuilder

asmjit::BaseBuilder Class Reference [¶]

Inheritance diagram for asmjit::BaseBuilder:
asmjit::BaseEmitter asmjit::BaseCompiler asmjit::a64::Builder asmjit::x86::Builder asmjit::a64::Compiler asmjit::x86::Compiler

Builder interface.

BaseBuilder interface was designed to be used as a BaseAssembler replacement in case pre-processing or post-processing of the generated code is required. The code can be modified during or after code generation. Pre processing or post processing can be done manually or through a Pass object. BaseBuilder stores the emitted code as a double-linked list of nodes, which allows O(1) insertion and removal during processing.

Check out architecture specific builders for more details and examples:

Public Types

Member Functions

Construction & Destruction

Node Management

Section Management

Label Management

Passes

Emit

Align

Embed

Comment

Serialization

Events

Public Member Functions inherited from asmjit::BaseEmitter

BaseBuilder::BaseBuilder()noexcept[¶]

Creates a new BaseBuilder instance.

BaseBuilder::~BaseBuilder()overridenoexcept[¶]

Destroys the BaseBuilder instance.

NodeList BaseBuilder::node_list() constnodiscardnoexcept[¶]

Returns first and last node of Builder/Compiler wrapped in NodeList.

BaseNode* BaseBuilder::first_node() constnodiscardnoexcept[¶]

Returns the first node.

BaseNode* BaseBuilder::last_node() constnodiscardnoexcept[¶]

Returns the last node.

template<typename T, typename... Args>
Error BaseBuilder::new_node_with_size_t(
Out<T*> out,
size_t size,
Args&&... args
)[¶]

Allocates data required for a node.

template<typename T, typename... Args>
Error BaseBuilder::new_node_t(
Out<T*> out,
Args&&... args
)[¶]

Allocates and instantiates a new node of type T and returns its instance. If the allocation fails nullptr is returned.

The template argument T must be a type that is extends BaseNode.

Remarks

The pointer returned (if non-null) is owned by the Builder or Compiler. When the Builder/Compiler is destroyed it destroys all nodes it created so no manual memory management is required.

Error BaseBuilder::new_inst_node(
Out<InstNode*> out,
InstId inst_id,
InstOptions inst_options,
uint32_t op_count
)[¶]

Creates a new InstNode.

Error BaseBuilder::new_label_node()[¶]

Creates a new LabelNode.

Error BaseBuilder::new_align_node(
Out<AlignNode*> out,
AlignMode align_mode,
uint32_t alignment
)[¶]

Creates a new AlignNode.

Error BaseBuilder::new_embed_data_node(
TypeId type_id,
const void* data,
size_t item_count,
size_t repeat_count = 1
)[¶]

Creates a new EmbedDataNode.

Error BaseBuilder::new_const_pool_node()[¶]

Creates a new ConstPoolNode.

Error BaseBuilder::new_comment_node(
const char* data,
size_t size
)[¶]

Creates a new CommentNode.

BaseNode* BaseBuilder::add_node(
BaseNode* ASMJIT_NONNULL node
)noexcept[¶]

Adds node after the current and sets the current node to the given node.

BaseNode* BaseBuilder::add_after(

Inserts the given node after ref.

BaseNode* BaseBuilder::add_before(

Inserts the given node before ref.

BaseNode* BaseBuilder::remove_node(
BaseNode* ASMJIT_NONNULL node
)noexcept[¶]

Removes the given node.

void BaseBuilder::remove_nodes(
BaseNode* first,
BaseNode* last
)noexcept[¶]

Removes multiple nodes.

BaseNode* BaseBuilder::cursor() constnodiscardnoexcept[¶]

Returns the cursor.

When the Builder/Compiler is created it automatically creates a '.text' SectionNode, which will be the initial one. When instructions are added they are always added after the cursor and the cursor is changed to be that newly added node. Use set_cursor() to change where new nodes are inserted.

BaseNode* BaseBuilder::set_cursor(
BaseNode* node
)noexcept[¶]

Sets the current cursor to node and returns the previous one.

Remarks

This function returns the previous cursor for convenience, but the return value can be safely ignored in case it's not important for the user.

Span<SectionNode*>BaseBuilder::section_nodes() constnodiscardnoexcept[¶]

Returns a vector of SectionNode objects.

Note

If a section of some id is not associated with the Builder/Compiler it would be null, so always check for nulls if you iterate over the vector.

bool BaseBuilder::has_registered_section_node(
uint32_t section_id
) constnodiscardnoexcept[¶]

Tests whether the SectionNode of the given section_id was registered.

Error BaseBuilder::section_node_of(
uint32_t section_id
)[¶]

Returns or creates a SectionNode that matches the given section_id.

Remarks

This function will either get the existing SectionNode or create it in case it wasn't created before. You can check whether a section has a registered SectionNode by using BaseBuilder::has_registered_section_node().

bool BaseBuilder::has_dirty_section_links() constnodiscardnoexcept[¶]

Returns whether the section links of active section nodes are dirty. You can update these links by calling update_section_links() in such case.

void BaseBuilder::update_section_links()noexcept[¶]

Updates links of all active section nodes.

Span<LabelNode*>BaseBuilder::label_nodes() constnodiscardnoexcept[¶]

Returns a vector of LabelNode nodes.

Note

If a label of some id is not associated with the Builder/Compiler it would be null, so always check for nulls if you iterate over the vector.

bool BaseBuilder::has_registered_label_node(
uint32_t label_id
) constnodiscardnoexcept[1/2][¶]

Tests whether the LabelNode of the given label_id was registered.

bool BaseBuilder::has_registered_label_node(
const Label& label
) constnodiscardnoexcept[2/2][¶]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Error BaseBuilder::label_node_of(
Out<LabelNode*> out,
uint32_t label_id
)[1/2][¶]

Gets or creates a LabelNode that matches the given label_id.

Remarks

This function will either get the existing LabelNode or create it in case it wasn't created before. You can check whether a label has a registered LabelNode by calling BaseBuilder::has_registered_label_node().

Error BaseBuilder::label_node_of(
Out<LabelNode*> out,
const Label& label
)[2/2][¶]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Error BaseBuilder::register_label_node(
LabelNode* ASMJIT_NONNULL node
)nodiscard[¶]

Registers this LabelNode (internal).

This function is used internally to register a newly created LabelNode with this instance of Builder/Compiler. Use label_node_of() functions to get back LabelNode from a label or its identifier.

Label BaseBuilder::new_label()nodiscardoverride[¶]

Creates a new label.

Reimplemented from asmjit::BaseEmitter.

Label BaseBuilder::new_named_label(
const char* name,
size_t name_size = SIZE_MAX,
uint32_t parent_id = Globals::kInvalidId
)nodiscardoverride[¶]

Creates a new named label.

Reimplemented from asmjit::BaseEmitter.

Error BaseBuilder::bind(
const Label& label
)override[¶]

Binds the label to the current position of the current section.

Note

Attempt to bind the same label multiple times will return an error.

Reimplemented from asmjit::BaseEmitter.

Span<Pass*>BaseBuilder::passes() constnodiscardnoexcept[¶]

Returns a vector of Pass instances that will be executed by run_passes().

template<typename PassT, typename... Args>
PassT* BaseBuilder::new_pass(
Args&&... args
)nodiscardnoexcept[¶]

Allocates and instantiates a new pass of type T and returns its instance. If the allocation fails nullptr is returned.

The template argument T must be a type that is extends Pass.

Remarks

The pointer returned (if non-null) is owned by the Builder or Compiler. When the Builder/Compiler is destroyed it destroys all passes it created so no manual memory management is required.

Pass* BaseBuilder::pass_by_name(
const char* name
) constnodiscardnoexcept[¶]

Returns Pass by name.

If the pass having the given name doesn't exist nullptr is returned.

Error BaseBuilder::_add_pass(
Pass* pass
)noexcept[¶]

Adds pass to the list of passes.

Error BaseBuilder::run_passes()[¶]

Runs all passes in order.

Error BaseBuilder::align(
AlignMode align_mode,
uint32_t alignment
)override[¶]

Aligns the current CodeBuffer position to the alignment specified.

The sequence that is used to fill the gap between the aligned location and the current location depends on the align mode, see AlignMode. The alignment argument specifies alignment in bytes, so for example when it's 32 it means that the code buffer will be aligned to 32 bytes.

Reimplemented from asmjit::BaseEmitter.

Error BaseBuilder::embed(
const void* data,
size_t data_size
)override[¶]

Embeds raw data into the CodeBuffer.

Reimplemented from asmjit::BaseEmitter.

Error BaseBuilder::embed_data_array(
TypeId type_id,
const void* data,
size_t item_count,
size_t repeat_count = 1
)override[¶]

Embeds a typed data array.

This is the most flexible function for embedding data as it allows to:

  • Assign a type_id to the data, so the emitter knows the type of items stored in data. Binary data should use TypeId::kUInt8.
  • Repeat the given data repeat_count times, so the data can be used as a fill pattern for example, or as a pattern used by SIMD instructions.

Reimplemented from asmjit::BaseEmitter.

Error BaseBuilder::embed_const_pool(
const Label& label,
const ConstPool& pool
)override[¶]

Embeds a constant pool at the current offset by performing the following:

  1. Aligns by using AlignMode::kData to the minimum pool alignment.
  2. Binds the ConstPool label so it's bound to an aligned location.
  3. Emits ConstPool content.

Reimplemented from asmjit::BaseEmitter.

Error BaseBuilder::embed_label(
const Label& label,
size_t data_size = 0
)override[¶]

Embeds an absolute label address as data.

The data_size is an optional argument that can be used to specify the size of the address data. If it's zero (default) the address size is deduced from the target architecture (either 4 or 8 bytes).

Reimplemented from asmjit::BaseEmitter.

Error BaseBuilder::embed_label_delta(
const Label& label,
const Label& base,
size_t data_size = 0
)override[¶]

Embeds a delta (distance) between the label and base calculating it as label - base. This function was designed to make it easier to embed lookup tables where each index is a relative distance of two labels.

Reimplemented from asmjit::BaseEmitter.

Error BaseBuilder::comment(
const char* data,
size_t size = SIZE_MAX
)override[¶]

Emits a comment stored in data with an optional size parameter.

Reimplemented from asmjit::BaseEmitter.

Error BaseBuilder::serialize_to()[¶]

Serializes everything the given emitter dst.

Although not explicitly required the emitter will most probably be of Assembler type. The reason is that there is no known use of serializing nodes held by Builder/Compiler into another Builder-like emitter.

Error BaseBuilder::on_attach()overridenoexcept[¶]

Called after the emitter was attached to CodeHolder.

Reimplemented from asmjit::BaseEmitter.

Reimplemented in asmjit::a64::Builder, asmjit::a64::Compiler, asmjit::BaseCompiler, asmjit::x86::Builder, and asmjit::x86::Compiler.

Error BaseBuilder::on_detach()overridenoexcept[¶]

Called after the emitter was detached from CodeHolder.

Reimplemented from asmjit::BaseEmitter.

Reimplemented in asmjit::a64::Builder, asmjit::a64::Compiler, asmjit::BaseCompiler, asmjit::x86::Builder, and asmjit::x86::Compiler.

Error BaseBuilder::on_reinit()overridenoexcept[¶]

Called when CodeHolder is reinitialized when the emitter is attached.

Reimplemented from asmjit::BaseEmitter.

Reimplemented in asmjit::a64::Compiler, asmjit::BaseCompiler, and asmjit::x86::Compiler.

Arena BaseBuilder::_builder_arena[¶]

Arena used to allocate nodes and passes.

Arena BaseBuilder::_pass_arena[¶]

Arena only used by Pass::run().

ArenaVector<Pass*>BaseBuilder::_passes[¶]

Array of Pass objects.

ArenaVector<SectionNode*>BaseBuilder::_section_nodes[¶]

Maps section indexes to LabelNode nodes.

ArenaVector<LabelNode*>BaseBuilder::_label_nodes[¶]

Maps label indexes to LabelNode nodes.

BaseNode* BaseBuilder::_cursor = nullptr[¶]

Current node (cursor).

NodeList BaseBuilder::_node_list[¶]

First and last nodes.

bool BaseBuilder::_dirty_section_links = false[¶]

The sections links are dirty (used internally).