[LLVMdev] Methodology for interfacing LLVM JITed code with C++

Aaron Gray angray at beeb.net
Wed Sep 12 07:11:53 PDT 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.

See :-

        http://en.wikipedia.org/wiki/Interface_description_language

Hope this helps,

Aaron




More information about the llvm-dev mailing list