public class SparcFrame extends Frame.Frame { private static int WORD_SIZE = 4; // Offset at which formal arguments should be stored. The first // argument goes at offset 68, the second at 68+WORD_SIZE, and so on. private static int FORMAL_AREA = 68; // Offsets at which local variables should be stored. The first // local variable goes at offset -4, the second at offset -4-WORD_SIZE, // and so on. private static int LOCALS_AREA = -4; // The method newFrame should just call the constructor public Frame.Frame newFrame (Label name, Util.BoolList formals) { return new SparcFrame (name, formals); } // The constructor should initialize the instance variables: // Label name, and // Frame.AccessList formals // When creating a SparcFrame, we are given a list describing the // formals arguments. A "true" says that the formal variable must // go in the stack frame (use an InFrame access); a "false" says that // the formal variable may go in a register (use an InReg access). public SparcFrame (Label name, Util.BoolList formals) { ... } // The next method allocates space for a local variable. As described // above, a "true" means that the variable must be allocated in the // frame and a "false" means that the variable may go in a register. // See pp.143-144. public Frame.Access allocLocal (boolean escape) { ... } }
package Translate; public class Access { Level home; Frame.Access acc; Access (Level home, Frame.Access acc) { this.home = home; this.acc = acc; } }
... // create a new frame with no formals for the top level Frame.Frame frame = new Sparc.SparcFrame(new Temp.Label("main"), null); // use above frame to create the top level. This is the level // in which the library functions are declared. The Tiger // program itself will be defined in a level that is nested // within the top level one. Translate.Level outermost = new Translate.Level(frame); // create and call the semantic analysis module Semant analyze = new Semant(errorMsg, outermost); analyze.transProg(absyn); if (errorMsg.anyErrors) throw new Error("Type Error"); ...
sabry@cs.uoregon.edu