MC97 Lab 5: Escape analysis (Spring 1999)

Due: April 14, 1999

For this lab, you will not need any code from lab 4. Instead, you will need to build on your work in labs 2 and 3. However, if you don't have working versions of that code, you can instead use the compiled class files that I provided for your use in lab 4. Recall that in lab 3, the main program (from chap4) called your parser to generate an abstract syntax tree from the source file and then used Absyn.Print to print the tree out. That tree had every variable declaration and field list element (as in the parameters of a function) marked with "true" for the escape flag, since the conservative assumption is made that they all might escape. In this lab, you are to change the main program from chap4 so that it invokes an escape analysis module (which you are to write) on the abstract syntax tree, between its generation by your parser and its printing by Absyn.Print. Appel provides some guidance in chapter 6 for how the escape analysis can be done. Be sure to test thoroughly. For example, you should probably have the escaping uses of your variables appear in a variety of different expression types, and at least two different depths relative to the variable (or parameter) declaration. You should also test that scoping works correctly, in that if a variable, x, is declared in an outer function, declared again in an inner function, and used in the same inner function, the outer x should not be marked as escaping.

Instructor: Max Hailperin