Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LLVM Interoperability (Like JVM or .Net) - Is it possible to do?

I recently played around a bit with different LLVM Frontends like Clang (C Familiy ), LDC2 (D), Terra, ...

All these languages can be compiled into the LLVM IR (somewhat readable) and LLVM IR Bitcode . So at this stage they are all on the same "level" right?

My Question is : Is there some way of language interoperability like the .NET Languages or JVM Languages on "language level" or is it only possible to do it by editing in the IR?

I already looked this question up in Google but didn't find what is was looking for.

If yes how can I do it and can I do it with all frontends or only some specific?

like image 867
T.Furholzer Avatar asked Oct 21 '25 16:10

T.Furholzer


1 Answers

For language X be able to call language Y, it must possess an ability to

  • Call Y functions (know Y's calling convetions)
  • Convert data passed to Y into form it expects (called marshalling)

This mostly should be done on front-end level (not middle-end, which LLVM is). C language can be used as common ground for interop, so if two languages can call C and export their own functions to C, they can talk to each other.

Haskell and C++ can serve as example. C++ can export code as C using

extern "C" {
}

block, and Haskell can also export its functions with foreign export ccall keywords. It also features marshalling functions to convert Haskell strings to C string and back.

As you can see, LLVM plays minor role here, but you were right mentioning that with LLVM you can, theoretically, interop any language that compiles to LLVM by manually editing resulting IR.

like image 50
arrowd Avatar answered Oct 23 '25 09:10

arrowd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!