Instruction

Enum Instruction 

Source
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

Source

pub fn new(value: u32) -> Self

Create a new 32-bit instruction

Source

pub fn new_compressed(value: u16) -> Self

Create a new 16-bit compressed instruction

Source

pub fn value(self) -> u32

Get the instruction value as u64 (for compatibility)

Source

pub fn bytes(self) -> Vec<u8>

Get the instruction as bytes with proper length

Source

pub fn size(&self) -> usize

Get the size of this instruction in bytes

Source

pub fn is_compressed(&self) -> bool

Check if this is a compressed instruction

Trait Implementations§

Source§

impl Clone for Instruction

Source§

fn clone(&self) -> Instruction

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Instruction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Instruction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Instruction for Instruction

Source§

fn value(&self) -> u64

Get the instruction as a 32-bit or 64-bit value
Source§

fn bytes(&self) -> Vec<u8>

Get the instruction as bytes (little-endian)
Source§

fn size(&self) -> usize

Get the size of this instruction in bytes
Source§

impl InstructionBuilder<Instruction> for Riscv64InstructionBuilder

Source§

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§

type Register = Register

The register type used by this architecture
Source§

fn new() -> Self

Create a new instruction builder
Source§

fn instructions(&self) -> InstructionCollection<Instruction>

Get the generated instructions
Source§

fn push(&mut self, instr: Instruction)

Add an instruction to the builder
Source§

fn clear(&mut self)

Clear all instructions
Source§

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

Source§

fn eq(&self, other: &Instruction) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Instruction

Source§

impl Eq for Instruction

Source§

impl StructuralPartialEq for Instruction

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.