Tiger frontend compiler for C--

Paul Govereau
2007/01/29

Introduction

This document describes the source code for a Tiger language front end to the Quick C-- compiler. The Tiger language is described in "Modern Compiler Implementation in ML"[cite appel]. To quote from Appendix A of this book:
The Tiger language is a small language with nested functions, record values with implicit pointers, arrays, integer and string variables, and a few simple structured control constructs.
In addition, we have added exceptions to the basic Tiger language. Full source code and documentation can be found at the C-- website, or in the Quick C-- CVS repository under frontends/tiger.

Guide to the Source Code

The sources are dived into several modules, each of which is described below. Figure [->] shows the dependencies between the major modules in the compiler.
[PostScript figure tiger.eps] Module Dependencies [*]

Abstract Syntax
The abstract syntax for Tiger programs is described in the Ast module. Symbols and tables of symbols are implemented in a companion module Symbol. As usual, Tiger source programs are converted into abstract syntax by the parser. The abstract syntax is then used by the rest of the compiler as the representation of programs.

symbol.nwSymbols and symbol tables.
ast.nwAbstract Syntax Trees.

Analysis
The analysis phase verifies that the abstract syntax tree represents a semanticly correct program. This process includes type checking and verifying that expressions are used in a proper context (e.g. a break can only occur within a loop). The semantic analysis uses an environment to keep track of type definitions, variable bindings and other information. The environment is implemented in the Environment module, and the analysis is implemented in the Semantics module.

environment.nwEnvironments.
semantics.nwSemantic analysis.

Translation
The Translate module translates an abstract syntax tree into the intermediate representation used by the rest of the compiler. The intermediate representation is defined in the Tree module.

tree.nwThe intermediate representation.
translate.nwTranslates ASTs to intermediate representation.

Code Generation
The code generator translates the intermediate representation into a C-- program. Each Tiger function is translated into a C-- function by the Tiger compiler. The stack frame for each function is managed by the Frame module. The Codegen module outputs C-- programs from the intermediate representation and information contained in the Frame module.

frame.nwStack frames.
codegen.nwGenerates C-- code.

Tiger Runtime System
Compiled tiger programs must be linked with the tiger runtime system to create a complete program. The runtime system contains the startup code, a simple copying garbage collector, and a library of standard functions.

gc.nwGarbage collector.
stdlib.nwTiger standard library functions.
runtime.nwStartup code.

Other Modules
The Tiger compiler also contains several support modules. These modules are listed below---the complete sources can be found in the appendices.

driver.nwThe compiler driver.
error.nwError reporting.
option.nwCommand line options.
parser.nwParser and scanner.
canonical.nwLinearizes expression trees.