[LLVMdev] Two languages in the same IR

Duncan Sands baldrick at free.fr
Sat Mar 5 03:00:42 PST 2011


Hi Renato,

> Is it possible to merge two different languages in the same IR?

it is perfectly possible to compile C++ and Ada (and other languages) to
bitcode and link the modules together, resulting in a mixed language module.
The only thing I know of that doesn't work well is if exception handling
constructs from different languages get inlined into the same function.  But
maybe this is not what you mean?

> With Java, JNI specifies a whole lot of rules to make C structures and
> PCS work with Java classes, if we were to do the same thing in IR,
> would that work?

I'm not entirely sure what you are imagining but it sounds like a job for
the front-end to me.

> Is there anyone doing this today (with any language)?

In Ada you can import functions from other languages.  I regularly do this
to use C, C++ and Fortran functions from Ada.  The frontend takes care of
ensuring that the right calling conventions etc are used, so everything is
sorted out before it gets to the LLVM IR generation stage.

Ciao, Duncan.



More information about the llvm-dev mailing list