Note: Homeworks 4 and 5 are due on the same date—that is, they are handed in together. (This is because it is hard to debug the frame analyser without having the IR generator, its downstream client, to exercise it.) Since the IR generator's official start date is 10/20, you should set 10/20 as an internal deadline for having your frame analyser finished. The IR generator is a very ambitious piece of code, one of the two or three hardest modules in the entire compiler.
Homework 4 is to read Chapter 6 of the text and build a frame analyzer for Appel's Tiger language.
Your code should take an AST and:
You should implement a MipsFrame
structure satisfying
the FRAME
signature as discussed in Chapter 6 of the
course text. Note that this is not the final version of the
FRAME
interface; we'll be extending the
FRAME
signature in the future. For a complete
description of the signature, see program 12.1, which is on page
260 of my edition of the textbook. (This may explain why you may
be hunting in vain through Chapter 6 and $TIGER/chap6 for
the signature...)
You will need to augment your existing Semant
and
Env
structures as well as implement at least three
other structures: FindEscape
(escape analysis),
MipsFrame
(managing stack frames), and
Translate
(managing lexical nesting).
You are required to allocate "temps" (abstract registers) for non-escaping variables; they should not go in the stack frame. You are not required to handle more than four procedure parameters. That is, you can assume all parameters are passed in the registers. You are encouraged, however, to handle more than four. (It's not much harder.)
You should submit the following files:
MipsFrame
structureFindEscape
structureTranslate
structureSemant
structureWord to the wise: The tricky part of this project is working with the "static link" pointers in the frames to access non-local variables that occur in outer scopes. This requires small amounts of code but non-trivial amounts of thought.
Last updated 18 February 2008.