pub trait InstructionBuilder<I: Instruction> {
type Register: Register;
// Required methods
fn new() -> Self;
fn instructions(&self) -> InstructionCollection<I>;
fn push(&mut self, instr: I);
fn clear(&mut self);
unsafe fn function<F>(&self) -> Result<CallableJitFunction<F>, JitError>;
unsafe fn raw_function(&self) -> Result<RawCallableJitFunction, JitError>;
}
Expand description
An instruction builder for a specific architecture
Required Associated Types§
Required Methods§
Sourcefn instructions(&self) -> InstructionCollection<I>
fn instructions(&self) -> InstructionCollection<I>
Get the generated instructions
Sourceunsafe fn function<F>(&self) -> Result<CallableJitFunction<F>, JitError>
unsafe fn function<F>(&self) -> Result<CallableJitFunction<F>, JitError>
Create a JIT-compiled function from the assembled instructions (std-only)
This method converts the assembled instructions into executable machine code
that can be called directly as a function. The generic type parameter F
specifies the function signature.
§ABI Compatibility
While you specify a Rust function type like fn() -> u64
, the actual JIT
code uses C ABI internally for stability across Rust versions. This conversion
is handled transparently by the call()
methods.
§Limitations
Currently supports function signatures with up to 7 arguments. For functions with more arguments or complex calling conventions, use manual function pointer conversion.
§Safety
This function is unsafe because:
- It allocates executable memory
- It assumes the assembled code follows the correct C ABI
- The caller must ensure the function signature matches the actual code
- The assembled code must be valid for the target architecture
Sourceunsafe fn raw_function(&self) -> Result<RawCallableJitFunction, JitError>
unsafe fn raw_function(&self) -> Result<RawCallableJitFunction, JitError>
Create a raw JIT-compiled function for manual type conversion (std-only)
This method is similar to function()
but returns a type-erased function
that allows manual conversion to any function signature. Use this for
function signatures with more than 7 arguments or custom calling conventions.
§Safety
This function is unsafe because:
- It allocates executable memory
- The caller must manually ensure type safety when calling
as_fn()
- The assembled code must be valid for the target architecture
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.