1 This is a wrapper around the LLVM C API. The design is to be a fairly
2 thin wrapper, without much lispification.
4 NOTE: currently I've checked in the generated bindings in
5 src/generated/*.lisp. These are autogenerated with SWIG, but with
6 slightly modified versions of the LLVM .h files to make them work
7 better with SWIG. (so you shouldn't rebuild them). I'm working on
8 getting the changes upstream. Oh, and I patched SWIG too because it's
9 got some annoying bugs in its CFFI generator. :)
14 1) Build the shared library.
16 Ensure you have llvm installed (including llvm-dev if applicable
17 for your distribution), then run:
21 2) Make the asdf system available.
23 The way I do that is like this:
25 $ ln -s $PWD/cl-llvm.asd ~/.sbcl/systems
30 There's an example of usage in examples/test.lisp.
32 A more substantial example of usage is my work to port SBCL itself to
33 support an LLVM backend, available at:
34 http://repo.or.cz/w/sbcl/llvm.git/
39 There are a few things which I have adjusted in the wrapper:
41 1) The LLVM C API has a concept of a global context. I do not use the
42 C-level global context in the Lisp bindings, but instead have a
43 lisp-level dynamic variable *llvm-context*, which you may
44 rebind. (e.g. if you want to use LLVM from multiple threads without
45 locking, give each thread its own *llvm-context*).
47 Whenever the LLVM C API has a pair of functions like
48 "LLVMInt32Type" and "LLVMInt32TypeInContext", I have instead
49 created a single function "LLVMInt32Type", which takes the same
50 arguments as the C function, but also takes an extra optional
51 argument for the context that defaults to *llvm-context*.
53 2) Where the C API takes a pointer and a count for an array of values,
54 such as LLVMFunctionType, I have replaced the pointer/length
55 arguments with a list argument, in the same position.
57 3) ...Except for LLVMAddIncoming, which in the C API, took an array of
58 incoming values/blocks to add to the PHI node. I simplified it to
59 take one at a time: call it multiple times to add multiple incoming
62 4) Where the C API uses an output array argument, such as
63 LLVMGetStructElementTypes, I instead return a list.
65 5) Where the C API takes a pointer to a char *ErrorMsg, ...FIXME