Bindings, Platforms, and Innovation
This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.
Tracking change and innovation in the enterprise software development community
Posted by Werner Schuster on Oct 18, 2008 03:19 PM
LLVM contains the letters "VM", but it's actually a framework for building compiler backends. In short, it comes with an instruction set (immediate representation) and a backend which optimizes the code and generates native code for a host of platforms (x86, ARM, ...). One of the real world uses is in Apple's OpenGL JIT.
Llvmruby (llvmruby GitHub repository) is project by Tom Bagby. It provides Ruby bindings to LLVM. Llvmruby is well integrated into Ruby. For instance, this code adds an add instruction (codeblock is an instruction builder).
codeblock.bin_op(Instruction::Add, 41.llvm, 1.llvm)
Llvmruby opens Object and adds llvm to turn them into values LLVM can handle.
After following the instructions in the README (getting and compiling LLVM and compiling llvmruby), it's possible to start experimenting, eg. with irb. Here a sample session (with some snippets of code taken from the samples in the llvmruby project):
# Set up LLVM
>> require 'llvm'
=> true
>> include LLVM
=> Object
>> m = LLVM::Module.new("test_module")
=> ; ModuleID = 'test_module'
# Create a function type - the second argument is the method signature,
# ie. the return type and the types of the arguments
# In this case, there are no return values or arguments
>> type = Type::function(MACHINE_WORD, [])
=> #
>> f = m.get_or_insert_function("test", type)
=>
declare i32 @test()
# Create an LLVMBuilder object which allows to call methods and
# generate instructions
>> builder = f.create_block.builder
=> #
# Create an Add instruction - note how it's possible to pass regular Ruby Fixnums
>> ret = builder.bin_op(Instruction::Add, 41.llvm, 1.llvm)
=> #
>> fcode = builder.return(ret)
=> #
>> ExecutionEngine.get(m);
=> true
# Finally: execute the generated code
>> ExecutionEngine.run_autoconvert(f)
=> 42
For more information on using LLVM, the LLVM Tutorial shows how to implement a JIT for a simple language and more.
Two bigger examples using llvmruby come from Miura Hidek:
Llvmruby allows to experiment with LLVM without having to touch any C++ and also allows to do so incrementally with irb. A useful property, eg. for contributors to Rubinius (the project plans to use LLVM) to prototype ideas. The Rubinius team has been busy rewriting the VM in C++ and cleaning up some internals. This work is currently happening on the CPP branch of Rubinius in the Git repository, which also contains LLVM as an external library. The C++ branch should soon turn into the master branch. According to some recent Twitters, Rubinius has regained the ability to run a lot of Ruby code with the new C++ VM. Eric Hodel twittered this week
Rubinius' new vm can now run the core specs without crashing
Evan Phoenix recently reported:
Huzzah! IRB works again under the new Rubinius C++ VM!
How would you use LLVM with Ruby?
Give-away eBook – Confessions of an IT Manager
Usage Landscape: Enterprise Open Source Data Integration
Agile Development: A Manager's Roadmap for Success
Effective Management of Static Analysis Vulnerabilities and Defects
There's also libjit + ruby 1.9 [http://rumble.withoutpenandink.com:4559/]
Note that libjit is now LGPL 2.1 so that's nice. I'm not sure how the speed compares with LLVM.
Could someone please port psyco to Ruby for me?
Ludicrous has been around for over a year now and has the ability to selectively JIT-compile methods on both 1.8 and 1.9 (which reduces risk of a bug in the compiler affecting the entire application). I don't know how the speed compares to an LLVM-based solution either, but I suspect that though LLVM should generate better code, the difference should be minimal, because the bottlenecks are in places like block invocation and method dispatch. Whichever compiler optimizes these better will perform better in real-world applications.
This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.
This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.
This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.
This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.
This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.
After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.
IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.
Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.
2 comments
Watch Thread Reply