pub enum Instruction {
Standard(u32),
Compressed(u16),
}
Expand description
RISC-V instruction representation (supports both 32-bit and 16-bit compressed instructions)
Variants§
Standard(u32)
32-bit standard instruction
Compressed(u16)
16-bit compressed instruction (C extension)
Implementations§
Source§impl Instruction
impl Instruction
Sourcepub fn new_compressed(value: u16) -> Self
pub fn new_compressed(value: u16) -> Self
Create a new 16-bit compressed instruction
Sourcepub fn is_compressed(&self) -> bool
pub fn is_compressed(&self) -> bool
Check if this is a compressed instruction
Trait Implementations§
Source§impl Clone for Instruction
impl Clone for Instruction
Source§fn clone(&self) -> Instruction
fn clone(&self) -> Instruction
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for Instruction
impl Debug for Instruction
Source§impl Display for Instruction
impl Display for Instruction
Source§impl Instruction for Instruction
impl Instruction for Instruction
Source§impl InstructionBuilder<Instruction> for Riscv64InstructionBuilder
impl InstructionBuilder<Instruction> for Riscv64InstructionBuilder
Source§unsafe 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.
§Safety
This function is unsafe because:
- It allocates executable memory
- It assumes the assembled code follows the correct ABI
- The caller must ensure the function signature matches the actual code
§Examples
use jit_assembler::riscv64::{reg, Riscv64InstructionBuilder};
use jit_assembler::common::InstructionBuilder;
let add_func = unsafe {
Riscv64InstructionBuilder::new()
.add(reg::A0, reg::A0, reg::A1) // Add first two arguments
.ret()
.function::<fn(u64, u64) -> u64>()
}.expect("Failed to create JIT function");
// Call the JIT function directly (only works on RISC-V hosts)
let result = add_func.call(10, 20); // Should return 30
Source§fn instructions(&self) -> InstructionCollection<Instruction>
fn instructions(&self) -> InstructionCollection<Instruction>
Get the generated instructions
Source§fn push(&mut self, instr: Instruction)
fn push(&mut self, instr: Instruction)
Add an instruction to the builder
Source§unsafe 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) Read more
Source§impl PartialEq for Instruction
impl PartialEq for Instruction
impl Copy for Instruction
impl Eq for Instruction
impl StructuralPartialEq for Instruction
Auto Trait Implementations§
impl Freeze for Instruction
impl RefUnwindSafe for Instruction
impl Send for Instruction
impl Sync for Instruction
impl Unpin for Instruction
impl UnwindSafe for Instruction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more