15

I saw the http://vmkit.llvm.org/ project but it's not quite what I'm looking for. Don't want my code to run on yet another VM but on .NET's and Java's VM.

Are there any compiler backends for LLVM that generate .NET CIL and/or Java Bytecode?

  • 1
    What's wrong with using C# for CIL or Java for Java bytecode? Why do you want to go through LVVM? – svick Jun 29 '11 at 23:35
  • 9
    svick, this path will allow C code to compile to CIL or Java bytecode. – Thorbjørn Ravn Andersen Jun 30 '11 at 14:40
  • In case you are interested in java look at the following, http://stackoverflow.com/questions/4934707/is-it-possible-to-transform-llvm-bytecode-into-java-bytecode its not 100% the same question as its only specific to java. – Peter Oct 15 '13 at 08:31

2 Answers2

7

LLVM is on a much lower level than CIL and Java byte code. This means that it is difficult to map the LLVM instructions on to CIL and Java instructions, and nobody has really needed it yet so the work has not been done completely.

Some of the work has been done though. See http://llvm.1065342.n5.nabble.com/JVM-Backend-tp41356.html to see if it is useful to you.


EDIT 2020-09-03: Since this answer was written, WebAssembly has been defined which is essentially a cross platform machine language definition which runs in all major browsers and hopefully soon also natively on Linux and others. I would think that the future would be that everything distributes in this format and then is run on the appropriate virtual machine. This will most likely end the CPU wars.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • 3
    hmmm, if llvm code can be compiled to Javascript that if you ask me is at a much higher level then cil or java bytecode then it should be compilable to cil/javabytecode, also your link seems to be broken! – Peter Oct 14 '13 at 20:14
  • 3
    As they all are Turing Complete so yes. That alone, however, does not mean that it is easy to map instructions from one world to the other. Just think how you would map java byte code to assembler... – Thorbjørn Ravn Andersen Oct 14 '13 at 21:14
  • I do like your example @ThorbjørnRavnAndersen but isn't that exactly what a JIT bytecode runner does? Perhaps a better example is mapping assembler code into java bytecode; this seems to be more about converting low-level code to high-level code. – Lazerbeak12345 Sep 02 '20 at 17:21
0

C++ can be compiled to CIL (with visual C++/CLI compiler), so why not a CIL backend for LLVM?
I don't think it would be so complicated as far as the not .NET specific CIL instruction set
is quite small/simple. Compiling C++ to Java is much more complicated because there are no pointer instructions in Java's bytecode, so a Java's bytecode LLVM backend would be much more complicated.

I guess guys from MONO LLVM backend have already worked on something similar, but it seems they exploited LLVM in a different way because MONO is a C# compiler not a C++ compiler.

gre_gor
  • 6,669
  • 9
  • 47
  • 52
reuns
  • 17
  • 1