Programming Assignment 6
Due Thursday, April 24

Introduction

In this assignment you will start to implement code generation for Cool. You will prepare the data segment with prototype objects, dispatch tables, and constant objects (strings, integers and booleans). The real code generation part of the Cool compiler remains for PA7.

Files and Directories

To get the assignment type

make -f /afs/cs/users/classes/cs654/assignments/PA6/Makefile
in the PA6 directory of your AFS volume. This command copies a number of files to your directory, some of them with read-only permission. As usual, you should not modify files that are read-only. Please read and follow the directions in the README file.

The files that you may need to modify are:

There will be many other files in your directory containing other pieces of the compiler. These files were described in previous handouts and are listed in the README file. The files we will collect and use to grade your assignment are the first set listed above; you should not modify any other files.

Interface to the Semantic Analyzer

In the previous assignments, you implemented the semantic analyzer, finding errors and setting attributes needed by the code generator. Your code generator will only be invoked if the semantic analyzer finds no errors. In this case, the following table shows what attributes the semantic analyzer has set for you. This is the same table you saw in PA4 and PA5, but this time it represents things you can use, not things you must define.

constructor or phylum attribute meaning
program obj_class AST for class Object
  int_class AST for class Integer
  str_class AST for class String
  bool_class AST for class Boolean
class super AST for super class (or NULL for Object)
method overrides AST of method being overridden (or NULL)
  return_of_class AST for class of return type
attr of_class AST for class of type
formal of_class AST for class of type
branch of_class AST for class of type of branch variable
  type symbol for type of value of expression in branch
Expression type symbol for type of value of expression (or NoType)
let of_class AST for class of type of let variable
object binding description of variable being used
assign binding description of variable being assigned
dispatch method AST for (statically selected) method
static_dispatch method AST for method selected
new_ of_class AST for class being instantiated.

The Assembly Language File

The assembly language file, when everything is done, has the following structure:

We hope this description will be a useful ``road-map'' for you as you examine the assembly language files produced by the Cool compiler.

Designing and Testing the Partial Code Generator

You will need a working lexer, parser, and semantic analyzer to test your code generator. See the README file for instructions on how to use either your own components or the components from coolc. It is wise to test your code generator with the coolc lexer, parser, and semantic analyzer at least once, because we will grade your code generator using coolc's version.

See the README file for instructions for compiling and running a compiler with your code generator. Essentially you use mycoolc6 to run your partial code generator. You will need to make sure you assign the exact same offsets, class tags, string and integer constant indices as the installed code generator. You probably should use diff to compare the output of your (partial) code generator to the installed version.

For your convenience, a command line debugging flag -c is included in the skeleton, which controls the global variable cgen_debug. Use this to control whether to print verbose output.

The file you start with has many functions in it that you will not use this assignment. You will need to use your solution to PA6 in order to do PA7, so do not delete these functions. The file also includes extra code needed for memory management even if you don't use garbage collection. Do not make any changes in this part of the code generator.

Overview

The basic stages of the code generator for this assignment are as follows:

  1. Generate class name table, and constant objects for program literals (strings, integers and booleans).
  2. Determine class tags for classes, method offsets for methods and attribute offsets for attributes.
  3. Generate the prototype object and the dispatch table for each class.
Your test case example.cl should test these aspects of the code generation: the computation of class tags and feature offsets, and the generation of the class name table, literal objects, dispatch tables and prototype objects.



John Tang Boyland 2008-04-10