#jit #solely #help #phase #hopefully #macro-rules #link

nightly lejit

A JIT library written solely in Rust

1 unstable release

Uses old Rust 2015

0.0.1 Dec 8, 2014

#4 in #solely

MPL-2.0 license

19KB
526 lines

LeJIT Build Status

A simple JIT library written in Rust. Any help is much appreciated.

Dependencies

  • Rust (from Git)

Build Instructions

make

License

Copyright (C) 2014 by Arcterus. All rights reserved.
Licensed under the MPL v2.0. See LICENSE.txt for more information.


lib.rs:

A (hopefully) simple JIT library.

Example

#![feature(macro_rules, globs, phase)]

#[phase(plugin, link)]
extern crate lejit;
extern crate libc;

use lejit::*;
use lejit::JitOp::*;
use lejit::JitReg::*;

fn main() {
   let mut jit = Jit::new();

   jit.build_function("add_four".to_string(), |func| {
       func.op(Movrr(R1, R2))
           .op(Addri(R1, 4))
           .op(Call("sub_four"))
           .end();
   });

   jit.build_function("sub_four".to_string(), |func| {
      func.op(Movrr(R1, R2))
          .op(Subri(R1, 4))
          .op(Call("random_stuff"))
          .end();
   });

   jit.build_function("random_stuff".to_string(), |func| {
      let op = func.op(Subri(R1, 7))
                   .op(Addri(R1, 1000000000));
      let op2 = op.op(Subri(R1, 500000000))
                  .op(Movri(R1, 1))
                  .op(Movri(R1, 10000));
      op2.op(Movri(R1, 1000000000000))
         .end();
   });

   let add = jit_compilefn!(jit, (int) -> int);
   println!("add(4): {}", add(4));
}

No runtime deps