CSC502 - Theory of Compilers

Spring 2013


Dr. Lutz Hamel
Tyler, Rm 251
Office Hours: TBA


This course is an advanced compiler design course. We will be studying the GCC compiler tool suite and architecture. GCC is a state-of-the-art compiler and tool suite -- the gcc C-compiler is used to compile the Linux system. A version of gcc is also used in Mac OSX Darwin.

You will learn how to write advanced compiler front-ends. You will also learn how to take advantage of the tool suite to generate code.

This is a project-based class, we will meet once a week to for a student led presentation and discuss projects/problems/progress etc.


[4/11/13] Posted project 2 description, see below.
[3/21/13] Posted the simple grammar. Simple has a semantics similar to C and Java. Please implment this language using gcc. You will need to rewrite the grammar for YACC/Bison. Implement this language and demonstrate that you compiler works with a couple of telling examples. The project is due April 3rd.
[3/1/13] ** IMPORTANT ** please ignore all the build tutorials I posted, they are incorrect. In order to build a gcc version that we can use for our development follow the steps outlined below. I assume that you installed the source tree for gcc-4.2.4 in [srcdir] where [srcdir] is an absolute path from root. That means to find the front end for the tree language you would have to do:
cd [srcdir]/gcc-4.2.4/gcc/treelang
So, here are the steps to building gcc from source on your system (either linux or MacOS):
cd [srcdir]/gcc-4.2.4/gcc/treelang
So, here are the steps to building gcc from source on your system (either linux or MacOS):
# assuming that the source tree gcc-4.2.4 is in folder [srcdir]
cd [srcdir]

# make a directory that will hold our compiled code
mkdir obj

# make a directory that will hold our installed compiler 
# NOTE: you don't want to install it in the default locations because
#       you don't want this compiler to be confused with your actual system compiler
mkdir install

# go to the obj folder to start the build process
cd obj

# configuring the make file
# - no bootstrap necessary -- we will not use this compiler for anything critical
# - only enable treelang, this will build the C compiler and the tree compiler, no need
#      to build anyhting else
../gcc-4.2.4/configure --disable-bootstrap --enable-languages=treelang

# start the make (keep your fingers crossed) - on my machine that takes about 5mins

# move the compiler to the install folder
make DESTDIR=[srcdir]/install install

# now create a link so you can execute your new compiler
# NOTE: make sure that /usr/local/bin is in your path
# NOTE: once you have done this you can execute your new compiler by typing mygcc
sudo ln -s [srcdir]/install/usr/local/bin/gcc /usr/local/bin/mygcc
Here is a very simple tree program:
     // function prototypes
     // function 'add' taking two ints and returning an int
     external_definition int add(int arg1, int arg2);
     external_definition int subtract(int arg3, int arg4);
     external_definition int first_nonzero(int arg5, int arg6);
     external_definition int double_plus_one(int arg7);
     // function definition
       // return the sum of arg1 and arg2
       return arg1 + arg2;
assume that you stored this in your home folder as file add.tree, then you can now compile this function using your new compiler:
mygcc -S add.tree
This will produce a file add.s containing the assembly code. There are a number of interesting options you might want to try:
mygcc -S -fdump-tree-original=stderr add.tree
dumps the intermedite tree represenation of the program in C like notation to your terminal.
mygcc -S -dP add.tree
dumps the RTL intermediate representation as comments to the assembly file.

[2/28/13] I finally unraveled the mystery why there are no example languages/front ends with the 4.6/4.7 gcc compiler...they took them out.

This means you will have to down grade to 4.2.3 (this is the version I have) in order to get a toy front end that you can play with/use as a template to build your own language.

Incidentally, this is also the gcc version that apple uses in snow leopard...

So, here is what you need to do:

You can find documentqtion of treelang on wikipedia:

and this is probably the most important document because it describes what each of the files in the treelang folder does:

[2/20/13] Here is the definition of a scripting language parser you can use for the simple frontend for next weeks implementation.
[2/13/13] Posted presentation schedule...please take a look and make sure it is correct.
[2/6/13] I have posted the presentation schedule (see below). At the end of the semester each one should have presented three times. Next time we will do conflict resolution on the topics and make sure everybody winds up with topics they want to present. For this please pick your favorite topics and backup topics in case you cannot get your favorites. Please note that the last presentation slot is on a reading day if this is inconvenient then we can double up on a previous slot. We can discuss this next time. The final project will be due on Friday May 10th @ noon in my office (more on that later).
[1/23/13] The Sakai discussion board is up and running...please use it to ask questions, make comments etc. rather than sending me email. It is the preferred way to communicate. I will look at it at least once a day. If you happen to know the answer to a particular question then please chime in. The discussion group is a cooperative effort.
[1/23/13] Read Chapter 1, Gregory will give a presentation on it. Please hand in one type written question on the material.
[1/23/13] Posted pointers to lecture slides written by Keith Cooper, one of the authors of our book. See below.
[1/16/13] Welcome!

Documents of Interest: