

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


CS322 Winter’09: Languages and Compiler Design II 2/12/ Prof. Jingke Li (FAB 120-06, [email protected]), Classes: TTh 2-3:50pm, URBAN 304, Office Hours: TTh 10-11am.
This project is to implement an interpreter for the IR tree language. The interpreter is to be implemented as a self-contained Java class (i.e. not as a visitor), Interp, with the following interface:
public Interp(PROG p) {...} --- the constructor takes an IR program as input public void go() {...} --- the main trigger for interpreting the IR program
Storage Model
The interpreter organizes data in three storage categories: temps, stack, and heap. To allow an uniform access pattern, they are all mapped to a single integer array called mem.
Interpreting Statements
The core of the interpreter is a while loop executing the statements of a FUNC node.
Interpreting Expressions
Every expression is evaluated to an integer value.
More on the Handling of CALL/CALLST Nodes
For each method invocation, a frame is allocated on the stack, and the frame pointer is switched to point to the new frame; when a method returns, the reverse actions are performed.
void interpFunc(String fname) throws Exception { ... // f =
void handleCall(String fname) { ... mem[sp] = fp; fp = sp; interpFunc(fname); sp = fp; fp = mem[sp]; ... }