Instr

Enum Instr 

Source
pub enum Instr<'a> {
Show 47 variants Add(Value, Value), Sub(Value, Value), Mul(Value, Value), Div(Value, Value), Rem(Value, Value), Cmp(Type<'a>, Cmp, Value, Value), And(Value, Value), Or(Value, Value), Copy(Value), Ret(Option<Value>), Jnz(Value, String, String), Jmp(String), Call(String, Vec<(Type<'a>, Value)>, Option<u64>), Alloc4(u32), Alloc8(u64), Alloc16(u128), Store(Type<'a>, Value, Value), Load(Type<'a>, Value), Blit(Value, Value, u64), DbgFile(String), DbgLoc(u64, Option<u64>), Udiv(Value, Value), Urem(Value, Value), Sar(Value, Value), Shr(Value, Value), Shl(Value, Value), Cast(Value), Extsw(Value), Extuw(Value), Extsh(Value), Extuh(Value), Extsb(Value), Extub(Value), Exts(Value), Truncd(Value), Stosi(Value), Stoui(Value), Dtosi(Value), Dtoui(Value), Swtof(Value), Uwtof(Value), Sltof(Value), Ultof(Value), Vastart(Value), Vaarg(Type<'a>, Value), Phi(String, Value, String, Value), Hlt,
}
Expand description

QBE instructions representing operations in the intermediate language.

§Examples

§Arithmetic Operations

use qbe::{Instr, Value};

// Addition: %result = %a + %b
let add = Instr::Add(
    Value::Temporary("a".to_string()),
    Value::Temporary("b".to_string()),
);

// Multiplication: %result = %x * 5
let mul = Instr::Mul(
    Value::Temporary("x".to_string()),
    Value::Const(5),
);

§Memory Operations

use qbe::{Instr, Type, Value};

// Allocate 8 bytes on the stack with 8-byte alignment
let alloc = Instr::Alloc8(8);

// Store a word to memory: store %value, %ptr
let store = Instr::Store(
    Type::Word,
    Value::Temporary("ptr".to_string()),
    Value::Temporary("value".to_string()),
);

// Load a word from memory: %result = load %ptr
let load = Instr::Load(
    Type::Word,
    Value::Temporary("ptr".to_string()),
);

§Control Flow

use qbe::{Instr, Value};

// Conditional jump based on %condition
let branch = Instr::Jnz(
    Value::Temporary("condition".to_string()),
    "true_branch".to_string(),
    "false_branch".to_string(),
);

// Return a value from a function
let ret = Instr::Ret(Some(Value::Temporary("result".to_string())));

Variants§

§

Add(Value, Value)

Adds values of two temporaries together

§

Sub(Value, Value)

Subtracts the second value from the first one

§

Mul(Value, Value)

Multiplies values of two temporaries

§

Div(Value, Value)

Divides the first value by the second one

§

Rem(Value, Value)

Returns a remainder from division

§

Cmp(Type<'a>, Cmp, Value, Value)

Performs a comparion between values

§

And(Value, Value)

Performs a bitwise AND on values

§

Or(Value, Value)

Performs a bitwise OR on values

§

Copy(Value)

Copies either a temporary or a literal value

§

Ret(Option<Value>)

Return from a function, optionally with a value

§

Jnz(Value, String, String)

Jumps to first label if a value is nonzero or to the second one otherwise

§

Jmp(String)

Unconditionally jumps to a label

§

Call(String, Vec<(Type<'a>, Value)>, Option<u64>)

Calls a function

§

Alloc4(u32)

Allocates a 4-byte aligned area on the stack

§

Alloc8(u64)

Allocates a 8-byte aligned area on the stack

§

Alloc16(u128)

Allocates a 16-byte aligned area on the stack

§

Store(Type<'a>, Value, Value)

Stores a value into memory pointed to by destination. (type, destination, value)

§

Load(Type<'a>, Value)

Loads a value from memory pointed to by source (type, source)

§

Blit(Value, Value, u64)

(source, destination, n)

Copy n bytes from the source address to the destination address.

n must be a constant value.

§Minimum supported QBE version

1.1

§

DbgFile(String)

Debug file.

§

DbgLoc(u64, Option<u64>)

Debug line.

Takes line number and an optional column.

§

Udiv(Value, Value)

Performs unsigned division of the first value by the second one

§

Urem(Value, Value)

Returns the remainder from unsigned division

§

Sar(Value, Value)

Shift arithmetic right (preserves sign)

§

Shr(Value, Value)

Shift logical right (fills with zeros)

§

Shl(Value, Value)

Shift left (fills with zeros)

§

Cast(Value)

Cast between integer and floating point of the same width

§

Extsw(Value)

Sign-extends a word to a long

§

Extuw(Value)

Zero-extends a word to a long

§

Extsh(Value)

Sign-extends a halfword to a word or long

§

Extuh(Value)

Zero-extends a halfword to a word or long

§

Extsb(Value)

Sign-extends a byte to a word or long

§

Extub(Value)

Zero-extends a byte to a word or long

§

Exts(Value)

Extends a single-precision float to double-precision

§

Truncd(Value)

Truncates a double-precision float to single-precision

§

Stosi(Value)

Converts a single-precision float to a signed integer

§

Stoui(Value)

Converts a single-precision float to an unsigned integer

§

Dtosi(Value)

Converts a double-precision float to a signed integer

§

Dtoui(Value)

Converts a double-precision float to an unsigned integer

§

Swtof(Value)

Converts a signed word to a float

§

Uwtof(Value)

Converts an unsigned word to a float

§

Sltof(Value)

Converts a signed long to a float

§

Ultof(Value)

Converts an unsigned long to a float

§

Vastart(Value)

Initializes a variable argument list

§

Vaarg(Type<'a>, Value)

Fetches the next argument from a variable argument list

§

Phi(String, Value, String, Value)

Selects value based on the control flow path into a block.

§

Hlt

Terminates the program with an error

Trait Implementations§

Source§

impl<'a> Clone for Instr<'a>

Source§

fn clone(&self) -> Instr<'a>

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<'a> Debug for Instr<'a>

Source§

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

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

impl Display for Instr<'_>

Source§

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

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

impl<'a> Hash for Instr<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> Ord for Instr<'a>

Source§

fn cmp(&self, other: &Instr<'a>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'a> PartialEq for Instr<'a>

Source§

fn eq(&self, other: &Instr<'a>) -> 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<'a> PartialOrd for Instr<'a>

Source§

fn partial_cmp(&self, other: &Instr<'a>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a> Eq for Instr<'a>

Source§

impl<'a> StructuralPartialEq for Instr<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Instr<'a>

§

impl<'a> RefUnwindSafe for Instr<'a>

§

impl<'a> Send for Instr<'a>

§

impl<'a> Sync for Instr<'a>

§

impl<'a> Unpin for Instr<'a>

§

impl<'a> UnwindSafe for Instr<'a>

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.