lower-ir-utils
Helpers for bridging Rust types to Cranelift JIT
signatures and call sites. The crate trims the boilerplate of declaring
external functions, building Signatures, and lowering arguments, while still
giving you direct access to the underlying FunctionBuilder and Module.
What it provides
JitParam— type-level: how a Rust type expands into CraneliftAbiParams (e.g.&strbecomes(ptr, len)).JitArg— value-level: how a Rust value lowers into one or morecranelift_codegen::ir::Values. Implemented for already-loweredValues, integer/float constants, raw pointers, and&'static str/&'static [T].jit_signature!(&module; fn(T1, T2) -> R)— build aSignaturefrom Rust types.jit_call!(&mut bcx, ptr_ty, callee; arg1, arg2, ...)— emit acallinstruction, lowering each argument throughJitArg.define_function(...)/define_jit_fn!(...)— declare + define a function in one shot. Your closure receives theFunctionBuilder, theModule, and the entry-block params; whatever it returns is funneled throughIntoReturnsand emitted asreturn_.#[jit_export](proc-macro) — annotate a Rust function so it can be called from JITed IR. Generates a sibling<fn>_jitmodule withregister,signature,declare, andcallhelpers, and auto-injectsextern "C"if no ABI is specified.
Example
use ;
use ;
use ;
See tests/jit_integration.rs and tests/define_function.rs for end-to-end
examples covering multi-value returns, &str arguments, and slice arguments.
Layout
src/abi.rs—JitParam/JitArgtraits and impls.src/builder.rs—define_function+IntoReturns.src/macros.rs—jit_signature!,jit_call!,define_jit_fn!.macros/— proc-macro crate exporting#[jit_export].tests/— integration tests (jit_integration,define_function,abi_unit,jit_export) plus anexternal_consumerworkspace.
Building
cargo build
cargo test
Targets Cranelift 0.131. Tested on x86_64 Linux (System V ABI). The &str /
&[T] impls assume the platform passes fat pointers as separate (ptr, len)
args; on platforms where that doesn't hold, prefer flat scalar params.
License
MIT — see LICENSE.