Crates.io | gnu-libjit |
lib.rs | gnu-libjit |
version | 0.9.0 |
source | src |
created_at | 2022-06-15 03:56:59.76077 |
updated_at | 2022-08-21 03:42:08.288254 |
description | A safe rust wrapper around the libjit just in time compiler |
homepage | https://github.com/n8ta/gnu-libjit |
repository | https://github.com/n8ta/gnu-libjit |
max_upload_size | |
id | 606241 |
size | 65,744 |
Warning: This wrapper contains only exactly the functionality from libjit I needed for my own project. You may find it to be missing a piece of functionality. It shouldn't be too hard to add it yourself (:
This crate is a safe and performant wrapper around gnu-libjit. A just in time compiler with its own IR, optimization passes, and easy interoperability.
It's possible to jit a small program and execute it in < 5 ms compared to ~ 80 ms with llvm. I highly recmomend the inkwell library as a safe, feature rich, and well documented llvm rust wrapper. Do note that you are unlikely to execute a JIT'ed program in single digit ms with any llvm wrapper but you do get much more powerful optimizations, and far more safety and stability than with this library.
use gnu_libjit::{Abi, Context};
fn main() {
let mut context = Context::new();
context.build_start();
let int_type = Context::int_type();
let params = vec![int_type, int_type, int_type];
let mut func = context.function(Abi::Cdecl, int_type, params).unwrap();
let x = func.arg(0).unwrap();
let y = func.arg(1).unwrap();
let z = func.arg(2).unwrap();
let temp1 = func.insn_mult(&x, &y);
let temp2 = func.insn_add(&temp1, &z);
func.insn_return(temp2);
func.compile();
context.build_end();
let result: extern "C" fn(i32,i32,i32) -> i32 = func.to_closure();
println!("3*5+2 = {}", result(3,5,2))
}
See ./examples
and ./src/test.rs
for more. There are no docs. Functions are named almost exactly as in the libjit library. You can use its docs here.
f32
, f64
, i64
, i32
, i8
, u8
*mut c_void
if
if_not
branching plus the eq
operator to call them withSee LICENSE