IndexCompilerasmjit::BaseCompiler

asmjit::BaseCompiler Class Reference [¶]

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

Code emitter that uses virtual registers and performs register allocation.

Compiler is a high-level code-generation tool that provides register allocation and automatic handling of function calling conventions. It was primarily designed for merging multiple parts of code into a function without worrying about registers and function calling conventions.

BaseCompiler can be used, with a minimum effort, to handle 32-bit and 64-bit code generation within a single code base.

BaseCompiler is based on BaseBuilder and contains all the features it provides. It means that the code it stores can be modified (removed, added, injected) and analyzed. When the code is finalized the compiler can emit the code into an Assembler to translate the abstract representation into a machine code.

Check out architecture specific compilers for more details and examples:

Public Types

Public Types inherited from asmjit::BaseBuilder

Member Functions

Construction & Destruction

Passes

Function Management

Function Invocation

Virtual Registers

Stack

Constants

Miscellaneous

Jump Annotations

Events

Public Member Functions inherited from asmjit::BaseBuilder
Public Member Functions inherited from asmjit::BaseEmitter

BaseCompiler::BaseCompiler()noexcept[¶]

Creates a new BaseCompiler instance.

BaseCompiler::~BaseCompiler()overridenoexcept[¶]

Destroys the BaseCompiler instance.

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

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

Error BaseCompiler::new_func_node(
Out<FuncNode*> out,
const FuncSignature& signature
)[¶]

Creates a new FuncNode.

Error BaseCompiler::add_func_node(
Out<FuncNode*> out,
const FuncSignature& signature
)[¶]

Creates a new FuncNode adds it to the instruction stream.

Error BaseCompiler::new_func_ret_node(
const Operand_& o0,
const Operand_& o1
)[¶]

Creates a new FuncRetNode.

Error BaseCompiler::add_func_ret_node(
const Operand_& o0,
const Operand_& o1
)[¶]

Creates a new FuncRetNode and adds it to the instruction stream.

FuncNode* BaseCompiler::func() constnodiscardnoexcept[¶]

Returns the current function.

FuncNode* BaseCompiler::new_func(
const FuncSignature& signature
)[¶]

Creates a new FuncNode with the given signature and returns it.

FuncNode* BaseCompiler::add_func(
const FuncSignature& signature
)[1/2][¶]

Creates a new FuncNode with the given signature, adds it to the instruction stream by using add_func(FuncNode* func) overload, and returns the node.

FuncNode* BaseCompiler::add_func(
FuncNode* ASMJIT_NONNULL func
)[2/2][¶]

Adds a function node to the instruction stream.

Error BaseCompiler::end_func()[¶]

Emits a sentinel that marks the end of the current function.

Error BaseCompiler::new_invoke_node(
Out<InvokeNode*> out,
InstId inst_id,
const Operand_& o0,
const FuncSignature& signature
)[¶]

Creates a new InvokeNode.

Error BaseCompiler::add_invoke_node(
Out<InvokeNode*> out,
InstId inst_id,
const Operand_& o0,
const FuncSignature& signature
)[¶]

Creates a new InvokeNode and adds it to the instruction stream.

Error BaseCompiler::new_virt_reg(
Out<VirtReg*> out,
TypeId type_id,
const char* name
)[¶]

Creates a new virtual register representing the given type_id and signature.

Note

This function is public, but it's not generally recommended to be used by AsmJit users, use architecture specific new_reg() functionality instead or functions like _new_reg() and _new_reg_fmt().

Error BaseCompiler::_new_reg(
Out<Reg> out,
TypeId type_id,
const char* name = nullptr
)[1/2][¶]

Creates a new virtual register of the given type_id and stores it to out operand.

Error BaseCompiler::_new_reg(
Out<Reg> out,
const Reg& ref,
const char* name = nullptr
)[2/2][¶]

Creates a new virtual register compatible with the provided reference register ref.

Error BaseCompiler::_new_reg_fmt(
Out<Reg> out,
TypeId type_id,
const char* fmt,
...
)[1/3][¶]

Creates a new virtual register of the given type_id and stores it to out operand.

