Skip to main content

define_function

Function define_function 

Source
pub fn define_function<M, F, R>(
    module: &mut M,
    name: &str,
    linkage: Linkage,
    signature: Signature,
    body: F,
) -> ModuleResult<FuncId>
where M: Module, F: FnOnce(&mut FunctionBuilder<'_>, &mut M, &[Value]) -> R, R: IntoReturns,
Expand description

Declare and define a Cranelift function in one call.

body is invoked with the live FunctionBuilder, the module (re-borrowed so the body can declare imports / call other JITed functions), and the entry block’s parameters. Whatever it returns is wrapped via IntoReturns and emitted as the function’s return_ instruction.

§Example

let id = define_function(
    &mut module,
    "wrap",
    Linkage::Export,
    jit_signature!(&module; fn(i64) -> i64),
    |bcx, module, params| {
        double_i64_jit::call(bcx, module, ext_id, params[0])
    },
)?;