![](../resources/images/asmjit-logo.png)
AsmJit
Low-Latency Machine Code Generation
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:
Creates a new BaseBuilder
instance.
Destroys the BaseBuilder
instance.
Returns the first node.
Returns the last node.
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.
Creates a new InstNode.
Creates a new LabelNode.
Creates a new AlignNode.
1
)◆ Creates a new EmbedDataNode.
Creates a new ConstPoolNode.
Creates a new CommentNode.
Adds node
after the current and sets the current node to the given node
.
Inserts the given node
after ref
.
Inserts the given node
before ref
.
Removes the given node
.
Removes multiple nodes.
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 setCursor()
to change where new nodes are inserted.
Sets the current node to node
and return the previous one.
Sets the current node without returning the previous node.
Only use this function if you are concerned about performance and want this inlined (for example if you set the cursor in a loop, etc...).
Returns a vector of SectionNode objects.
Tests whether the SectionNode
of the given sectionId
was registered.
Returns or creates a SectionNode
that matches the given sectionId
.
SectionNode
or create it in case it wasn't created before. You can check whether a section has a registered SectionNode
by using BaseBuilder::hasRegisteredSectionNode()
. Switches the given section
.
Once switched, everything is added to the given section
.
Reimplemented from asmjit::BaseEmitter.
Returns whether the section links of active section nodes are dirty.
You can update these links by calling updateSectionLinks()
in such case.
Updates links of all active section nodes.
Returns a vector of LabelNode nodes.
Tests whether the LabelNode
of the given labelId
was registered.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Gets or creates a LabelNode that matches the given labelId
.
LabelNode
or create it in case it wasn't created before. You can check whether a label has a registered LabelNode
by calling BaseBuilder::hasRegisteredLabelNode(). This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Registers this LabelNode (internal).
This function is used internally to register a newly created LabelNode
with this instance of Builder/Compiler. Use labelNodeOf() functions to get back LabelNode from a label or its identifier.
Creates a new label.
Reimplemented from asmjit::BaseEmitter.
SIZE_MAX
, LabelType type = LabelType::kGlobal
, uint32_t parentId = Globals::kInvalidId
)override◆ Creates a new named label.
Reimplemented from asmjit::BaseEmitter.
Binds the label
to the current position of the current section.
Reimplemented from asmjit::BaseEmitter.
Returns a vector of Pass
instances that will be executed by runPasses()
.
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.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns Pass
by name.
If the pass having the given name
doesn't exist nullptr
is returned.
Adds pass
to the list of passes.
Removes pass
from the list of passes and delete it.
Runs all passes in order.
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.
Embeds raw data into the CodeBuffer.
Reimplemented from asmjit::BaseEmitter.
1
)override◆ Embeds a typed data array.
This is the most flexible function for embedding data as it allows to:
typeId
to the data, so the emitter knows the type of items stored in data
. Binary data should use TypeId::kUInt8.repeatCount
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.
Embeds a constant pool at the current offset by performing the following:
pool
alignment.Reimplemented from asmjit::BaseEmitter.
0
)override◆ Embeds an absolute label
address as data.
The dataSize
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.
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.
SIZE_MAX
)override◆ Emits a comment stored in data
with an optional size
parameter.
Reimplemented from asmjit::BaseEmitter.
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.
Called after the emitter was attached to CodeHolder
.
Reimplemented from asmjit::BaseEmitter.
Reimplemented in asmjit::BaseCompiler, asmjit::x86::Builder, and asmjit::x86::Compiler.
Called after the emitter was detached from CodeHolder
.
Reimplemented from asmjit::BaseEmitter.
Reimplemented in asmjit::BaseCompiler, asmjit::x86::Builder, and asmjit::x86::Compiler.
Base zone used to allocate nodes and passes.
Data zone used to allocate data and names.
Pass zone, passed to Pass::run()
.
Allocator that uses _codeZone
.
Array of Pass
objects.
Maps section indexes to LabelNode
nodes.
Maps label indexes to LabelNode
nodes.
Current node (cursor).
First and last nodes.
Flags assigned to each new node.
The sections links are dirty (used internally).