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

六眼飞鱼酱① 提交于 2019-12-24 05:26:09

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/45232722/llvm-interoperability-like-jvm-or-net-is-it-possible-to-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!