Skip to main content

NativeInst

Enum NativeInst 

Source
pub enum NativeInst {
Show 28 variants LoadImm { dst: Register, ty: NativeType, value: i64, }, Add { dst: Register, ty: NativeType, lhs: NativeValue, rhs: NativeValue, }, Sub { dst: Register, ty: NativeType, lhs: NativeValue, rhs: NativeValue, }, Mul { dst: Register, ty: NativeType, lhs: NativeValue, rhs: NativeValue, }, Div { dst: Register, ty: NativeType, lhs: NativeValue, rhs: NativeValue, }, And { dst: Register, ty: NativeType, lhs: NativeValue, rhs: NativeValue, }, Or { dst: Register, ty: NativeType, lhs: NativeValue, rhs: NativeValue, }, Xor { dst: Register, ty: NativeType, lhs: NativeValue, rhs: NativeValue, }, Shl { dst: Register, ty: NativeType, lhs: NativeValue, rhs: NativeValue, }, Shr { dst: Register, ty: NativeType, lhs: NativeValue, rhs: NativeValue, }, Cmp { dst: Register, cc: CondCode, ty: NativeType, lhs: NativeValue, rhs: NativeValue, }, Br { target: BlockId, }, CondBr { cond: NativeValue, then_target: BlockId, else_target: BlockId, }, Call { dst: Option<Register>, func: NativeValue, args: Vec<NativeValue>, ret_type: NativeType, }, Ret { value: Option<NativeValue>, }, Load { dst: Register, ty: NativeType, addr: NativeValue, }, Store { ty: NativeType, addr: NativeValue, value: NativeValue, }, Alloc { dst: Register, size: usize, align: usize, }, Free { ptr: NativeValue, }, Phi { dst: Register, ty: NativeType, incoming: Vec<(NativeValue, BlockId)>, }, Select { dst: Register, ty: NativeType, cond: NativeValue, true_val: NativeValue, false_val: NativeValue, }, Copy { dst: Register, src: NativeValue, }, Nop, Comment(String), IntToPtr { dst: Register, src: NativeValue, }, PtrToInt { dst: Register, src: NativeValue, }, GetElementPtr { dst: Register, base: NativeValue, offset: NativeValue, elem_size: usize, }, Switch { value: NativeValue, default: BlockId, targets: Vec<(u64, BlockId)>, },
}
Expand description

A single instruction in the native IR.

Variants§

§

LoadImm

Load immediate: dst = imm.

Fields

§value: i64
§

Add

Add: dst = lhs + rhs.

§

Sub

Subtract: dst = lhs - rhs.

§

Mul

Multiply: dst = lhs * rhs.

§

Div

Divide: dst = lhs / rhs.

§

And

Bitwise AND: dst = lhs & rhs.

§

Or

Bitwise OR: dst = lhs | rhs.

§

Xor

Bitwise XOR: dst = lhs ^ rhs.

§

Shl

Shift left: dst = lhs << rhs.

§

Shr

Shift right (arithmetic): dst = lhs >> rhs.

§

Cmp

Compare: dst = cmp(cc, lhs, rhs).

§

Br

Unconditional branch to a block.

Fields

§target: BlockId
§

CondBr

Conditional branch: if cond != 0, goto then_target, else goto else_target.

Fields

§then_target: BlockId
§else_target: BlockId
§

Call

Function call: dst = func(args...).

§

Ret

Return from function.

Fields

§

Load

Load from memory: dst = *addr.

§

Store

Store to memory: *addr = value.

§

Alloc

Allocate stack space: dst = alloca(size, align).

Fields

§size: usize
§align: usize
§

Free

Free heap memory.

Fields

§

Phi

Phi node (SSA): dst = phi([(val, block), ...]).

Fields

§incoming: Vec<(NativeValue, BlockId)>
§

Select

Select: dst = cond ? true_val : false_val.

Fields

§true_val: NativeValue
§false_val: NativeValue
§

Copy

Copy: dst = src.

Fields

§

Nop

No-operation (placeholder).

§

Comment(String)

Comment (for debugging).

§

IntToPtr

Integer to pointer cast.

Fields

§

PtrToInt

Pointer to integer cast.

Fields

§

GetElementPtr

Get element pointer (pointer arithmetic).

Fields

§elem_size: usize
§

Switch

Switch/table branch.

Fields

§default: BlockId
§targets: Vec<(u64, BlockId)>

Implementations§

Source§

impl NativeInst

Source

pub fn dst_reg(&self) -> Option<Register>

Get the destination register of this instruction, if any.

Source

pub fn src_regs(&self) -> Vec<Register>

Get all source registers read by this instruction.

Source

pub fn is_terminator(&self) -> bool

Whether this instruction is a terminator (ends a basic block).

Trait Implementations§

Source§

impl Clone for NativeInst

Source§

fn clone(&self) -> NativeInst

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 NativeInst

Source§

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

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

impl PartialEq for NativeInst

Source§

fn eq(&self, other: &NativeInst) -> 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 StructuralPartialEq for NativeInst

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