----------------------------------------------------------------------

CSE 401 Fall 1997 (Henry): Compilers

[Home] [Admin] [Details] [Help] [Other]

Assignment #9 (Code Generation and Run time systems)

----------------------------------------------------------------------

Due Monday, December 08, 1997

This is the final project assignment! Its now time to make it all work and come together.

If you have not already done so, read ASU 7.1 through 7.5 on run time environments, data storage, and procedure calling.

Implement Code generation for all the extensions of PL/0

Design and implement the extensions to the PL/0 run time system.

  • There are two distinct calling conventions used in the PL/0 run time system. You will need to understand both of them, so that you can use and extend them as appropriate. I suggest that you examine the assembly code produced by the base pl/0 compiler carefully to understand what the calling conventions are.

    • The internal calling convention is observed when two pl/0 procedures call each other. In this case, parameters are passed on the stack in memory.

    • The external calling convention is observed when a pl/0 procedure calls a procedure compiled by another compiler. This calling convention passes parameters in registers, following the MIPS ABI (Applications Binary Interface). You will need to use this interface (you can not change it) when you call procedures in the Set library, which is written in C++. You can refer to the appendices in the Patterson and Hennessey textbook ("Computer Organization and Design: The Hardware/Software Interface"), or to whatever text book you used when learning about the MIPS architecture and assembly language programming.

    You will have to understand the way that the C++ compiler expects the ``this'' pointer to be passed, and how the compiler mangles names. You'll need this so that the pl/0 compiler can call C++ routines and exactly match the C++ interface.

  • You will have to figure out how you will pass sets as parameters to PL/0 procedures and return sets as values from PL/0 function procedures. I would suggest using a simple call be reference implementation, in which the caller allocates temporary local space for the formal parameters and return value, evaluates the actuals into the temporaries, and passes to the callee the address of temporaries and address of the return value.

  • You will have to figure out how to allocate space, initialize that space, and then use the space needed for expression temporaries that hold pl/0 sets. You'll need to do the same for explicitly declared local variables of type Set. Remember, the C++ Set constructor (Set::Set) must be called immediately after every allocation of a set, and the C++ Set destructor (Set::~Set) must be called immediately prior to deallocating a set.

  • You will have to figure out how much space is needed for local variables. You must ensure that the PL/0 compiler's notion of the size of sets in the MIPS memory is exactly the same as the g++ compiler's notion of the size of the instances of the Set class.

  • You should do a little work to minimize the amount of temporary space needed by the compiler. If you are not careful, a big procedure that uses sets and set expressions is likely to bump up against limits in the way that the local variables are addressed on the MIPS.

  • You will have to figure out how to do range checking at run time, and what kind of action to take when the range check fails.

  • You will have to figure out how to implement the control flow aspects of the switch statement. As discussed in class, there are several different data structures and control structures that you can choose from.

Run the extended compiler using arguments to generate assembly code. Run (and, if necessary, debug) the assembly code on SPIM. Run the test cases you wrote in the beginning of the quarter, plus any additional test cases that your more mature knowledge of the PL/0 language and compiler suggest that you write.

As usual, follow the printing instructions and turnin instructions posted in the Help Section.

Turn in printouts for

  • asm.c and asm.h
  • decl.codegen.c epxr.codegen.c and stmt.codegen.c
  • symtab.codegen.c
  • and any other file that has more than roughly 10 lines of code written by you.

    Turn in your whole working directory electronically, even if you only changed a couple of files.

    Please highlight the changes you make on the paper copy.

    Since this chunk of the project is fairly sizable, please begin early on your design and implementation!

    Sign up for a 20 minute time slot for doing face to face grading in the instructional workstation lab. (We'll pass around a paper sign up sheet in class on Friday Dec 5.) Saurabh and Henry will allocate 4 hours on Monday Dec 8 and Tuesday Dec 9 for face to face grading. You should sign up for a slot that all of your group members can attend. We'll ask you questions about the assignment your approach to solving the major problems, and the hurdles you encountered. We'll ask for a demonstration or two, and will then ask you to compile and run a pl/0 program that we supply. You should have your login session all ready to go at the start of your time slot.

  • ----------------------------------------------------------------------

    401admin@cs.washington.edu (Last modified: 11/14/97)