Back End


This assumes that you have a compiler that generates intermediate code: either your own or mine. I will assume that you are compiling for the SPARC.

Canon

The task is really easy. Copy the Canon package to your compiler and modify your main method as follows:
// For each procFrag, do the following:
   Tree.StmList stl = Canon.Canon.linearize(procFrag.body); 
   Canon.BasicBlocks bbs = new Canon.BasicBlocks (stl);
   Canon.TraceSchedule ts = new Canon.TraceSchedule(bbs);
This sequence of calls applies some transformations to your intermediate code to make it more "assembly-like". Read Chapter 8 for the details of these transformations. You should be able to get your compiler to print canonical trees with a minimal effort. Even better, print the canonical trees to a file in preparation to assembly code generation.

Instruction Selection

There is little I can add to what the book describes. Just implement the maximal munch algorithm in Chapter 9.

Registers

You certainly shouldn't try to do the graph coloring register allocator described in Chapters 10 and 11. Use the simplest possible idea that comes to mind. Chapters 9 and 12 have some discussion about register allocation. The Dragon book has a couple of simple algorithms for register allocation that don't require a major data flow analysis. Page visited times since September 14, 1998.

sabry@cs.uoregon.edu