Skip to content

Latest commit

 

History

History
65 lines (47 loc) · 1.66 KB

Readme.md

File metadata and controls

65 lines (47 loc) · 1.66 KB

RLLVM

Languages GitHub Repo stars GitHub License Dynamic TOML Badge

LLVM alternativ

Example

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(())
}

ToDo

Here is a bit of ToDo for my libary:

v0.1.2

  • 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

v0.1.3

  • Implement args to the high level ir
  • Add option (in context) to compile to object file
  • Naming convention
    • generate
    • parse