Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can C/C++ software be compiled into bytecode for later execution? (Architecture independent unix software.)

I would want to compile existing software into presentation that can later be run on different architectures (and OS).

For that I need a (byte)code that can be easily run/emulated on another arch/OS (LLVM IR? Some RISC assemby?)

Some random ideas:

  • Compiling into JVM bytecode and running with java. Too restricting? C-compilers available?
  • MS CIL. C-Compilers available?
  • LLVM? Can Intermediate representation be run later?
  • Compiling into RISC arch such as MMIX. What about system calls?

Then there is the system call mapping thing, but e.g. BSD have system call translation layers.

Are there any already working systems that compile C/C++ into something that can later be run with an interpreter on another architecture?


Edit

Could I compile existing unix software into not-so-lowlevel binary, which could be "emulated" more easily than running full x86 emulator? Something more like JVM than XEN HVM.

like image 510
jkj Avatar asked Jun 22 '11 11:06

jkj


People also ask

How is a bytecode program executed?

A bytecode program may be executed by parsing and directly executing the instructions, one at a time. This kind of bytecode interpreter is very portable. Some systems, called dynamic translators, or just-in-time (JIT) compilers, translate bytecode into machine code as necessary at runtime.

How does C++ code compile to machine code?

C++ code can be compiled to an intermediate format and JIT'ed to machine code, or it can be interpreted or anything else you like. This is trivial, and most compilers already do that. gcc compiles to RTL (register transfer language) which is then translated to the target CPU.

What are the advantages of bytecode in programming languages?

This introduces a delay before a program is run, when the bytecode is compiled to native machine code, but improves execution speed considerably compared to interpreting source code directly, normally by around an order of magnitude (10x).

Can Visual Studio compile C++ as bytecode?

Parrot project will have c++ bytecode compilation and execution parrotVisual Studio can compile C++ as bytecode C++ managed Share Improve this answer Follow answered Oct 2 '09 at 18:05 SomeUserSomeUser 1,8891414 gold badges4141 silver badges5757 bronze badges 2 3 Just remember that Managed C++ is notC++.


1 Answers

There are several C to JVM compilers listed on Wikipedia's JVM page. I've never tried any of them, but they sound like an interesting exercise to build.

Because of its close association with the Java language, the JVM performs the strict runtime checks mandated by the Java specification. That requires C to bytecode compilers to provide their own "lax machine abstraction", for instance producing compiled code that uses a Java array to represent main memory (so pointers can be compiled to integers), and linking the C library to a centralized Java class that emulates system calls. Most or all of the compilers listed below use a similar approach.

like image 122
Don Kirkby Avatar answered Oct 21 '22 04:10

Don Kirkby