previous                   ToC                next

 

9. Code generation

 

Finally the front end of a compiler has to generate intermediate code.

Since we don't aim at developing a new back end for our compiler, the choice of an intermediate representation  language is determined by the choice of an already available back end.

The LLVM compiler infrastructure is a collection of source code that implements static back ends for the X86, X86-64, PowerPC, PowerPC-64, ARM, Thumb, SPARC, Alpha, and IA-64 architectures.

LLVM uses a virtual instruction set that provides type safety, low-level operations and flexibility.

 

We have installed LLVM-2.7 revision on the Linux Fedora 13 platform and used the shell script llvm.spt to perform the following steps:

· assemble a LLVM program ( .ll file ) into LLVM bitcode ( .bc file )

· compile LLVM bitcode into Intel assembly language for the x86 architecture ( .s file )

· run LLVM bitcode .

The LLVM code generator for mjava is specified in mjava.cup.

In this first implementation, we have only considered non object-oriented mjava programs, such as Fact.mjava, where no class instance is created and all the methods are called internally to their declaring classes.

You can generate the front end, run it on the input program Fact.mjava to produce the LLVM program Fact.mjava.ll, and finally launch llvm  by means of mjava.spt and the files in CodeGenerator.rar.

The x86 assembly program Fact.mjava.s will be emitted and the output reported in  CodeGeneratorResult.txt will be printed on your terminal.

You can also try to compile and run the other mjava programs stored in the CodeGenerator/source directory, or to write and test your own mjava programs.

 

previous                   ToC                next