Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to transform LLVM bytecode into Java bytecode?

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.

like image 863
Ben Page Avatar asked Feb 08 '11 15:02

Ben Page


People also ask

Does JVM use LLVM?

Assuming you mean JVM rather than Java: The LLVM is a low level register-based virtual machine. It is designed to abstract the underlying hardware and draw a clean line between a compiler back-end (machine code generation) and front-end (parsing, etc.). The JVM is a much higher level stack-based virtual machine.

Is LLVM a bytecode?

What is commonly known as the LLVM bitcode file format (also, sometimes anachronistically known as bytecode) is actually two things: a bitstream container format and an encoding of LLVM IR into the container format. The bitstream format is an abstract encoding of structured data, very similar to XML in some ways.

Can C be compiled to Java bytecode?

Axiomatic Solutions has an answer to this problem called Axiomatic Multi-Platform C (AMPC). This software can compile C source files directly into Java class files.

What converts source code into bytecode in Java?

The Java compiler (javac) converts the source code into bytecode. Bytecode is a kind of average machine language.


1 Answers

It does now appear possible to convert LLVM IR bytecode to Java bytecode, using the LLJVM interpreter.

There is an interesting Disqus comment (21/03/11) from Grzegorz of kraytracing.com which 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.

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
LLJVM documentation @ 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:

The general process of producing a Java executable with Proteus then can be summarised as below.

  1. Generate human readable representation of the LLVM intermediate representation (ll file)
  2. Pass this ll file as an argument to the proteus compilation system
  3. The above will produce a Java jar file which can be executed or used as a library

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.

[UPDATE 31/03/14] - LLJVM has seemed to have been dead for somewhile, however Howard Chu (https://github.com/hyc) looks to have made LLJVM compatible with the latest version of LLVM (3.3). See Howard's LLJVM-LLVM3.3 branch at Github, here

like image 162
Big Rich Avatar answered Sep 21 '22 19:09

Big Rich