previous                   ToC                next

 

10. Object oriented code generation

 

In object oriented languages such as Java (and mjava), array and object variables behave like pointers whose values are assigned when new instances are created.

When a method is called externally to its declaring class, the following operations must be performed:

1. determine the class in which the method is declared and look for the method in that class

2. pass the object on which the method is called as an extra argument of the method call.

The translation of method declarations must avoid name clashes among methods declared with the same name in different classes: for this reason the name of the translated method is the concatenation of the class name and the method name.

 

The final version of the LLVM code generator for mjava is specified in mjava.cup.

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

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

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

 

previous                   ToC                next