pub struct Bytecode;Expand description
The reference backend: lowers a function to a flat, register-based Program.
Bytecode is the concrete target shipped with the crate and the one
compile uses. It validates the function, then lowers each block in order to a
linear op stream — small enough to read, serialize, and execute, which makes it the
natural target for testing a front-end’s output before a native backend exists.
It is a zero-sized type with no configuration; construct it directly or with
Default.
§Examples
use codegen_lang::{Backend, Bytecode};
use ir_lang::{Builder, BinOp, Type};
// fn inc(x: int) -> int { x + 1 }
let mut b = Builder::new("inc", &[Type::Int], Type::Int);
let x = b.block_params(b.entry())[0];
let one = b.iconst(1);
let sum = b.bin(BinOp::Add, x, one);
b.ret(Some(sum));
let program = Bytecode.compile(&b.finish()).expect("inc is well-formed");
assert_eq!(program.register_count(), 3); // x, the constant, the sumTrait Implementations§
impl Copy for Bytecode
impl Eq for Bytecode
impl StructuralPartialEq for Bytecode
Auto Trait Implementations§
impl Freeze for Bytecode
impl RefUnwindSafe for Bytecode
impl Send for Bytecode
impl Sync for Bytecode
impl Unpin for Bytecode
impl UnsafeUnpin for Bytecode
impl UnwindSafe for Bytecode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more