Module 6:
A Code Generator for Klein
Stage 6 of the Klein compiler project
Out: Friday, November 14
Due: Friday, December 5, at 11:59 PM
STATUS CHECK DUE: Friday, November 21
Tasks
Introduction
This stage consists of a complete implementation of the fourth component of your Klein compiler and two auxiliary programs.
1. A Code Generator
Your primary task is:
Extend your code generator so that it produces executable TM assembly language for any semantically-valid Klein program.
As defined in Module 5, a code generator is a function or object that takes as input:
- the abstract syntax tree of a semantically-correct Klein program, and
- its associated symbol table.
and produces as output an equivalent TM program. In combination with the first five stages of the project, you will now have a complete compiler for Klein.
The code produced by your code generator should run in the TM simulator as configured in the download. If you would like to run experiments with other configurations, say, a larger data memory or instruction memory, be sure to document your experiments and corresponding changes to the configuration of TM prominently in your README file.
Producing an Incomplete Implementation
The goal of this project is to write a code generator for the entire Klein programming language. If you are unable to implement a generator for the entire language, then your team should make deliberate choices about which elements of the language to include and omit.
- Be sure to document any omissions and other design decisions prominently in your README file.
- Have your code generator print suitable warning and error messages for language features not supported by the compiler.
Your code generator should work correctly and gracefully, even if only for a subset of the language.
2. A New Klein Program
In order to test your now-complete compiler,
Your test program should be at least at the level of a late CS1 program, minus the data structures. Feel free to write a more advanced program, say, a solution to a Project Euler problem. You certainly understand Klein well enough by this time to perform some interesting computations.
If you still aren't sure what program you might write, see if any of the problems in this list interest you. They are rather simple, but they may jog your creativity. I will add a couple of new ideas in the coming days. Feel free to discuss possibilities with me.
You should, of course, produce as many tests as necessary in order to ensure that your code generator works correctly. You are also encouraged to use any test programs available on the project home page.
3. The kleinc Command
Finally,
Modify your kleinc Unix command-line script,
if necessary, to take the name of a Klein program as an
argument, run your complete compiler on it, and produce as
output a TM program of the same name.
For example,
$ ls euclid.kln $ kleinc euclid.kln $ ls euclid.kln euclid.tm
kleinc should run your scanner, parser, semantic
checker, and code generator on the given Klein program.
kleinc should catch all errors generated by the
scanner, parser, and semantic checker. If any previous stage
signals an error, kleinc should display those
error messages and abort. However, if there are semantic
warnings but no errors, the code generator should produce a
TM file as expected.
This is the fifth in a series of tools that makes up the command-line suite of your Klein compiler.
Extra Credit Opportunity
Implement kleinc so that the .kln
extension is optional. If we call kleinc with
a filename that does not contain the .kln
extension, such as euclid, it will look for
a file named euclid.kln before proceeding.
Note: This extra credit is available only if you did not earn credit for it on Module 5.
Deliverables
As before, submit only one copy of each assignment per team. The team captain or a designated team member can be responsible for the submission.
Status Check
In order to stay on track, you will want to be adding new
Klein features to the code generator regularly over the
course of the next two weeks. Identify or create
two Klein programs beyond print-one.kln
that your code generator handles correctly by the end of the
first week.
Submit:
-
the
*.tmfiles generated by your code generator for these programs -
the
*.klnfiles, too, if they are not in the Klein collection available from the project web page
Final Deliverable
By the due time and date, use
the course submission system
to submit
your project directory
electronically as a zip file named project06.zip
or project06.tar.gz.
A Refresher on the TM Simulator
For details on downloading the TM virtual machine, see Module 5's description. At this point in the project, I hope you already did this long ago!