lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


A while ago we wrote a binding to LLVM in Lua. Not to be confused with llvm-lua, which converts Lua bytecode to LLVM IR. Instead, this was for generating code on-the-fly, using LLVM's API for generating intermediate representation (IR). LLVM IR isn't quite assembly, but it's close; and the optimizations are admirable. It's also pretty fast to compile from the IR level.  

However, in the end generating code at this low level wasn't scaling well, so we shifted the project toward compiling C/C++ via the Clang front-end to LLVM. The resultant JITted code is just as fast, and it has the advantage of being able to hook into existing library code much more easily. It's currently living in the LuaAV repository but should be easy enough to lift out [1]. 

That said, the Clang solution isn't perfect either: the compilation time is quite a lot longer (especially parsing large template-filled C++ headers). At some point I'm planning to revisit the raw LLVM IR bindings, because the speed to compile is so much faster; I'll post results if they become clean enough to be worth looking at.

BTW One major caveat with LLVM is that it is *big*. Expect many megabytes of library dependency... 

[1] http://www.mat.ucsb.edu/projects/luaAV/browser/trunk/LuaAVApp/luaclang

Graham

On Jan 4, 2011, at 6:26 PM, beo wulf wrote:

Played with tcc before -- it's fast at assembling, but there's no
optimiations for the assembled code (in particular, it pushes
everything to the stack after every operation) -- i.e. -- the
generated code is _NOT_ fast.

On Tue, Jan 4, 2011 at 4:12 PM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
As for why not C ? C is fine, but I'd prefer to not write out a *.c
file, call gcc, compile it to a *.so, and load it back in -- just
something self contained.

As suggested before, try luatcc.