Hi,
This idea just struck me -
Is it possible to write a Java bytecode backend for gcc? It would certainly be pretty cool to be able to compile C/C++ code into Java bytecode =).
Hi,
This idea just struck me -
Is it possible to write a Java bytecode backend for gcc? It would certainly be pretty cool to be able to compile C/C++ code into Java bytecode =).
C++ into Java bytecode? That could be ugly.
I believe it might have been done already, though, I don't know of it being done for GCC.
Last edited by MacGyver; 05-08-2008 at 12:13 AM.
Actually it would be gcc's language-independent intermediate code (where gcc does all its optimizations) to Java bytecode, (IIRC) instead of x86 or SPARC code.
How would this be useful? One time another compiler developer thought something like this would be useful and even developed a back end for other language. They even made their own languages specifically for this intermediate code. Many thought it would be a fad that would disappear... But alas it stayed. And it was not and still is not a good system.
Meanwhile, gcj?
Last edited by master5001; 05-08-2008 at 05:28 AM.
IIRC gcj is a frontend. It translates java into the intermediate code.
Why is intermediate code not a good idea? IMHO it simplifies gcc quite a bit? Eg, without the intermediate code, every frontend will need to have their own optimizer, and their own set of binary code generators?
How else would you achieve this kind of modularity without intermediate code?
Last edited by cyberfish; 05-08-2008 at 12:38 AM.
The reason I say this is because language like JAVA are exactly what you are asking to have. I am not saying its a horrible idea in practical use, I am just considering the development time of this framework, the development time of applications, the efforts in porting code, etc. For what? A JAVA clone. Unless you are M$ trying to skirt patent issues, there is no need to develop your own JAVA equivalent.
OK, let's get some facts straight.
1) The effort of developing the framework is being done. It's called GNU Classpath.
2) The effort of developing the frontend is being done. It's called gcj.
3) Gcj can output Java bytecode.
4) General GCC cannot output Java bytecode. Gcj bypasses the GCC backend for generating bytecode.
GCC's intermediate representation is register-based. It is very unsuitable for the generation of stack-based code like Java bytecode. That's why nobody wants to write a bytecode backend.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Doing this would be non-trivial but certainly possible. The hardest part is mapping the pseudo-registers of the intermediate code to the Java stack.
And I'm baffled by the criticism of intermediate code.