This article presents a C to Java translator. Coming soon! Please check this Website regularly for updates.
This C to Java translator is known by its shorter abbreviation: c2java. You can download the Java code for the c2java translator. This code is subject to the GNU General Public License. To build Java code from a C source file, first execute these commands from the folder that you downloaded c2java-1.21-20160926-132616.tar.gz to:
tar -xvf c2java-1.21-20160926-132616.tar.gz
Before you build the c2java translator, you might consider setting c2java-1.21/com/davinpearson/ByteCodeInterpreter.java’s variable debug variable to false (for no debug information). The Makefile takes one argument STUMP and for a C file such as A0.c the Makefile invocation should be without the .c extension like so:
make default STUMP=A0
To invoke the byte code interpreter separately, issue the following Makefile target from the folder c2java-1.21:
make clean com/davinpearson/ByteCodeInterpreter.jrun ARGS=A0
To simply build the byte code file A0.c2j and the glued file A0.glued, issue the following Makefile target: from the folder c2java-1.21:
make clean A0.c2j
If you are not touching the files c2java-1.21/*.java, c2java-1.21/com/davinpearson/*.java, c2java-1.21/com/davinpearson/expr/*.java and c2java-1.21/com/davinpearson/stmt/*.java then the Makefile invocation can be without the ‘‘clean’’ target like so:
make com/davinpearson/ByteCodeInterpreter.jrun ARGS=A0
To build c2java-1.21/A*.c (all of the tester module C source files) into c2java, simply issue the following Makefile commands from the folder c2java-1.21:
The first command builds files A0.c, A1.c, A2.c ... A29.c. The second command builds files A30.c, A31.c, A32.c ... A59.c. To build and execute a C source file such as A0.c using the C compiler and linker, issue the following Makefile command from the folder c2java-1.21:
Note that you will need to uncomment the lines that say ‘‘//#define strobe(x)’’ for the code to compile. These lines should be commented out if you want to build a Java interpreter for the C code. To build and execute all of the tester module C source files like A*.c using the C compiler and linker, issue the following Makefile command from the folder c2java-1.21:
The package c2java now supports include files, but not linking across multiple object files. You must #include all of your code from the main file being compiled. Figure 1 of the following diagram shows the situation using a C compiler and linker and Figure 2 of the following diagram shows the situation with c2java:
In the above diagram, you have three source code files: a.c, b.c and c.c. They are compiled to produce the object files a.o, b.o and c.o, before linking them together to produce an executable called for argument's sake foo.exe. Also there are three header files a.h, b.h and c.h. On the right hand side of the above diagram the C source files have been renamed from *.c to *.ch and the three source files are #included by a file called for argument's sake global.c. The c2java translator is then run on global.c to produce output files global.glued and global.c2j suitable for interpretation by the Java byte code interpreter com.davinpearson.ByteCodeInterpreter.
Currently the only built-in functions from the built-in C standard library libc you can call are as follows:
Other functions will be added as time progresses.
|Back to Research Projects|
This page has the following hit count: