Retargetable C Compiler, A Design and Implementation

by ;
Edition: 1st
Format: Paperback
Pub. Date: 1995-01-31
Publisher(s): Addison-Wesley Professional
List Price: $69.99

Rent Book

Select for Price
There was a problem. Please try again later.

New Book

We're Sorry
Sold Out

Used Book

We're Sorry
Sold Out

eBook

We're Sorry
Not Available

How Marketplace Works:

  • This item is offered by an independent seller and not shipped from our warehouse
  • Item details like edition and cover design may differ from our description; see seller's comments before ordering.
  • Sellers much confirm and ship within two business days; otherwise, the order will be cancelled and refunded.
  • Marketplace purchases cannot be returned to eCampus.com. Contact the seller directly for inquiries; if no response within two days, contact customer service.
  • Additional shipping costs apply to Marketplace purchases. Review shipping costs at checkout.

Summary

This book brings a unique treatment of compiler design to the professional who seeks an in-depth examination of a real-world compiler. Chris Fraser of AT &T Bell Laboratories and David Hanson of Princeton University codeveloped lcc, the retargetable ANSI C compiler that is the focus of this book. They provide complete source code for lcc; a target-independent front end and three target-dependent back ends are packaged as a single program designed to run on three different platforms. Rather than transfer code into a text file, the book and the compiler itself are generated from a single source to ensure accuracy.

Author Biography

Since 1975, Christopher W. Fraser has researched compiling, particularly producing code generators automatically from compact specs, and has published many technical articles in this area. He originated retargetable peephole optimization, which GCC, a popular C compiler, uses to help select instructions. From 1977 until 1986, Fraser taught computer science, including compiling, at the University of Arizona. Since 1986, Fraser has conducted computing research at AT&T Bell Laboratories in Murray Hill, New Jersey.

David R. Hanson is a Professor of Computer Science at Princeton University with more than 20 years of research experience in programming languages. He has conducted research in conjunction with Bell Laboratories and is the co-author of lcc, a production quality, research compiler for the C language that is popular with the Unix community. lcc is presented and analyzed in the book A Retargetable C Compiler: Design and Implementation , by Christopher Fraser and David Hanson (c) 1995, Addison-Wesley.



0805316701AB04062001

Table of Contents

Preface.
1. Introduction.
Literate Programs.
How to Read This Book.
Overview.
Design.
Common Declarations.
Syntax Specifications.
Errors.

2. Storage Management.
Memory Management Interface.
Arena Representation.
Allocating Space.
Deallocating Space.
Strings.

3. Types.
Representing Symbols.
Representing Symbol Tables.
Changing Scope.
Finding and Installing Identifiers.
Labels.
Constants.
Generated Variables.

4. Code Generation Interface.
Representing Types.
Type Management.
Type Predicates.
Type Constructors.
Function Types.
Structure and Enumeration Types.
Type-Checking Functions.
Type Mapping.

5. Lexical Analysis.
Type Metrics.
Interface Records.
Symbols.
Types.
Dag Operators.
Interface Flags.
Initialization.
Definitions.
Constants.
Functions.
Interface Binding.
Upcalls.

6. Parsing.
Input.
Recognizing Tokens.
Recognizing Keywords.
Recognizing Identifiers.
Recognizing Numbers.
Recognizing Character Constants and Strings.

7. Expressions.
Languages and Grammars.
Ambiguity and Parse Trees.
Top-Down Parsing.
FIRST and FOLLOW Sets.
Writing Parsing Functions.
Handling Syntax Errors.

8. Expression Semantics.
Representing Expressions.
Parsing Expressions.
Parsing C Expressions.
Assignment Expressions.
Conditional Expressions.
Binary Expressions.
Unary and Postfix Expressions.
Primary Expressions.

9. Expression Semantics.
Conversions.
Unary and Postfix Operators.
Function Calls.
Binary Operators.
Assignments.
Conditionals.
Constant Folding.

10. Statements.
Representing Code.
Execution Points.
Recognizing Statements.
If Statements.
Labels and Gotos.
Loops.
Switch Statements.
Return Statements.
Managing Labels and Jumps.

11. Declarations.
Translation Units.
Declarations.
Declarators.
Function Declarators.
Structure Specifiers.
Function Definitions.
Compound Statements.
Finalization.
The Main Program.

12. Generating Immediate Code.
Eliminating Common Subexpressions.
Building Nodes.
Flow of Control.
Assignments.
Function Calls.
Enforcing Evaluation Order.
Driving Code Generation.
Eliminating Multiply Referenced Nodes.

