pub enum Inst {
Iconst(i64),
Fconst(f64),
Bconst(bool),
Bin(BinOp, Value, Value),
Un(UnOp, Value),
}Expand description
A value-producing instruction.
Every variant defines exactly one Value, whose type is recorded by the
Function and can be read with
Function::value_type. Instructions reference
their operands by Value handle, never by nesting a sub-expression, so the IR
stays flat and walkable in program order. The terminator that ends a block is a
separate type, Terminator.
You do not build an Inst directly; the Builder emits one
per call and hands back the value it defines. This type is what you read back
when inspecting a function, for example with
Function::inst.
§Examples
use ir_lang::{Builder, BinOp, Inst};
let mut b = Builder::new("k", &[], ir_lang::Type::Int);
let one = b.iconst(1);
let sum = b.bin(BinOp::Add, one, one);
b.ret(Some(sum));
let func = b.finish();
// The instruction that defined `sum` is the add.
assert!(matches!(func.inst(sum), Some(Inst::Bin(BinOp::Add, _, _))));
// A block parameter is not produced by an instruction.
assert!(func.inst(one).is_some());Variants§
Iconst(i64)
An integer constant. Result type is Int.
Fconst(f64)
A floating-point constant. Result type is Float.
Bconst(bool)
A boolean constant. Result type is Bool.
Bin(BinOp, Value, Value)
A binary operation over two values. Result type follows the operation.
Un(UnOp, Value)
A unary operation over one value. Result type follows the operation.