LLVM互操作性(类似于JVM或.Net)-可以这样做吗? [英] LLVM Interoperability (Like JVM or .Net) - Is it possible to do?

查看:109
本文介绍了LLVM互操作性(类似于JVM或.Net)-可以这样做吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在CLL(C Familiy),LDC2(D),Terra等不同的LLVM前端上玩了一些游戏...

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

所有这些语言都可以编译为LLVM IR(有点可读)和LLVM IR Bitcode.因此,在这个阶段,他们都处于相同的级别"上吗?

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?

我的问题是:是否存在某种语言互操作性,例如语言级别"上的.NET语言或JVM语言,还是只能通过在IR中进行编辑来实现?

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?

我已经在Google中查询了此问题,但没有找到所需的内容.

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?

推荐答案

要使语言X能够调用语言Y,它必须具备以下能力:

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

  • 呼叫Y函数(知道Y的呼叫让步)
  • 将传递给Y的数据转换为期望的形式(称为编组)

这主要应该在前端级别(而不是LLVM的中端)上完成. C语言可以用作互操作的通用基础,因此,如果两种语言可以调用C并将自己的函数导出到C,它们就可以相互交谈.

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和C ++可以作为示例. C ++可以使用以下代码将代码导出为C

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

extern "C" {
}

block,Haskell也可以使用foreign export ccall关键字导出其功能.它还具有编组功能,可将Haskell字符串转换为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.

如您所见,LLVM在这里起着很小的作用,但是您正确地提到,使用LLVM,从理论上讲,您可以通过手动编辑生成的IR互操作编译为LLVM的任何语言.

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.

这篇关于LLVM互操作性(类似于JVM或.Net)-可以这样做吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