PROGRAM MAKING IT WORK
Make your compiler generate working code that runs. The file $MINIJAVA/chap12/runtime.c is a C-language file containing several external functions useful to your MiniJava program. These are generally reached by externalCall from code generated by your compiler. You may modify this as necessary. Write a module Main that calls on all the other modules to produce an assembly language file prog.s for each input program prog.java. This assembly language program should be assembled (producing prog.o) and linked with runtime.o to produce an executable file.
Programming projects
After your MiniJava compiler is done, here are some ideas for further work:
- 12.1 Write a garbage collector (in C) for your MiniJava compiler. You will need to make some modifications to the compiler itself to add descriptors to records and stack frames (see ).
- 12.2 Implement inner classes is MiniJava.
- 12.3 Implement dataflow analyses such as reaching definitions and available expressions and use them to implement some of the optimizations discussed in .
- 12.4 Image out other approaches to improving the assembly language generated by your compiler. Discuss; perhaps implement.
- 12.5 Implement instruction scheduling to fill branch-delay and load-delay slots in the assembly language (for a machine such as the Sparc). Or discuss how such a module could be integrated into the existing compiler; what interfaces would have to change, and in what ways?
- 12.6 Implement "software pipelining" (instruction scheduling around loop iterations) in your compiler (see ).
- 12.7 Analyze how adequate the MiniJava language itself would be for writing a compiler. What are the smallest possible additions/changes that would make it a much more useful language?
- 12.8 In the MiniJava language, some object types are recursive and must be implemented as pointers; that is, a value of that type might contain a pointer to another value of the same type (directly or indirectly). But some object types are not recursive, so they could be implemented without pointers. Modify your compiler to take advantage of this by keeping nonrecursive records in the stack frame instead of on the heap.
- 12.9 Similarly, some arrays have bounds that are known at compile time, are not recursive, and are not assigned to other array variables. Modify your compiler so that these arrays are implemented right in the stack frame.
- 12.10 Implement inline expansion of functions (see ).
- 12.11 Suppose an ordinary MiniJava program were to run on a parallel machine (a multiprocessor)? How could the compiler automatically make a parallel program out of the original sequential one? Research the approaches.