wlp4cc
Project site for WLP to MIPS compiler
As this project contains course assignment material, due to the University of Waterloo Policy 71 academic freedom rules, the source code will be available by request. Please send me an email with your GitHub account ID.
Source code: Repository URL
Overview
The Waterloo Programming Language v4 (WLP4) is developed for the CS241 course. The language is a subset of C (and so can be compiled with minimum modifications with an off-the-shelf C compiler).
IR and code optimization was not taught during the course and all material below was created on my own volition. This is separate from assignment material.
The program input will undergo a series of steps:
Tokenized
Parsed into a concrete syntax tree (CST)
CST is streamed into our wlp4cc program
The CST is walked and an IR graph is emitted
The IR is represented internally by a graph but can be printed linearly for debugging purposes.
Optimizations are performed (see below)
Initialize control flow graph (CFG)
Convert to SSA form
Perform constant folding + copy propagation
Perform dead code elimination (DCE)
Remote PHI nodes
IR is lowered into machine code (MC) and placed through the backend
The following snippet of the compiler is shown below. This is not critical in solving the assignment (so hopefully not a Policy 71 violation) but details the extra optimization steps implemented:
Example Program
Consider the following input program:
We will present the IR at each optimization step, in graphical form.
The final IR emitted looks like:
Some notes about the IR:
Syntax is similar to LLVM IR
Each operation is
OP x y
wherex
andy
are registersNegative register numbers indicate parameter values
Labels are prefixed with
.
Last updated