asmjit::BaseCompiler Class Reference

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 Members

- Public Attributes inherited from asmjit::BaseBuilder
- Public Attributes inherited from asmjit::BaseEmitter

Public Types

- Public Types inherited from asmjit::BaseBuilder
- Public Types inherited from asmjit::BaseEmitter

Member Functions

Construction & Destruction
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

Constructor & Destructor Documentation

BaseCompiler::BaseCompiler()noexcept

Creates a new BaseCompiler instance.

BaseCompiler::~BaseCompiler()virtualnoexcept

Destroys the BaseCompiler instance.

Member Function Documentation

FuncNode* BaseCompiler::func() constnoexcept

Returns the current function.

Error BaseCompiler::_newFuncNode(FuncNode** out, const FuncSignature& signature)

Creates a new FuncNode.

Error BaseCompiler::_addFuncNode(FuncNode** out, const FuncSignature& signature)

Creates a new FuncNode adds it to the compiler.

Error BaseCompiler::_newRetNode(FuncRetNode** out, const Operand_& o0, const Operand_& o1)

Creates a new FuncRetNode.

Error BaseCompiler::_addRetNode(FuncRetNode** out, const Operand_& o0, const Operand_& o1)

Creates a new FuncRetNode and adds it to the compiler.

FuncNode* BaseCompiler::newFunc(const FuncSignature& signature)

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

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

Creates a new FuncNode with the given signature, adds it to the compiler by using the addFunc(FuncNode*) overload, and returns it.

FuncNode* BaseCompiler::addFunc(FuncNode* func)[2/2]

Adds a function node to the instruction stream.

Error BaseCompiler::endFunc()

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

Error BaseCompiler::setArg(uint32_t argIndex, const BaseReg& reg)

Sets a function argument at argIndex to reg.

Error BaseCompiler::_newInvokeNode(InvokeNode** out, uint32_t instId, const Operand_& o0, const FuncSignature& signature)

Creates a new InvokeNode.

Error BaseCompiler::_addInvokeNode(InvokeNode** out, uint32_t instId, const Operand_& o0, const FuncSignature& signature)

Creates a new InvokeNode and adds it to Compiler.

InvokeNode* BaseCompiler::newCall(uint32_t instId, const Operand_& o0, const FuncSignature& signature)

Creates a new InvokeNode.

InvokeNode* BaseCompiler::addCall(uint32_t instId, const Operand_& o0, const FuncSignature& signature)

Adds a new InvokeNode.

Error BaseCompiler::newVirtReg(VirtReg** out, uint32_t typeId, uint32_t signature, const char* name)

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

Note
This function is public, but it's not generally recommended to be used by AsmJit users, use architecture-specific newReg() functionality instead or functions like _newReg() and _newRegFmt().

Error BaseCompiler::_newReg(BaseReg* out, uint32_t typeId, const char* name = nullptr)[1/2]

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

Error BaseCompiler::_newRegFmt(BaseReg* out, uint32_t typeId, const char* fmt, ...)[1/2]

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

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

Error BaseCompiler::_newReg(BaseReg* out, const BaseReg& ref, const char* name = nullptr)[2/2]

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

Error BaseCompiler::_newRegFmt(BaseReg* out, const BaseReg& ref, const char* fmt, ...)[2/2]

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

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

bool BaseCompiler::isVirtIdValid(uint32_t id) constnoexcept

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

bool BaseCompiler::isVirtRegValid(const BaseReg& reg) constnoexcept

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

VirtReg* BaseCompiler::virtRegById(uint32_t id) constnoexcept

Returns VirtReg associated with the given id.

VirtReg* BaseCompiler::virtRegByReg(const BaseReg& reg) constnoexcept

Returns VirtReg associated with the given reg.

VirtReg* BaseCompiler::virtRegByIndex(uint32_t index) constnoexcept

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_::virtIdToIndex() and Operand_::indexToVirtId() functions.

const ZoneVector<VirtReg*>& BaseCompiler::virtRegs() constnoexcept

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

Error BaseCompiler::_newStack(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::setStackSize(uint32_t virtId, uint32_t newSize, uint32_t newAlignment = 0)[1/2]

Updates the stack size of a stack created by _newStack() by its virtId.

Error BaseCompiler::setStackSize(const BaseMem& mem, uint32_t newSize, uint32_t newAlignment = 0)[2/2]

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

Error BaseCompiler::_newConst(BaseMem* out, uint32_t scope, const void* data, size_t size)

Creates a new constant of the given scope (see ConstPool::Scope).

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 BaseReg& reg, const char* fmt, ...)

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

JumpAnnotation* BaseCompiler::newJumpAnnotation()

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::onAttach(CodeHolder* code)overridenoexcept

Called after the emitter was attached to CodeHolder.

Reimplemented from asmjit::BaseBuilder.

Reimplemented in asmjit::x86::Compiler.

Error BaseCompiler::onDetach(CodeHolder* code)overridenoexcept

Called after the emitter was detached from CodeHolder.

Reimplemented from asmjit::BaseBuilder.

Member Data Documentation

FuncNode* BaseCompiler::_func

Current function.

Zone BaseCompiler::_vRegZone

Allocates VirtReg objects.

ZoneVector<VirtReg*>BaseCompiler::_vRegArray

Stores array of VirtReg pointers.

ZoneVector<JumpAnnotation*>BaseCompiler::_jumpAnnotations

Stores jump annotations.

ConstPoolNode* BaseCompiler::_localConstPool

Local constant pool, flushed at the end of each function.

ConstPoolNode* BaseCompiler::_globalConstPool

Global constant pool, flushed by finalize().