pub fn define_function<M, F, R>(
module: &mut M,
name: &str,
linkage: Linkage,
signature: Signature,
body: F,
) -> ModuleResult<FuncId>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])
},
)?;