||This assigment focuses on the implementation of the code generation
of our j0 compiler. We generate assembler code for a simple RISC processor.
An emulator assembles and executes the code. Here is the source code
of the emulator:
A description of the processor was handed out in the lecture. You can find
an instruction summary here.
For your implementation, we provide several supporting classes:
1) Start with generating code for simple arithmetic expressions.
Then proceed with supporting arrays. For this phase you can assume that
there is only one function without parameters containing all the code.
2) Integrate conditional items in order to be able to compile
loops, conditional jumps and shortcut evaluation of
|. Note that the implementation of shortcut evaluation
3) Implement function definitions and function calls. Please
note that the compilation scheme for functions presented in the
lecture leaves out allocation of block-local variables. You have
basically two choices to allocate them:
In J0, the main function has the following signature:
- you traverse the body of the function and find all local
variables before generating code; in this case all variables
are allocated at the beginning of the function and deallocated
at the end.
- variables of a block are allocated on the stack when entering
the block and deallocated when leaving. (beware of implementing
return statement inside of nested blocks correctly)
The J0 compiler has to emit code for calling the
function after setting up the global variables. A J0 program without
main function terminates immediately.