[LLVMdev] C Compiler written in OCaml, Pointers Wanted

Jon Harrop jon at ffconsultancy.com
Sun Feb 28 14:43:40 PST 2010

On Wednesday 24 February 2010 13:26:33 Jianzhou Zhao wrote:
> On Wed, Feb 24, 2010 at 7:10 AM, Jon Harrop <jon at ffconsultancy.com> wrote:
> > On Wednesday 24 February 2010 03:58:03 Jianzhou Zhao wrote:
> >> I think LLVM OCaml bindings do not support JIT too much.
> >
> > Can you elaborate on this?
> I meant the OCaml bindings let OCaml call existing C++ LLVM routines,
> such as creating an execution engine, JIT-ing a function with existing JIT
> or interpret or, and evaluating a function,
>   as what http://llvm.org/docs/tutorial/OCamlLangImpl4.html shows.
> But LLVM has not exposed the LLVM interfaces to design a new JIT
>   like http://llvm.org/docs/WritingAnLLVMBackend.html#jitSupport.
> I did not find such bindings from
> bindings/ocaml/executionengine/llvm_executionengine.ml.
> Please fix me if I am wrong.

Your statements are correct but, given that you can write a complete compiler 
in OCaml using LLVM's JIT compilation, I think it is OTT to say that 
the "OCaml bindings do not support JIT too much".

> > Several major projects are using OCaml's LLVM bindings to execute
> > non-trivial code via JIT.
> Could you please point out what these projects are?

You'll have to ask Erick Tryzelaar, James Woodyatt and Nyx what they're up 
to. :-)

> I am very interested in looking into these projects to see if they exposed
> any more LLVM interfaces, and how they did this. 

I doubt they exposed any more of LLVM's internals.

> OCaml bindings for optimizations have not exposed the LLVM interfaces to
> let OCaml define a new optimization pass yet. I was planning to design
> an OCaml LLVM pass, so it would help a lot to look at how JIT bindings are
> used.

I would strongly advise against that. The impedance mismatch between OCaml and 
C++ is so large that you will spend virtually all of your time addressing the 
incidental complexity of writing and maintaining low-level bindings instead 
of solving real problems. Moreover, the bindings will be so slow (due to 
copying) and error-prone that you will have lost the core benefits of using 
OCaml in the first place.

If you do decide to go this route you might consider writing very loose and 
more language agnostic bindings, e.g. via XML-RPC rather than the ABIs.

Dr Jon Harrop, Flying Frog Consultancy Ltd.

More information about the llvm-dev mailing list