Maxim Kizub wrote:

> Bernd Kreimeier wrote:
> >
> > I am looking for a Linux tool to generate Java source
> > from C. I am aware of C2J/C2J++. What I need would
> > have to be used repeatedly - the code will be
> > maintained in C. Changing the C code once to match
> > converters restrictions is feasible.
> >
> > Short of hacking C2J++ - any recommendations?
> >
> >                                                   b.
>
> It's not possible. They have mostly the same syntax,
> but the semantic of languages has about nothing
> common. Don't even think port C program to java
> without complete redesign of basic programs
> structures and data.
> Also, support libraries (libc.so and java.* packages)
> are too different, and this means even more
> for program change (in case of automatic
> conversion).
> C sources may be a good tutorial and/or documentation
> and/or example how to solve the task, but
> simple translating of even middle-colmplex
> program without redesign will lead to
> _very_ slow and inefficient java program.
>
> Regards
>   Maxim Kizub

One possible whay would be to find another intermediate languge wich has
a
bytcode compiler. For example  maybe cobol or Ada.
Then C-> ada compile to bytcode.  This is the best you can get. Maxim is
right the sematices are too
diffrent for a high level languqage to high level trhanslation.
I't would be like writing a C->Lisp converter. I don't think that's a
good Idea.
But A C-> bytecode compiler is possible.  Then bytecode-> java.
It would be some ugly java.

See if there a C-> Some languge -> bytcode converter.

I think a way that would work whell is to modify the Objective-C runtime
to expose a Object file as a Java class
I think its quit possible to produce a java file for a Elf file.  This
would be some sort of JNI like generator. The Objective-C runtime
works in a similar manner.

If you think about it the Hotspot compiler is capable for decompiling
incorrect optimizations supposedly....
So  binding a Java clas file to a ELF file is not impossible.  You
porbably also need the  C structure defineitions or at the least
a clean Header file with prototypes and the C structures.
The C structres go to Classes and the prototypes get wrapped with
JNI calls.
The JNI class then  call the various C functions.

I've succesfully written Java classes wich allow you to layout C
structures in Java so that
Java allcoates the space for the C data structures and there then
accesed using a cast from  C.
This inclueds pointers. So I know you can do that part.

By exposing the shared library calls to Java one could load the cshared
lib and get the funtion offsets.

Then I would use some version of the Objective-C runtime to link  a
generated java class with its native implementation.

This can be done via generating JNI calls also. Anyway I'm thinking
about it as I write certianly doable.

Mike





Reply via email to