Using LCC with the JAVA backend

Note:This is meant for lcc 4.1.

Building the compiler

  1. Edit etc/java.c, setting the paths correctly for your system.
  2. Copy files in lcc-java/src to lcc-4.1/src
  3. Copy files in lcc-java/etc to lcc-4.1/etc
  4. Copy lcc-java/makefile to lcc-4.1/makefile
  5. Do make.
  6. Edit the jcc_base and lcc_base paths at the top of jcc (which is a shell script). lcc_base should be the directory where your installed lcc binary is located. jcc_base is the place where you will put class_header and class_footer. I put these in /usr/local/lib/lcc-java.
  7. Copy lcc-java/jcc and lcc-java/jld to somewhere in your path (/usr/local/bin might be a good choice)

Building the demo programs

  1. cd lcc-java/test
  2. $ jcc hello.c externs.java
  3. Compile hello.java externs.java and lcc-java/c_program.java together. You should be able to use the test cradle in lcc-java/hellotest.java to run the program, by putting in the name of the class you created.

    The hellotest cradle just sets up the globals for the program, then calls it's main function. (equivalent functionality to _start in crt0.o)

jcc

Usage: jcc c-program.c [link-with.java ...]

jcc compiles the indicated C program to java, making arrangements to call functions present in the link-with.java files as the corresponding calls in C. For example if externs.java contains printf then if externs.java is specified on the jcc command line, whenver printf is called the resulting call will go to the java method printf in externs.java.

For a method to link correctly, it must be a public static method and have the exact signature '( c_program parent )'. The c_program argument passes the virtual machine state to the function so that it can act on C arguments and return a value.