• What’s LLVMRuby

LLVMRuby is a set of bindings making the LLVM compiler infrastructure (llvm.org) usable from Ruby. This extention allows using LLVM as an abstract assembler and reflects a good chunk of the LLVM class hierarchy into Ruby. Included is an example of using this to build a simple JIT compiler, written entirely in Ruby, which is able to interact with the native Ruby 1.8/1.9 data types.

  • How to build

You must get LLVM from svn and build it separately:

$ svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm

Make sure that you configure LLVM with PIC enabled:

$ ./configure --enable-pic

Add the llvm bin directory to your path, extconf needs to be able to find llvm-conf:

$ export PATH=$PATH:/$LLVMDIR/Debug/bin

Once you have built LLVM, run extconf.rb giving it location of LLVM:

$ ruby extconf.rb --with-llvm-include=/$DIR/llvm/include --with-llvm-lib=/$DIR/llvm/Debug/lib

Run make

$ make

Run the tests (you will need Rake installed)

$ rake test

Look in test.rb to see examples of use and start messing around.

  • Caveats

I created this using very latest LLVM (from svn, soon to be 2.4). Other versions may not work. I have been trying to get the 2.3 released package to work, only one conditional typedef is required, but it complaining about fPIC stuff :(

I primarily develop this on my home machine which is 64bit Fedora. I occasionally test it on a 32bit CentOS machine, and recently tested it on a 32bit MacBook. It built and passed tests with no issues. My knowledge of building either Ruby or LLVM on Windows is minimal. It should be doable, but I don’t believe LLVM currently is usable with VC++, which is the main compiler for Ruby on Windows, so you may run into fun times trying to figure out a good way to make that go.

  • Things that definitely do not work right now

No attempt has been made to properly free LLVM objects. This probably isn’t hard, LLVM api has easy to deal with memory management. Many LLVM objects end up owned by modules/execution engine and shouldn’t be freed normally anyway.

There needs to be a lot more exception raising when arguments are of wrong number/type.

Malformed LLVM functions will cause the program to abort, even just from calling verify on a module. This seems like a bug in LLVM. Verification in theory is slow and should be used only for debugging, but it would nice if tests did not abort and die because of missing block terminators or whatever.

  • Copying

See the file COPYING

  • Author

For questions or answers, my email is: [email protected]