I've spent some time sifting through the documentation for LLVM, and I'm both impressed and horrified. I'm not sure I've ever seen so much documentation about something that looks really cool that I'm not interested in. I've been reading the dragon book and Advanced Compiler Design and Implementation, and I wanted to use LLVM to generate a simple runtime JIT compiler, but I can't seem to find the necessary documentation.
I see plenty of documentation on the IR, the various command-line tools, and just about everything else LLVM-related except for a straightforward tutorial that explains how to
- blast either opcodes or IR at the LLVM API, and
- have LLVM either emit an ELF/blob/whatever or execute the result.
I did manage to find a couple of examples that give me half of what I want. The source code ships with a sample Brainfuck compiler which reads an input bf file and emits LLVM IR. There are a couple more examples that show how to construct a basic JIT, then create some functions that do frustratingly simple things like calculate Fibonacci numbers or add two integers together, but nothing that's too much more detailed than that.
Oh, did I mention that the online API documentation is broken?
A bit of googling turned up libjit, which is almost exactly what I want. It's got a simple C API (instead of the nightmarishly bloated C++ monstrosity that is the LLVM API), a simple build and link system, and simple, straightforward and complete documentation. In short, it's everything that I want.
It's also GPL-licensed, which makes it almost completely unusable. I found this 2006 email exchange comparing libgit and LLVM. The author, who apparently works on libgcj, mentions all of my problems with LLVM (sans the anti-C++ bias).
My other crazy idea was to generate C as an IR and blast it at libtcc, but with my limited fiddling I couldn't get to do anything other than segfault on me. Incidentally, the documentation for libtcc is a single file and it's still better than what's available for LLVM.
So here's my question: Is there a decent book or tutorial that walks through the LLVM API? I've Googled to the end of the earth and back, I've seen the Stacker documentation, and I've read through everything in the LLVM documentation section, and none of it was what I'm looking for. I'm open to suggestions...