Skip to content

Toni-Graphics/rllvm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published

Languages