LLVM alternativ
use std::error::Error;
use rllvm::prelude::*;
fn main() -> Result<(), Box<dyn Error>>{
let mut contxt = Context::new( Triple::host() )?;
let func = contxt.add_function("add", vec![Type::u32, Type::u32], Type::u32);
let asm = func.asm_func()?;
let x = asm.arg(0).unwrap();
let y = asm.arg(1).unwrap();
func.ir.push( Return::new(*(x + y) ) );
unsafe {
let mut func: JitFunction<unsafe extern "C" fn(u32, u32) -> u32> = contxt.get_jit_function("add")?;
let out = func.call(5, 5);
println!("main() -> {}", out);
}
Ok(())
}
Here is a bit of ToDo for my libary:
- Starting high level ir struct
- Use traits
impl Compiler for Ir::Add<Var, Int>
so i can overload the enum variants - Make it compilable
- Implement
mov
,add
,sub
,mul
,div
|ints
,floats
- mov
- add
- sub
- mul
- div
- ints
- floats
- Starting high level ir builder
- via traits
- Use traits
- Implement
args
to the high level ir - Add option (in
context
) to compile to object file - Naming convention
- generate
- parse