Intermediate Code Generation

In this last part of the project, we are adding one more part to the puzzle! In that part, your compiler is actually generating code.

Intermediate Code Generation

In that part you are required to generate three-address code, represented as quadruples (as specified in the Dragon book). 

Your output must be in file a.txt 

The three-address code language consists of items of the following forms:

x := y binop z where binop is one of: +, -, *, /, and, or

x := unop y where unop is one of: -, not

x := y

L: where L is a label

goto L

if x relop y goto L where relop is one of <,<=,=,>=,>,<>

param x precedes call operation, passing a parameter.  
NOTE: these operations
should be issued in left-to-right order.

call p procedure call, no return value

x := funcall f function call, x is assigned the value returned by f

return procedure return

funreturn x function return, returning x

x := y[i] In this case, y[i] refers to the ith element of array y, and is independent

of the size of the elements. Assembly-code generation,

will convert this to a size-dependent array reference.

x[i] := y

x := y.b This is a reference to the b field of record y. Note that the b field of y may

itself be a record, in which case x.c might appear subsequently in the

code. Similarly, if y.b is an array, x[i] can appear subsequently.

x.z := y

Note that each of the variables x, y, and z, can correspond to either variables in the

source program (in particular, local variables of a procedure, formal parameters of a

procedure, or global variables in the program), or temporary variables created by the

intermediate code generator.

We will be testing that part with an error free program., and our test programs will not require more than the above three-address codes.

What you have to submit

Submission rules

  1. The lab submission must be sent as an attachment to an email sent to the TA.
  2. Subject: of the email must be Compiler-codegen-lastname-firstname, lastname is your last name in lower case and firstname is your first name in lower case.
  3.  Put all your submission files in a directory called "codegen-lastname-firstname"  then tar/zip the whole directory.
  4. Send the tar/zip file as an attachement to the email.