COOL is the Classroom Object Oriented Language which was created by Professor Alex Aiken for the purpose of teaching compiler design. A complete description can be found in the The COOL Reference Manual.
Several years ago, I took an online version of Prof Aiken's compilers course. The course had a series of challenging projects that, together, formed a functioning compiler. Recently, I wanted to learn Rust. To that end, I decided to implement a COOL compiler entirely in Rust.
In order to build the compiler, you must have the Rust compiler installed. More information is available at https://www.rust-lang.org/. Building the compiler is accomplished in the standard way:
> cargo build
To compile COOL source files (i.e. file1.cl
, file2.cl
)
> ./coolc file1.cl file2.cl
By default, the output assembly file is the name of the first source file with a .s
extension. The output can be set is the -o
option.
> ./coolc file1.cl file2.cl -o output.s
The output of coolc
is MIPS assembly intended to run on the SPIM emulator.
In addition to installing SPIM, you must obtain the COOL trap.handler
file.
To run the assembly file (i.e. name.s
), run
> spim -exception_file trap.handler -file name.s