9 releases

Uses old Rust 2015

0.0.9 May 16, 2015
0.0.8 Feb 16, 2015
0.0.4 Jan 25, 2015
0.0.2 Dec 22, 2014

#1099 in Programming languages


Used in jit

MIT license

21KB
462 lines

JIT.rs

Build Status Latest Version

NOTE

Because LibJIT has been inactive for a year, it seems there won't be any more updates. On the other hand, LLVM is still very active, so I have been working on bindings for a couple of days now. There will be news soon about a replacement.

What is LibJIT?

LibJIT is a portable, lightweight JIT library developed by GNU in C. It aims to have an IR which is compatible with any language or runtime you throw at it, without forcing the programmer to use a specific one.

What's jit.rs?

jit.rs is a Rust library that wraps LibJIT in an idiomatic Rust way, which includes a macro for easy compilation of abritary types into JIT types. It also uses the Rust memory model to save some otherwide pointless operations that would me used if it were implemented in a GC language

Why are there so many packages?

  • libjit-sys - this contains the bindings to JIT functions, constants etc. If you want to stick to the original API, you should use this.
  • jit - this contains the Rust-style wrappers of the JIT functions and structures.
  • jit_macros - this contains the macro definitions that help to streamline code interacting with JIT.

How do I build this?

If you want to build this, you'll need to install these packages for Ubuntu or Debian:

sudo apt install autoconf automake texinfo libtool bison flex g++

Then, you can just use cargo to build it

cargo build

How do I use the macro?

Just annotate your types you want to pass into LibJIT like this

#[derive(Compile)]
struct Position {
  x: f64,
  y: f64
}

fn main() {
  ...
  let pos = Position {
    x: 5.0,
    y: -32.2
  };
  func.insn_return(func.insn_of(pos))
  ...
}

Are there any examples?

There's a Brainfuck virtual machine example with an nice command-line interface and everything. You can run it with this command from the project root:

cargo run --example brainfuck

You should then enter in the brainfuck code followed by a newline to run it.

> ++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
Hello, world!
>

You can also view its source code here.

Dependencies

~6KB