pub enum Op {
Const {
dst: Reg,
value: Const,
},
Bin {
op: BinOp,
dst: Reg,
lhs: Reg,
rhs: Reg,
},
Un {
op: UnOp,
dst: Reg,
src: Reg,
},
Move {
dst: Reg,
src: Reg,
},
Jump {
target: Label,
},
JumpUnless {
cond: Reg,
target: Label,
},
Return {
value: Option<Reg>,
},
}Expand description
One bytecode instruction.
An op is the unit a Program is a sequence of. The arithmetic ops
(Const, Bin, Un) write their result to a
destination Reg and read their operands from registers; Move copies
one register to another; and the control-flow ops (Jump,
JumpUnless, Return) carry a Label or a result
register. The set is closed and every variant is Copy, so an op stream is a flat
&[Op] an interpreter or a further pass can walk with no indirection.
§Examples
use codegen_lang::{Const, Op, Reg};
let load = Op::Const { dst: Reg(0), value: Const::Int(1) };
assert_eq!(load.to_string(), "r0 = const 1");
let ret = Op::Return { value: Some(Reg(0)) };
assert_eq!(ret.to_string(), "ret r0");Variants§
Const
Load a constant into dst.
Bin
Apply a binary operation: dst = lhs <op> rhs.
Fields
Un
Apply a unary operation: dst = <op> src.
Fields
Move
Copy a register: dst = src. Emitted on a control-flow edge to move a block
argument into the parameter register of the block being entered — the bytecode’s
stand-in for an SSA phi.
Jump
Jump unconditionally to target.
JumpUnless
Jump to target when cond holds false; otherwise fall through to the next op.
Fields
Return
Return from the function, optionally yielding the value in a register.