Page #18 (Chapter 14 The Object Module)

Previous Table of Contents Next


Chapter 15
Completion and Futures

We have reached the end of all of the technology. The proof of piecing this technology together will come in building a compiler using it. Together with teams I have worked with, I have used most of these techniques. I myself (with anyone interested in participating) will implement the design. Of course, I invite you to do the same.

How will I build a compiler? I will build it out of technology that is freely available. I have no desire to rebuild something that has a reasonable implementation already. This section will discuss what I plan to build and how I will build it.

15.1 Target Machine

First, for what processor should I build a compiler? The INTEL-based processors have a host of reasonable compilers, and each of the UNIX vendors have built reasonable compilers for their RISC chips. As you probably noted, I have a fondness for the Alpha processor, but there are a number of good compilers for it. I will build a compiler with two targets: a fake RISC processor useful for testing and verification of the compiler, and the ARM or StrongARM processor used in real-time systems.

The fake RISC processor will be used for initial testing. It is based on an idea that I have seen used by both Rice University and Bill Waite at University of Colorado. The idea is to define a RISC processor where each instruction can be described as a C macro. Consider the iADD instruction for integer add operations. It can be defined by the macro

#define iADD(S1,S2,T) T=S1+S2

where there are global variables defined to represent each of the registers in the register set. All of the characteristics of the machine can be simulated in C. What is the advantage? The compiler can run and generate assembly language for the program. The program can be executed on any reasonable processor. Each instruction in the assembly language can be simulated in this way.

In fact, additional expressions can be added to the definitions to measure the characteristics of the program. For example, a counter can be incremented in the macro simulating a branch operation. Thus we can know how many times all of the branches are executed or, even more specially, how often a particular branch is executed.

The StrongARM processor was chosen as the real machine to compile for because there are inadequate optimizing compilers for that processor. I find no joy in building a compiler that will always be worse than a compiler that already exists, so I am choosing a processor with less support. Thus I have a chance of building a compiler that might be useful.

15.2 Host Machine

What machine should I use to host this project? I prefer a good-size PC with one of the excellent C/C++ program environments: Visual C/C++, Borland C/C++, or Symantec C/C++. These environments make it easy to write small sections of code and check-debug them. The support for UNIX facilities like make are less adequate; however, there are some facilities for configuration and project management.

UNIX would be a second choice. In that case, I would use an editor such as GNU EMACS as a programming environment in which to embed all other activity.

15.3 Source Language

I want to write a compiler for a full language, not a toy, and I do not want to write a front end. Thus I will compile for the C language and use one of the freely available C front ends as the starting point. In this case, I will use LCC, created by Frazer and Hanson. This is a well-written and well-documented C front end that can be adapted to generate the intermediate representation that is needed for the optimizing compiler.

Some modifications will need to be made to the front end to increase the information passed to the optimization phases. LCC assumes that it is directly generating assembly language or object modules. Thus information is used and lost. This information must be preserved. In particular, the alias information concerning load and store operations must be preserved for use within the optimizer. Also, arrays should not be directly changed into pointer expressions, but kept as array references instead.


Previous Table of Contents Next


Building an Optimizing Compiler
Building an Optimizing Compiler
ISBN: 155558179X
EAN: 2147483647
Year: 1997
Pages: 18
Authors: Bob Morgan

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net