13. Structuring the Code Generator.
Organization of the Code Generator.
Interface Extensions.
Upcalls.
Node Extensions.
Symbol Extensions.
Frame Layout.
Generating Code to Copy Blocks.
Initialization.

14. Selecting and Emitting instructions.
Specifications.
Labelling the Tree.
Reducing the Tree.
Cost Functions.
Debugging.
The Emitter.
Register Targeting.
Coordinating Instruction Selection.
Shared Rules.

15. Register Allocation.
Organization.
Tracking the Register State.
Allocating Registers.
Spilling.

16. Generating MIPS R3000 Code.
Registers.
Selecting Instructions.
Implementing Functions.
Defining Data.
Segments.
Copying Blocks.

17. Generating SPARC Code.
Registers.
Selecting Instructions.
Implementing Functions.
Defining Data.
Copying Blocks.

18. Generating X86 Code.
Registers.
Selecting Instructions.
Implementing Functions.
Defining Data.

19. Retrospective.
Data Structures.
Interface.
Syntactic and Semantic Analyses.
Code Generation and Optimization.
Testing and Validation.

Bibliography.
Index.
How to Obtain ICC. 0805316701T04062001

Excerpts

The compiler is the linchpin of the programmer's toolbox. Working programmers use compilers every day and count heavily on their correctness and reliability. A compiler must accept the standard definition of the programming language so that source code will be portable across platforms. A compiler must generate efficient object code. Perhaps more important, a compiler must generate correct object code; an application is only as reliable as the compiler that compiled it. A compiler is itself a large and complex application that is worthy of study in its own right. This book tours most of the implementation of lcc, a compiler for the ANSI C programming language. It is to compiling what Software Tools by B.W. Kernighan and P.J. Plauger (Addison-Wesley, 1976) is to text processing like text editors and macro processors. Software design and implementation are best learned through experience with real tools. This book explains in detail and shows most of the code for a real compiler. The accompanying diskette holds the source code for the complete compiler. lcc is a production compiler. It's been used to compile production programs since 1988 and is now used by hundreds of C programmers daily. Detailing most of a production compiler in a book leaves little room for supporting material, so we present only the theory needed for the implementation at hand and leave the broad survey of compiling techniques to existing texts. The book omits a few language features--those with mundane or repetitive implementations and those deliberately treated only in the exercises--but the full compiler is available on the diskette, and the book makes it understandable. The obvious use for this book is to learn more about compiler construction. But only few programmers need to know how to design and implement compilers. Most work on applications and other aspects of systems programming. There are four reasons why this majority of C programmers may benefit from this book. First, programmers who understand how a C compiler works are often better programmers in general and better C programmers in particular. The compiler writer must understand even the darkest corners of the C language; touring the implementation of those corners reveals much about the language itself and its efficient realization on modern computers. Second, most texts on programming must necessarily use small examples, which often demonstrate techniques simply and elegantly. Most programmers, however, work on large programs that have evolved--or degenerated--over time. There are few well documented examples of this kind of "programming in the large" that can serve as reference examples. lcc isn't perfect, but this book documents both its good and bad points in detail and thus provides one such reference point. Third, a compiler is one of the best demonstrations in computer science of the interaction between theory and practice. lcc displays both the places where this interaction is smooth and the results are elegant, as well as where practical demands strain the theory, which shows in the resulting code. Exploring these interactions in a real program helps programmers understand when, where, and how to apply different techniques. lcc also illustrates numerous C programming techniques. Fourth, this book is an example of a "literate program." Like TEX: The Program by D.E. Knuth (Addison-Wesley, 1986), this book is lcc's source code and the prose that describes it. The code is presented in the order that best suits understanding, not in the order dictated by the C programming language. The source code that appears on the diskette is extracted automatically from the book's text files. This book is well suited for self-study by both academics and professionals. The book and its diskette offer complete documented source code for lcc, so they may interest practitioners who wish to experiment with compilatio

An electronic version of this book is available through VitalSource.

This book is viewable on PC, Mac, iPhone, iPad, iPod Touch, and most smartphones.

By purchasing, you will be able to view this book online, as well as download it, for the chosen number of days.

Digital License

You are licensing a digital product for a set duration. Durations are set forth in the product description, with "Lifetime" typically meaning five (5) years of online access and permanent download to a supported device. All licenses are non-transferable.

More details can be found here.

A downloadable version of this book is available through the eCampus Reader or compatible Adobe readers.

Applications are available on iOS, Android, PC, Mac, and Windows Mobile platforms.

Please view the compatibility matrix prior to purchase.