CS 451 - 651 Homework assignment 11 and 12
This builds on the material we've been working on, and requires hw
9 be working.
This
group
of
assignments leads up to the final project effort for the
term. It is staged, with a little overlap, to give you
flexibility in how you approach it.
-
hw 11&12 assigned Wednesday Nov 18; first
portion [#11] due Monday, Nov 23; full project [#12], due Monday,
Nov 30;
-
there may be a [small] additional implementation, some feature
of your choice, due Dec 7;
-
Absolute last day for
project submission: 7:00 pm Thurs Dec 10 (after last day
of class)
Homework 11: Function definition, call, return - phase 1
For this phase, you'll implement enough to get simple functions
working. This will include
- function definition (declaration)
- return statement
- function call statement (and expression)
You should be able to build, emit, and execute simple
functions. Something simple will be fine:
{ print 111; void apple(){print 222; return;}; print 333; apple(); print 444;}
(the print's are there to help you see that things are happening in the
right order!)
See Wednesday's
lecture notes (augmented) for more details.
Simplifications
-- things which you not need for this assignment:
- no arguments
- no name scopes (avoid using variables inside the function for now)
- function cannot call another function
- don't need to have a return value yet.
- no prolog or epilog required
We will always insist that
functions must be defined before they can be called, just as a
variable must be declared before its use.
Homework 12: Functions with local variables, args, value -
phase 2
Get the rest of the basic function implementation working: fill
in all the things in the bullet list above that we left out in phase
1. Here's a bit more detail which might be helpful.
- Add name scopes (we'll discuss this in class on Monday) and
allocate local variables to the function's stack frame
- Generate a prolog and epilog (see notes on stack linkage)
- Provide analyze() functions for the node types added for functions
- Support returning a scalar value (if you can, check that
its type is the same as declared in the function definition!)
- Support passing an argument. At least: one argument, can
pass it in rVal register, and store into "local variable" in prolog.
Simplifications:
- Uplevel addressing is not supported
- Array arguments are not supported
- Not necessary to save registers around a function call.
(This may produce some slight problems with recursive functions)