Converting C++ to Java

Hi

We want to use our existing engine sourcecode to build Java applications. Our core engine is written in C/C++ and has hooks to platform specific functions which we have filled in for lots of platforms so far, PC, DS, PS2, PSP, XBOX, IPHONE etc. All of which can use C/C++ as their compiler. However now we want to target Android platforms, so we are looking into converting the main body of code automatically into Java. This means as we add code to the main engine, we don’t have to keep adding Java code – w would like to just convert it automatically. We have looked at converter software, but even the “best” won’t touch pointer arithmetic. We don’t use this excessively, but certain parts of the engine do use it for streaming data, building variable length lists, etc, and we also have internal memory allocation code which “grabs” a large area of memory at the start, then casts parts of it to all sorts of different structures.

Is it going to be possible to use LLVM to convert our platform agnostic engine code to Java, then link in the “hook” functions entirely written in Java. These functions do things such as “read data from file”, “play sound effect”, “draw triangle”.

Thanks, looking forward to your replies !

Shaun Southern

Team 3 Games Ltd

Hi

We want to use our existing engine sourcecode to build Java applications. Our core engine is written in C/C++ and has hooks to platform specific functions which we have filled in for lots of platforms so far, PC, DS, PS2, PSP, XBOX, IPHONE etc. All of which can use C/C++ as their compiler. However now we want to target Android platforms, so we are looking into converting the main body of code automatically into Java. This means as we add code to the main engine, we don’t have to keep adding Java code – w would like to just convert it automatically. We have looked at converter software, but even the “best” won’t touch pointer arithmetic. We don’t use this excessively, but certain parts of the engine do use it for streaming data, building variable length lists, etc, and we also have internal memory allocation code which “grabs” a large area of memory at the start, then casts parts of it to all sorts of different structures.

Emitting Dalvik byte-code (Android does not use standard Java byte-code) would require a new target back-end in LLVM.

The question I have is: why port everything to Dalvik byte-code? You can use the Android NDK to compile native C/C++ and just write your “hook” functions in Java with an appropriate JNI interface. This seems like it would save a lot of time!

To get full C++ support including STL, exceptions, and RTTI, look at Crystax’s build of the NDK: http://www.crystax.net/