Storage Allocation

Purpose

To implement the data mapping task of the C-- to SPIM compiler:

Due dates

You must complete the PEP tasks (individually), and then hand in the requested material (as a group) at the beginning of class on Monday, November 9. This assignment is worth 40 points.

Background

The calling conventions obeyed by programs running on the SPIM simulator are stated in Section 4 of the SPIM Manual. Remember that the ``parameters'' of a C-- program are not parameters in the sense of these calling conventions, but merely local variables that are initialized by reading from the standard input unit at the start of program execution. Thus the SPIM equivalent of a C-- program has no parameters.

In order to support the calling convention, the SPIM equivalent of a C-- program must contain an instruction that establishes the stack frame by subtracting the frame size from the stack pointer. The frame size must therefore be available in a convenient place for use by the action mapping task.

Section 2.3 of the SPIM Manual describes the available addressing modes. In order to generate an addressing mode appropriate for accessing a variable in the stack frame, the action mapping task must have access to the offset of that variable's storage within the stack frame.

Task

Implement the data mapping task of a compiler that translates C-- to assembly code for the MIPS R2000, using any tools and techniques you wish. Combine your data mapper with the structural analyzer, name analyzer and type analyzer that you implemented for earlier assignments. The resulting program must read input text, construct the corresponding source program tree, and report violations of all context conditions if the text is lexically and syntactically correct. If the input text is incorrect according to the lexical or syntactic rules of C--, your program must report at least the first error. It may terminate immediately after reporting the first error, or it may continue in an attempt to detect further errors.

The data mapping task should store an integer-valued Offset property in the definition table for every parameter and variable defined in the source program. That value is the address of the storage for the parameter or variable relative to the base address of the activation record.

In addition, the data mapping task should store the total size of the activation record as an attribute of the Source node. Your data mapping must take advantage of the limited extent of C-- variables to minimize the size of the activation record.

Verify your implementation by applying it to several programs that illustrate different variable extents, printing the total activation record size and a list of the parameter and variable names in each program with their associated Offset values. Hand in listings of your test programs and the resulting printouts.

A directory containing the complete source code (or specifications, if you used tools) for your compiler must be permitted for world read by 1700 on the due date for this assignment. You need not make it available to be read by others before that time. Hand in the location of this directory (machine and path name).

Complete your personal postmortem for this assignment and your personal project plan for the next assignment, and submit them via the web before class on the due date of this assignment.


Instructor
Revision 1.8 (1998/10/06 15:09:06)