asmjit::BaseAssembler Class Reference
Inheritance diagram for asmjit::BaseAssembler:
asmjit::BaseEmitter asmjit::a64::Assembler asmjit::x86::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 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:

Public Members

- Public Attributes inherited from asmjit::BaseEmitter

Public Types

Member Functions

Construction & Destruction
Code-Buffer Management
Section Management
Label Management
- Public Member Functions inherited from asmjit::BaseEmitter

Constructor & Destructor Documentation


Creates a new BaseAssembler instance.


Destroys the BaseAssembler instance.

Member Function Documentation

size_t BaseAssembler::bufferCapacity() constnoexcept◆ 

Returns the capacity of the current CodeBuffer.

size_t BaseAssembler::remainingSpace() constnoexcept◆ 

Returns the number of remaining bytes in the current CodeBuffer.

size_t BaseAssembler::offset() constnoexcept◆ 

Returns the current position in the CodeBuffer.

Error BaseAssembler::setOffset(size_t offset)◆ 

Sets the current position in the CodeBuffer to offset.

The offset cannot be greater than buffer size even if it's within the buffer's capacity.

uint8_t* BaseAssembler::bufferData() constnoexcept◆ 

Returns the start of the CodeBuffer in the current section.

uint8_t* BaseAssembler::bufferEnd() constnoexcept◆ 

Returns the end (first invalid byte) in the current section.

uint8_t* BaseAssembler::bufferPtr() constnoexcept◆ 

Returns the current pointer in the CodeBuffer in the current section.

Section* BaseAssembler::currentSection() constnoexcept◆ 

Returns the current section.

Error BaseAssembler::section(Section* section)override◆ 

Switches the given section.

Once switched, everything is added to the given section.

Reimplemented from asmjit::BaseEmitter.

Label BaseAssembler::newLabel()override◆ 

Creates a new label.

Reimplemented from asmjit::BaseEmitter.

Label BaseAssembler::newNamedLabel(const char* name, size_t nameSize = SIZE_MAX, LabelType type = LabelType::kGlobal, uint32_t parentId = Globals::kInvalidId)override◆ 

Creates a new named label.

Reimplemented from asmjit::BaseEmitter.

Error BaseAssembler::bind(const Label& label)override◆ 

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

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

Reimplemented from asmjit::BaseEmitter.

Error BaseAssembler::embed(const void* data, size_t dataSize)override◆ 

Embeds raw data into the CodeBuffer.

Reimplemented from asmjit::BaseEmitter.

Error BaseAssembler::embedDataArray(TypeId typeId, const void* data, size_t itemCount, size_t repeatCount = 1)override◆ 

Embeds a typed data array.

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

  • Assign a typeId to the data, so the emitter knows the type of items stored in data. Binary data should use TypeId::kUInt8.
  • Repeat the given data 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.

Error BaseAssembler::embedConstPool(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 BaseAssembler::embedLabel(const Label& label, size_t dataSize = 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.

Error BaseAssembler::embedLabelDelta(const Label& label, const Label& base, size_t dataSize = 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 BaseAssembler::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 BaseAssembler::onAttach(CodeHolder* code)overridenoexcept◆ 

Called after the emitter was attached to CodeHolder.

Reimplemented from asmjit::BaseEmitter.

Reimplemented in asmjit::x86::Assembler.

Error BaseAssembler::onDetach(CodeHolder* code)overridenoexcept◆ 

Called after the emitter was detached from CodeHolder.

Reimplemented from asmjit::BaseEmitter.

Reimplemented in asmjit::x86::Assembler.

Member Data Documentation

Section* BaseAssembler::_section = nullptr◆ 

Current section where the assembling happens.

uint8_t* BaseAssembler::_bufferData = nullptr◆ 

Start of the CodeBuffer of the current section.

uint8_t* BaseAssembler::_bufferEnd = nullptr◆ 

End (first invalid byte) of the current section.

uint8_t* BaseAssembler::_bufferPtr = nullptr◆ 

Pointer in the CodeBuffer of the current section.