Note

This version accepts a snprintf() format fmt followed by variadic arguments.

Error BaseCompiler::_new_reg_fmt(
Out<Reg> out,
TypeId type_id
)[2/3][¶]

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

Error BaseCompiler::_new_reg_fmt(
Out<Reg> out,
const Reg& ref,
const char* fmt,
...
)[3/3][¶]

Creates a new virtual register compatible with the provided reference register ref.

Note

This version accepts a snprintf() format fmt followed by variadic arguments.

bool BaseCompiler::is_virt_id_valid(
uint32_t virt_id
) constnodiscardnoexcept[¶]

Tests whether the given virt_id is a valid virtual register id.

bool BaseCompiler::is_virt_reg_valid(
const Reg& reg
) constnodiscardnoexcept[¶]

Tests whether the given reg is a virtual register having a valid id.

VirtReg* BaseCompiler::virt_reg_by_id(
uint32_t virt_id
) constnodiscardnoexcept[¶]

Returns VirtReg associated with the given virt_id.

VirtReg* BaseCompiler::virt_reg_by_reg(
const Reg& reg
) constnodiscardnoexcept[¶]

Returns VirtReg associated with the given reg.

VirtReg* BaseCompiler::virt_reg_by_index(
uint32_t index
) constnodiscardnoexcept[¶]

Returns VirtReg associated with the given virtual register index.

Note

This is not the same as virtual register id. The conversion between id and its index is implemented by Operand_::virt_id_to_index() and Operand_::virt_index_to_virt_id() functions.

Span<VirtReg*>BaseCompiler::virt_regs() constnodiscardnoexcept[¶]

Returns an array of all virtual registers managed by the Compiler.

Error BaseCompiler::_new_stack(
Out<BaseMem> out,
uint32_t size,
uint32_t alignment,
const char* name = nullptr
)[¶]

Creates a new stack of the given size and alignment and stores it to out.

Note

name can be used to give the stack a name, for debugging purposes.

Error BaseCompiler::set_stack_size(
uint32_t virt_id,
uint32_t new_size,
uint32_t new_alignment = 0
)[1/2][¶]

Updates the stack size of a stack created by _new_stack() by its virt_id.

Error BaseCompiler::set_stack_size(
const BaseMem& mem,
uint32_t new_size,
uint32_t new_alignment = 0
)[2/2][¶]

Updates the stack size of a stack created by _new_stack().

Error BaseCompiler::_new_const(
Out<BaseMem> out,
const void* data,
size_t size
)[¶]

Creates a new constant of the given scope (see ConstPoolScope).

This function adds a constant of the given size to the built-in ConstPool and stores the reference to that constant to the out operand.

void BaseCompiler::rename(
const Reg& reg,
const char* fmt,
...
)[¶]

Rename the given virtual register reg to a formatted string fmt.

JumpAnnotation* BaseCompiler::new_jump_annotation()nodiscard[¶]

Returns a new JumpAnnotation instance, which can be used to aggregate possible targets of a jump where the target is not a label, for example to implement jump tables.

Error BaseCompiler::on_attach()overridenoexcept[¶]

Called after the emitter was attached to CodeHolder.

Reimplemented from asmjit::BaseBuilder.

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

Error BaseCompiler::on_detach()overridenoexcept[¶]

Called after the emitter was detached from CodeHolder.

Reimplemented from asmjit::BaseBuilder.

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

Error BaseCompiler::on_reinit()overridenoexcept[¶]

Called when CodeHolder is reinitialized when the emitter is attached.

Reimplemented from asmjit::BaseBuilder.

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

FuncNode* BaseCompiler::_func[¶]

Current function.

ArenaVector<VirtReg*>BaseCompiler::_virt_regs[¶]

Stores array of VirtReg pointers.

ArenaVector<JumpAnnotation*>BaseCompiler::_jump_annotations[¶]

Stores jump annotations.

ConstPoolNode* BaseCompiler::_const_pools[2][¶]

Local and global constant pools.

Local constant pool is flushed with each function, global constant pool is flushed only by finalize().