Version française
Home     About     Download     Resources     Contact us    
Browse thread
Run-time FFI generation using LLVM
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jon Harrop <jon@f...>
Subject: Run-time FFI generation using LLVM

The latest OCaml Journal article describes how LLVM can be used to generate 
FFI code at run-time, allowing OCaml programs to dynamically load C libraries 
and call their functions without having to write any C stubs or statically 
link any custom libraries.

This technique has the obvious advantage that its potential for reuse is much 
better because the bindings are written in OCaml rather than C. However, 
there are two disadvantages:

. A significant amount of boilerplate is currently required (that could easily 
be amortized into an OCaml library)

. The LLVM execution engine is currently very slow to invoke from OCaml 
(taking around 0.5ms for a single function call).

Perhaps the most obvious steps forward are to expose the OCaml macros (e.g. 
Field, Wosize_val) as ordinary C functions so they can be called from 
LLVM-generated code, and then design and implement a DSL and compiler to ease 
the burden of generating FFI code.

As an aside, I think it would also be very interesting to convert OCaml's 
bytecode interpreter from C into a JIT using LLVM by partially specializing 
the existing C code over a given bytecode.

Anyway, LLVM is certainly a very exciting project for the OCaml community!

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?e