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 Members

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

Public Types

- Public Types inherited from asmjit::BaseBuilder

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()overridenoexcept◆ 

Destroys the BaseCompiler instance.

Member Function Documentation

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 instruction stream.

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

Creates a new FuncRetNode.

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

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

FuncNode* BaseCompiler::func() constnoexcept◆ 

Returns the current function.

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 instruction stream 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::newInvokeNode(InvokeNode** out, InstId instId, const Operand_& o0, const FuncSignature& signature)◆ 

Creates a new InvokeNode.

Error BaseCompiler::addInvokeNode(InvokeNode** out, InstId instId, const Operand_& o0, const FuncSignature& signature)◆ 

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

Error BaseCompiler::newVirtReg(VirtReg** out, TypeId typeId, OperandSignature 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, TypeId 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, TypeId typeId, const char* fmt, ...)[1/3]◆ 

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::_newRegFmt(BaseReg* out, TypeId typeId)[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::_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, ...)[3/3]◆ 

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, ConstPoolScope scope, 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 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.

Reimplemented in asmjit::x86::Compiler.

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::_constPools[2]◆ 

Local and global constant pools.

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