Skip to main content

compile

Function compile 

Source
pub fn compile(func: &Function) -> Result<Program, CodegenError>
Expand description

Lowers a function to bytecode with the default Bytecode backend.

A shortcut for Bytecode.compile(func) for the common case where the bytecode target is the one you want. Use Bytecode through the Backend trait when a generic over backends is what you need.

§Errors

Returns CodegenError::InvalidIr if func is not well-formed SSA.

§Examples

use codegen_lang::compile;
use ir_lang::{Builder, Type, UnOp};

// fn negate(x: int) -> int { -x }
let mut b = Builder::new("negate", &[Type::Int], Type::Int);
let x = b.block_params(b.entry())[0];
let neg = b.un(UnOp::Neg, x);
b.ret(Some(neg));

let program = compile(&b.finish()).expect("negate is well-formed");
assert_eq!(program.name(), "negate");