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