是否可以将 LLVM 字节码转换为 Java 字节码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4934707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to transform LLVM bytecode into Java bytecode?
提问by Ben Page
I have heard that google app engine can run any programming language that can be transformed to Java bytecode via it's JVM
. I wondered if it would be possible to convert LLVM bytecode to Java bytecode as it would be interesting to run languages that LLVM
supports in the Google App Engine JVM
.
我听说谷歌应用引擎可以运行任何可以通过它的JVM
. 我想知道是否可以将 LLVM 字节码转换为 Java 字节码,因为运行LLVM
支持 Google App Engine 的语言会很有趣JVM
。
采纳答案by Big Rich
It does now appear possible to convert LLVM IR bytecode to Java bytecode, using the LLJVM interpreter.
现在似乎可以使用LLJVM 解释器将 LLVM IR 字节码转换为 Java 字节码。
There is an interesting Disqus comment(21/03/11) from Grzegorz of kraytracing.comwhich explains, along with code, how he has modified LLJVM's Java class output routine to emit non-monolithic Java classes which agree in number with the input C/C++ modules. He suggests that his technique seems to avoid the excessively long 'compound' Java Constructor method argument signatures usually generated by LLJVM, and he provides links to his modifications and examples.
有一个有趣的Disqus评论从格热戈日(21/03/11)kraytracing.com这也解释了,用代码,他是如何修改LLJVM的Java类输出程序,其与输入的C同意号发射不单片Java类沿/C++ 模块。他建议他的技术似乎避免了通常由 LLJVM 生成的过长的“复合”Java 构造函数方法参数签名,并且他提供了指向他的修改和示例的链接。
Although LLJVM doesn't look like it's been in active development for a couple of years now, its still hosted on Github and some documentation can still be found at its former repository at GoogleCode:
尽管 LLJVM 看起来已经有几年没有积极开发了,但它仍然托管在 Github 上,并且仍然可以在其以前的 GoogleCode 存储库中找到一些文档:
LLJVM @ Github
LLJVM documentation @ GoogleCode
LLJVM @ Github
LLJVM 文档 @ GoogleCode
I also came across the 'Proteuscc' project which also utilises LLVM to output Java Byte code (it suggests that this is specifically for C/C++, although I assume the project could be modified or fed LLVM Intermediate Representation (IR)). From http://proteuscc.sourceforge.net:
我还遇到了“ Proteuscc”项目,该项目也利用 LLVM 输出 Java 字节代码(它表明这是专门针对 C/C++ 的,尽管我认为该项目可以修改或提供 LLVM 中间表示 (IR))。来自http://proteuscc.sourceforge.net:
The general process of producing a Java executable with Proteus then can be summarised as below.
- Generate human readable representation of the LLVM intermediate representation (ll file)
- Pass this ll file as an argument to the proteus compilation system
- The above will produce a Java jar file which can be executed or used as a library
使用 Proteus 生成 Java 可执行文件的一般过程可以总结如下。
- 生成 LLVM 中间表示的人类可读表示(ll 文件)
- 将此 ll 文件作为参数传递给 proteus 编译系统
- 以上将产生一个Java jar文件,可以执行或用作库
I've extended a bash script to compile the latest versions of LLVM and Clang on Ubuntu, it can found be as a Github Gist,here.
我已经扩展了一个 bash 脚本来在 Ubuntu 上编译最新版本的 LLVM 和 Clang,它可以作为Github Gist 找到,这里。
[UPDATE 31/03/14] - LLJVMhas seemed to have been dead for somewhile, however Howard Chu (https://github.com/hyc) looks to have made LLJVMcompatible with the latest version of LLVM (3.3). See Howard's LLJVM-LLVM3.3 branch at Github, here
[更新 31/03/14] - LLJVM似乎已经死了一段时间,但是 Howard Chu ( https://github.com/hyc) 看起来已经使LLJVM与最新版本的 LLVM (3.3) 兼容。在 Github 上查看Howard 的 LLJVM-LLVM3.3 分支,这里
回答by Big Rich
I doubt you can, at least not without significant effort and run-time abstractions (e.g. building half a Von Neumann machine to execute certain opcodes). LLVM bitcode allows the full range of low-level unsafe "do what you want but we won't clean up the mess" features, from direct, raw, constructor-free memory allocation up to completely unchecked casts - real casts, not conversions -you can take i32
and bitcast
it to to a %stuff *
if you wish. Also, JVMs are heavily geared towards objects and methods, while the LLVM guys are lucky they have function pointers and structs.
我怀疑您是否可以,至少在没有大量工作和运行时抽象的情况下(例如构建半个冯诺依曼机器来执行某些操作码)。LLVM 位码允许全方位的低级不安全“做你想做的,但我们不会清理混乱”功能,从直接、原始、无构造函数的内存分配到完全未经检查的强制转换——真正的强制转换,而不是转换——你可以把i32
和bitcast
它的%stuff *
如果你想。此外,JVM 非常面向对象和方法,而 LLVM 人员很幸运,他们拥有函数指针和结构。
On the other hand, it seems that C can be compiled to Java bytecodeand LLVM bitcode can be compiled to Javascript(although many features, e.g. dynamic loading and stdlib functions, are lacking), so it should be possible, given enough effort.
另一方面,C似乎可以编译为 Java 字节码,LLVM 位码可以编译为 Javascript(尽管缺少许多功能,例如动态加载和 stdlib 函数),因此只要付出足够的努力,它应该是可能的。
回答by box
Late to the discussion: Sulong executes LLVM IR on the JVM. It creates executable nodes (which are Java objects) from the LLVM IR instead of converting the LLVM IR to Java bytecode. These executable nodes form an AST interpreter. You can check out the project at https://github.com/graalvm/sulongor read a paper about it at http://dl.acm.org/citation.cfm?id=2998416. Disclaimer: I'm working on this project.
讨论晚了:速龙在JVM上执行LLVM IR。它从 LLVM IR 创建可执行节点(它们是 Java 对象),而不是将 LLVM IR 转换为 Java 字节码。这些可执行节点构成了一个 AST 解释器。您可以在https://github.com/graalvm/sulong查看该项目或在http://dl.acm.org/citation.cfm?id=2998416阅读有关它的论文。免责声明:我正在研究这个项目。
回答by AlexR
Read this: http://vmkit.llvm.org/. I am not sure that it will help you but it seems to be relevant.
阅读:http: //vmkit.llvm.org/。我不确定它会帮助你,但它似乎是相关的。
Note:This project is not more maintained.
注意:此项目不再维护。