Machine Code Generation for C++
BaseCompiler is a high-level interface built on top of BaseBuilder interface, which provides register allocation and support for defining and invoking functions. At the moment it's the easiest way of generating code in AsmJit as most architecture and OS specifics is properly abstracted and handled by AsmJit automatically. However, abstractions also mean restrictions, which means that BaseCompiler has more limitations that BaseAssembler or BaseBuilder.
Since BaseCompiler provides register allocation it also establishes the concept of functions - a function in Compiler sense is a unit in which virtual registers are allocated into physical registers by the register allocator. In addition, it enables to use such virtual registers in function invocations.
BaseCompiler automatically handles function calling conventions. It's still architecture dependent, but makes the code generation much easies. Functions are essential; the first-step to generate some code is to define a signature of the function to be generated (before generating the function body itself). Function arguments and return value(s) are handled by assigning virtual registers to them. Similarly, function calls are handled the same way.
BaseCompiler adds some nodes that are required for function generation and invocation:
Users of AsmJit have done mistakes in the past, this section should provide some useful tips for beginners: