3 ms·
I'm the author of this project. I think of this project as a technology demo. I wanted to how difficult it would be to write a minimalist compiler with LLVM --
by jasonjackson 15y ago
I'm the author of this project. I think of this project as a technology demo. I wanted to how difficult it would be to write a minimalist compiler with LLVM -- it was pretty quick & easy.
This is a great educational project as the code is short and to the point.
For my parsing code: https://github.com/jasonjckn/llvm-clojure-bindings/blob/master/src/parser.clj https://github.com/jasonjckn/llvm-clojure-bindings/blob/mast...
I'm using a combinator parser library. This code both parses and builds the AST in one pass.
The AST unsurprisingly looks like LISP code, here's an example AST https://github.com/jasonjckn/llvm-clojure-bindings/blob/master/src/example_ast.clj https://github.com/jasonjckn/llvm-clojure-bindings/blob/mast...
After that, all that's left is calling LLVM C API through JNA: https://github.com/jasonjckn/llvm-clojure-bindings/blob/master/src/ast.clj https://github.com/jasonjckn/llvm-clojure-bindings/blob/mast...
One advantage of using LLVM is you can leverage the C Standard Library from your code. In the example program, I forward declare 'cos' and 'printf', and LLVM takes care of linking the functions.
LLVM also supports JIT compilation, so you could do some really cool stuff.
Stay tuned for the next compiler I'm working on which will compile the majority of Java 2.0 to x86.