[LLVMdev] Methodology for interfacing LLVM JITed code with C++
angray at beeb.net
Wed Sep 12 09:11:53 CDT 2007
> I'm currently working on a C-like scripting language compiler backend
> designed to emit LLVM code. This code will be loaded into LLVM's JIT at
> runtime and will make calls into a C++ library (including calling
> virtual methods on C++ objects). The translation from our AST to an
> llvm::Module is fairly straightforward, the difficulty, however, comes
> in generating the appropriate LLVM code to call into the C++ code. We
> see two main issues, name mangling and virtual functions.
I suggest using IDL or an IDL like approach. Basically paralleling vtables
with structs and calling pointers to functions/vtable members directly. IDL
provides a way of automating this in C. But you could modify an open source
IDL to produce LLVM code. Both CORBA and Microsoft COM use IDL.
Hope this helps,
More information about the LLVMdev