CS453 Intro and PA1 1CS453 Lecture MiniJava Compiler - Frame class 1Plan for Today PA6: Stack frame (Variable placement)– testing and grading– the Frame class– the ClassSTE class– the MethodSTE class– the Temp packageCS453 Lecture MiniJava Compiler - Frame class 2Structure of the MiniJava Compiler“sentences”Synthesisinstruction selectionIR code generationTreeAnalysischaracter streamlexical analysis“words”tokenssemantic analysissyntactic analysisASTAST and symbol tablecode generationMIPSPA2PA3 and PA4PA5 and PA6PA7PA8PA8Assem/MIPSoptimizationCS453 Lecture MiniJava Compiler - Frame class 3Frame class implements Factory design patternFrameFrame newFrame()MipsFrameFrame newFrame()MipsFrameCS453 Lecture MiniJava Compiler - Frame class 4What, why, and where? What?– one instance of the MipsFrame will generate other instances Why?– need a Frame instance for each function and want to avoid calling theMipsFrame constructor everywhere Where?// FrameLayout.java! Frame.Frame frame = new Mips.MipsFrame();! BuildSymTable buildSTvisitor = new BuildSymTable(linesToNodes, frame);! // BuildSymTable::inAMethodDecl...Frame.Frame methodFrame = mFrame.newFrame(! new Temp.Label(mCurrentClass.getName()+"$"+node.getName().getText()), formalEscapeList);CS453 Intro and PA1 2CS453 Lecture MiniJava Compiler - Frame class 5Interface to Frame Three main responsibilities– provide a factory interface for generating machine-specific frames– Frame newFrame(Label name, List<Boolean> formals)– answer queries that are machine-specific, but not method specific– int wordSize()– Temp FP(), coming to an interface near you in PA7– store method-specific information about frame layout– Label name– List<Access> formals– Access allocLocal(boolean escape) Access classpublic abstract class Access {! public abstract String toString();! ! //public abstract Tree.Exp exp(Tree.Exp e);!}!CS453 Lecture MiniJava Compiler - Frame class 6When do parameters and/or locals escape? Nesting of classes and methods When the variable may have its address taken When the language uses pass-by-referenceint foo(int x){ int baz(int y) { return x+y; } int bar() { return baz(2); } return bar();}int main() { printf(“%f\n”, foo(3));}int addressFunc(int x){ int z; return blah(&x, &z);}FORTRANsubroutinefoo(x,y)double precision xdouble precision yy=x*2end subroutinesubroutine head()double precision a, bcall foo(a,b)end
View Full Document