Hi all, Is it possible to merge two different languages in the same IR? 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? Is there anyone doing this today (with any language)? -- cheers, --renato http://systemcall.org/ Reclaim your digital rights, eliminate DRM, learn more at http://www.defectivebydesign.org/what_is_drm
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.
Hey, we are intermixing LLVM IR generated from C code with IR generated from our custom RenderMan frontend. I am not sure whether this is relevant for you, but in our restricted setting (the C code does not change frequently and we have full control at link time) this works flawless. Best, Ralf Am 05.03.2011 11:42, schrieb Renato Golin:> Hi all, > > Is it possible to merge two different languages in the same IR? > > 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? > > Is there anyone doing this today (with any language)? >
On 5 March 2011 11:00, Duncan Sands <baldrick at free.fr> wrote:> 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?Hi Duncan, Exception handling is another beast, not concern about it now... ;)> 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.So the Ada front-end "understands" C? And generate IR from both? I was thinking more along the lines of linking IR generated by two (or more) different front-ends. One would need some kind of ABI (like JNI) to make sure types and PCS were retained. cheers, --renato
On 5 March 2011 11:26, Ralf Karrenberg <Chareos at gmx.de> wrote:> we are intermixing LLVM IR generated from C code with IR generated from > our custom RenderMan frontend. I am not sure whether this is relevant > for you, but in our restricted setting (the C code does not change > frequently and we have full control at link time) this works flawless.Hi Ralf, This is more along the lines of what I was thinking... But as you say, you have full control at link time and you can enforce the "ABI" yourself. I was wondering how relevant is this intermixing of languages and how many people were doing this. Mapping between any two (or more) languages' ABIs would be a fun exercise... ;) cheers, --renato