André Rösti

Class Project

SMPL Compiler

As a project in Prof. Dr. Michael Franz's Advanced Compiler Construction class at the University of California, Irvine, I created this optimizing compiler for a simple programming language. It includes a backend for the DLX instruction set architecture with a very simple register allocator, and performs constant elimination, common subexpression elimination, and dead code elimination.

Sample Program and Compiler-Generated IR and AST

main
var i, j, k, out;
{
	let i <- 0;
	let k <- 2;
	let out <- 1;
	while i < 20 do
	let out <- out * 2;
	let j <- 0;
	while j < 10 do
		let out <- out + j;
		let j <- j + 1;
	od;
	let i <- i + 1;
	let k <- 3;
	od;
	let out <- out + k;
	call outputNum(out);
}.

A sample program in the SMPL programming language.

DOT graph of intermediate representation

Besides producing binaries, the compiler can also output GraphViz .dot files. This is the generated graphical representation of the intermediate representation (IR) of the above/left program. The blue lines note dominating basic blocks, used for optimization. (Click for larger graphic.)

DOT graph of AST

The abstract syntax tree can also be output. This is the graph output for the above program. (Click for larger graphic.)