Compilers (CSC-362 98F)


Final Project

Due: 5 pm., Friday, December 11, 1998

Assignment

Your assignment is to develop a compiler from Tiger (as specified in one of Appel's Tiger books) to a ``straight-line intermediate-representation code'' (hereafter referred to as IRT) which is described in the next section. IRT is a simplified assembly code, which is quite similar to the intermediate representation trees given in the Appel book.

In order to complete the translation, your program should:

You will then interpret the textual instructions using an IRT interpreter that I will write (in Perl, for portability).

It is not clear when all of the helpers will be ready, so you should be prepared to go ahead using only ``stubs'' for the various parts. I will definitely have the various things ready Monday after Thanksgiving.

You need not implement the built-in functions.

Architecture

Code Format

A few forms of memory locations are accepted:

The valid commands are:

Registers

Calling Conventions

The CALL instruction copies all of the values to the appropriate registers and then branches to the appropriate label. It is the callee's responsibility to move values from those registers to other registers or to locations in memory. (The code given by IRTFrame will handle the parameters, but not the return address.)

If your functions call other functions, you will need to handle the code for storing values in possibly-changed registers within the current frame. The IRTFrame module will provide an inRegisters method that lists all registers used within the module.

Built-in Functions

You can call any of the built-in functions given as part of the Tiger standard library by using the name given in the Tiger language description. In addition to the given functions, there is also a printInt function for printing integers.

Sample IRT Programs

Here is a program that multiplies two and three and prints the result.

BINOP MUL 2 3
BUILTIN printInt ACC
END

Here is a program that that prints the string "Hello".

BUILTIN print L(L123)
END
LABEL L123
STRING Hello

Here is a program that reads two characters and prints the one with the larger ordinal value.

BUILTIN getchar
MOVE R(21) RV
BUILTIN ord R(21)
MOVE R(22) RV
BUILTIN getchar
MOVE R(23) RV
BUILTIN ord R(23)
MOVE R(24) RV
CJUMP GT R(22) R(24) L101
LABEL L100
BUILTIN print R23
JUMP 1 L102
LABEL L101
BUILTIN print R21
LABEL L102
END

Here is a program fragment that multiplies the contents of register 22 by 3

BINOP MUL R(22) 3
BUILTIN printInt ACC
END

Here is a program the prints numbers from 1 to ???

# Loop forever, printing numbers from 1 to maxint
BINOP PLUS 0 1
LABEL loop
BUILTIN printInt ACC
BUILTIN print L(cr)
BINOP PLUS 1 ACC
JUMP L(loop)
END
LABEL cr
STRING \n

More programs forthcoming.

Sample Tiger Programs

Forthcoming. Please send me some of your own suggestions.

Extra Credit

You can obtain extra credit by doing any or all of the following:


History


Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

Source text last modified Fri Dec 11 10:09:08 1998.

This page generated on Fri Dec 11 10:11:28 1998 by SiteWeaver.

Contact our webmaster at rebelsky@math.grin.edu