CL-LLVM Frontend – Bindings to LLVM C lib (via CFFI & SWIG)

I have just added CFFI integration of the C bindings of LLVM to my project that aims to create a Compiler LLVM Frontend for Common Lisp.

For creating the bindings, I have used SWIG for creating the CFFI definitions. I was delighted to see that a simple SWIG file that just includes Core.h of the LLVM C headers seems to be sufficient at this point:

%module llvmcffi
#include <llvm-c/Core.h>
%include <llvm-c/Core.h>

running this through swig via

$ swig -I/usr/local/include -cffi llvmcffi.i

results in a LISP file that is about 50kb in size and contains CFFI definitions for all LLVM core types & functions.

I have successfully integrated this stuff into my project by writing a small “loader” file that loads

(cffi:define-foreign-library libllvm
  (t (:default "libLLVM-3.2")))

(cffi:use-foreign-library libllvm)

and by including these two files into my asd definition.

Now I can stop writing LLVM-IR directly in a clumsy and error-prone way and start using the LLVM-C-interface instead.

Cool stuff! 🙂

Stay tuned…