AsmJit
Low-Latency Machine Code Generation
Provides a base foundation to emitting code - specialized by BaseAssembler and BaseBuilder.
Returns the type of this emitter, see EmitterType
.
Returns emitter flags , see Flags
.
Tests whether the emitter inherits from BaseAssembler
.
Tests whether the emitter inherits from BaseBuilder
.
true
. Tests whether the emitter inherits from BaseCompiler
.
Tests whether the emitter has the given flag
enabled.
Tests whether the emitter is finalized.
Tests whether the emitter is destroyed (only used during destruction).
Returns the CodeHolder this emitter is attached to.
Returns the target environment.
The returned Environment reference matches CodeHolder::environment().
Tests whether the target architecture is 32-bit.
Tests whether the target architecture is 64-bit.
Returns the target architecture type.
Returns the target architecture sub-type.
Returns the target architecture's GP register size (4 or 8 bytes).
Returns a signature of a native general purpose register (either 32-bit or 64-bit depending on the architecture).
Returns instruction alignment.
The following values are returned based on the target architecture:
Tests whether the emitter is initialized (i.e. attached to CodeHolder).
Finalizes this emitter.
Materializes the content of the emitter by serializing it to the attached CodeHolder through an architecture specific BaseAssembler. This function won't do anything if the emitter inherits from BaseAssembler as assemblers emit directly to a CodeBuffer held by CodeHolder. However, if this is an emitter that inherits from BaseBuilder or BaseCompiler then these emitters need the materialization phase as they store their content in a representation not visible to CodeHolder.
Reimplemented in asmjit::a64::Builder, asmjit::a64::Compiler, asmjit::x86::Builder, and asmjit::x86::Compiler.
Tests whether the emitter has a logger.
Tests whether the emitter has its own logger.
Own logger means that it overrides the possible logger that may be used by CodeHolder this emitter is attached to.
Returns the logger this emitter uses.
The returned logger is either the emitter's own logger or it's logger used by CodeHolder this emitter is attached to.
Sets or resets the logger of the emitter.
If the logger
argument is non-null then the logger will be considered emitter's own logger, see hasOwnLogger() for more details. If the given logger
is null then the emitter will automatically use logger that is attached to the CodeHolder this emitter is attached to.
Resets the logger of this emitter.
The emitter will bail to using a logger attached to CodeHolder this emitter is attached to, or no logger at all if CodeHolder doesn't have one.
Tests whether the emitter has an error handler attached.
Tests whether the emitter has its own error handler.
Own error handler means that it overrides the possible error handler that may be used by CodeHolder this emitter is attached to.
Returns the error handler this emitter uses.
The returned error handler is either the emitter's own error handler or it's error handler used by CodeHolder this emitter is attached to.
Sets or resets the error handler of the emitter.
Resets the error handler.
nullptr
)◆ Handles the given error in the following way:
handleError()
function may throw.Returns encoding options.
Tests whether the encoding option
is set.
Enables the given encoding options
.
Disables the given encoding options
.
Returns the emitter's diagnostic options.
Tests whether the given option
is present in the emitter's diagnostic options.
Activates the given diagnostic options
.
This function is used to activate explicit validation options that will be then used by all emitter implementations. There are in general two possibilities:
Architecture specific assembler is used. In this case a DiagnosticOptions::kValidateAssembler can be used to turn on explicit validation that will be used before an instruction is emitted. This means that internally an extra step will be performed to make sure that the instruction is correct. This is needed, because by default assemblers prefer speed over strictness.
This option should be used in debug builds as it's pretty expensive.
Deactivates the given validation options
.
See addDiagnosticOptions() and DiagnosticOptions for more details.
Returns forced instruction options.
Forced instruction options are merged with next instruction options before the instruction is encoded. These options have some bits reserved that are used by error handling, logging, and instruction validation purposes. Other options are globals that affect each instruction.
Returns options of the next instruction.
Returns options of the next instruction.
Adds options of the next instruction.
Resets options of the next instruction.
Tests whether the extra register operand is valid.
Returns an extra operand that will be used by the next instruction (architecture specific).
Sets an extra operand that will be used by the next instruction (architecture specific).
Sets an extra operand that will be used by the next instruction (architecture specific).
Resets an extra operand that will be used by the next instruction (architecture specific).
Returns comment/annotation of the next instruction.
Sets comment/annotation of the next instruction.
_emit()
, but until that it has to remain valid as the Emitter is not required to make a copy of it (and it would be slow to do that for each instruction). Resets the comment/annotation to nullptr.
Resets the emitter state, which contains instruction options, extra register, and inline comment.
Emitter can have a state that describes instruction options and extra register used by the instruction. Most instructions don't need nor use the state, however, if an instruction uses a prefix such as REX or REP prefix, which is set explicitly, then the state would contain it. This allows to mimic the syntax of assemblers such as X86. For example rep().movs(...)
would map to a REP MOVS
instuction on X86. The same applies to various hints and the use of a mask register in AVX-512 mode.
Switches the given section
.
Once switched, everything is added to the given section
.
Reimplemented in asmjit::BaseAssembler, and asmjit::BaseBuilder.
Creates a new label.
Reimplemented in asmjit::BaseAssembler, and asmjit::BaseBuilder.
SIZE_MAX
, LabelType type = LabelType::kGlobal
, uint32_t parentId = Globals::kInvalidId
)virtual◆ Creates a new named label.
Reimplemented in asmjit::BaseAssembler, and asmjit::BaseBuilder.
SIZE_MAX
)◆ Creates a new anonymous label with a name, which can only be used for debugging purposes.
SIZE_MAX
)◆ Creates a new external label.
SIZE_MAX
, uint32_t parentId = Globals::kInvalidId
)noexcept◆ Returns Label
by name
.
Returns invalid Label in case that the name is invalid or label was not found.
Label
returned. Binds the label
to the current position of the current section.
Reimplemented in asmjit::BaseAssembler, and asmjit::BaseBuilder.
Tests whether the label id
is valid (i.e. registered).
Tests whether the label
is valid (i.e. registered).
Emits an instruction (internal).
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Emits an instruction instId
with the given operands
.
This is the most universal way of emitting code, which accepts an instruction identifier and instruction operands. This is called an "unchecked" API as emit doesn't provide any type checks at compile-time. This allows to emit instruction with just Operand instances, which could be handy in some cases - for example emitting generic code where you don't know whether some operand is register, memory, or immediate.
Similar to emit(), but uses array of operands
instead.
Similar to emit(), but emits instruction with both instruction options and extra register, followed by an array of operands
.
Emits a function prolog described by the given function frame
.
Emits a function epilog described by the given function frame
.
Emits code that reassigns function frame
arguments to the given args
.
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 in asmjit::a64::Assembler, asmjit::BaseBuilder, and asmjit::x86::Assembler.
Embeds raw data into the CodeBuffer.
Reimplemented in asmjit::BaseAssembler, and asmjit::BaseBuilder.
1
)virtual◆ 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 in asmjit::BaseBuilder, and asmjit::BaseAssembler.
1
)◆ Embeds int8_t value
repeated by repeatCount
.
1
)◆ Embeds uint8_t value
repeated by repeatCount
.
1
)◆ Embeds int16_t value
repeated by repeatCount
.
1
)◆ Embeds uint16_t value
repeated by repeatCount
.
1
)◆ Embeds int32_t value
repeated by repeatCount
.
1
)◆ Embeds uint32_t value
repeated by repeatCount
.
1
)◆ Embeds int64_t value
repeated by repeatCount
.
1
)◆ Embeds uint64_t value
repeated by repeatCount
.
1
)◆ Embeds a floating point value
repeated by repeatCount
.
1
)◆ Embeds a floating point value
repeated by repeatCount
.
Embeds a constant pool at the current offset by performing the following:
pool
alignment.Reimplemented in asmjit::BaseAssembler, and asmjit::BaseBuilder.
0
)virtual◆ 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 in asmjit::BaseAssembler, and asmjit::BaseBuilder.
0
)virtual◆ 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 in asmjit::BaseAssembler, and asmjit::BaseBuilder.
SIZE_MAX
)virtual◆ Emits a comment stored in data
with an optional size
parameter.
Reimplemented in asmjit::BaseAssembler, and asmjit::BaseBuilder.
Emits a formatted comment specified by fmt
and variable number of arguments.
Emits a formatted comment specified by fmt
and ap
.
Called after the emitter was attached to CodeHolder
.
Reimplemented in asmjit::a64::Assembler, asmjit::a64::Builder, asmjit::a64::Compiler, asmjit::BaseAssembler, asmjit::BaseBuilder, asmjit::BaseCompiler, asmjit::x86::Assembler, asmjit::x86::Builder, and asmjit::x86::Compiler.
Called after the emitter was detached from CodeHolder
.
Reimplemented in asmjit::a64::Assembler, asmjit::a64::Builder, asmjit::a64::Compiler, asmjit::BaseAssembler, asmjit::BaseBuilder, asmjit::BaseCompiler, asmjit::x86::Assembler, asmjit::x86::Builder, and asmjit::x86::Compiler.
Called when CodeHolder has updated an important setting, which involves the following:
This function ensures that the settings are properly propagated from CodeHolder to the emitter.
See EmitterType.
See EmitterFlags.
Instruction alignment.
Validation flags in case validation is used.
Validation options.
All supported architectures in a bit-mask, where LSB is the bit with a zero index.
Encoding options.
Forced instruction options, combined with _instOptions by emit().
Internal private data used freely by any emitter.
CodeHolder the emitter is attached to.
Attached Logger.
Attached ErrorHandler.
Describes the target environment, matches CodeHolder::environment().
Native GP register signature and signature related information.
Next instruction options (affects the next instruction).
Extra register (op-mask {k} on AVX-512) (affects the next instruction).
Inline comment of the next instruction (affects the next instruction).