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.
cd [srcdir]/gcc-4.2.4/gcc/treelangSo, here are the steps to building gcc from source on your system (either linux or MacOS):
cd [srcdir]/gcc-4.2.4/gcc/treelangSo, 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 make # 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/mygccHere 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 add { // 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.treeThis 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.treedumps the intermedite tree represenation of the program in C like notation to your terminal.
mygcc -S -dP add.treedumps 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:
http://en.wikipedia.org/wiki/Treelang
and this is probably the most important document because it describes what each of the files in the treelang folder does:
http://stderr.org/doc/treelang-4.1-doc/treelang.html
[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!
Date Sections Topic Presenter ---- -------- ----- --------- 1/30 Chap 1 Overview Greg 2/6 Sec. 2.1,2.2,2.5 Scanners Deborah 2/13 Sec. 3.1-3.4 Parsing Brandon 2/20 lex/yacc & GCC Frontend HOWTO GCC things Nick 2/27 Sec. 4.1-4.3 Analysis & Types Greg 3/6 no presentation/QA 3/13 spring break 3/20 Sec. 5.1-5.3,5,5 IR & Symbol Tables Deborah 3/27 Sec. 6.1-6.5 (except 6.3) Function Calls Nick 4/3 Sec. 11.1-11.5 Code Generation Brandon 4/10 The GCC .md file Code Gen. w/ GCC Deborah 4/17 Sec. 13.1-13.4 Register Allocation Greg 4/24 Sec. 8.1-8.5 Intro to Optimization Brandon 5/1* Sec. 9.1,9.2,10.1,10.2 Data Flow Analysis & Nick Optimization