Compile Toy language to LLVM IR, then JIT the LLVM IR

Hello All,

I am creating a toy language, for my personal use and to help me learn rust.

Right now I am creating the interpreter. I have read some articles on the optimizations that interpreters carry out.

One thing that really interested me, is the ability to JIT.

I am looking for a way to compile rust code to LLVM IR, within my rust interpreter.

Then proceed to invoke that LLVM IR code and run it, again within my Rust Interpreter.

I have seen that this is possible with C++. What I am mainly looking for is a safe way to use LLVM within Rust.

If anyone has any suggestions, it will be much appreciated.

Thank you :slight_smile:

You might want to have a look at Cretonne. It is written entirely in Rust and is designed for this sort of use-case. It's still a work in progress, but, my understanding (I've only recently become aware of it myself) is that it is coming along rather nicely. see https://github.com/Cretonne/cretonne.

EDIT: Also, although not directly relevant, the following discussions on Reddit and this discourse here regarding LLVM/RLLVM and Cretonne may help to inform some background:

Alright, thank you very much will have a look at it.

check

https://github.com/hobinjk/rusty-kaleidoscope
https://github.com/jauhien/iron-kaleidoscope

which is based on LLVM Tutorial: Table of Contents — LLVM 16.0.0git documentation

1 Like

While Cretonne is cool, we don't have any tutorials yet, or documentation about what to do, what works, and what doesn't, yet. I can answer questions though :-).

1 Like

Thank you all for the suggestions :slight_smile:

iron-kaleidoscope looks really good!