GNU Compiler Collection
From Wikipedia, the free encyclopedia.
In computing, GCC is the GNU Compiler Collection. Originally, it stood for GNU C Compiler, but it now handles many different programming languages besides C.
| Table of contents |
|
2 Languages 3 Architectures 4 Structure 5 Reference 6 See also 7 External links |
Overview
GCC is a GPL-licensed compiler distributed by the Free Software Foundation, and a key enabling technology for the Open Source Software (OSS) and Free software movements. Originally written by Richard Stallman in 1987, GCC is now maintained by a varied group of programmers from around the world. It has been ported to more kinds of processors and operating systems than any other compiler.
In 1997, a group of developers dissatisfied with the slow pace and closed nature of official GCC development formed a project called EGCS (Experimental/Enhanced GNU Compiler System) which merged several experimental forks into a single project forked from GCC. EGCS development subsequently proved sufficiently more vital than GCC development that EGCS was eventually "blessed" as the official version of GCC in April 1999.
GCC has been adopted as the main compiler used to build and develop for a number of systems, including GNU/Linux, the BSDss, Mac OS X, NeXTSTEP, and BeOS.
Languages
As of version 3.2, the standard compiler release includes front ends for:
- Ada (GCC for Ada aka GNAT)
- C
- C++ (GCC for C++ aka G++)
- Fortran (GCC for Fortran aka G77)
- Java
- Objective-C
- Treelang
Architectures
GCC target processors (as of version 3.2) include:
- Alpha
- ARM
- H8/300
- System/370, System 390
- X86 and X86-64
- IA-64 "Itanium"
- Motorola 68000
- Motorola 88000
- MIPS
- PA-RISC
- PDP-11
- PowerPC
- SuperH
- SPARC
- VAX
Structure
GCC's external interface is generally standard for a Unix compiler. Users invoke a driver program named "gcc", which interprets command arguments, decides which language compilers to use for each input file, runs the assembler on their output, and then possibly runs the linker to produce a complete program.
Each of the language compilers is a separate program that takes in source code and produces assembly language. All have a common internal structure; a per-language front end that parses the languages and produces an abstract syntax tree ("tree" for short), and a back end that converts the trees to GCC's Register Transfer Language, runs various compiler optimizations, then produces assembly language using architecture-specific pattern matching originally based on an algorithm of Jack Davidson and Chris Fraser.
Nearly all of GCC is written in C, although much of the Ada frontend is in Ada.
Front ends
Frontends vary internally, having to produce trees that can be handled by the backend. Some parsers use a YACC-type grammar specification, and the others are hand-coded recursive descent parsers.
The tree representation of a program is more-or-less independent of the processor being targeted. However, confusingly, the meaning of a tree is somewhat different for different language front-ends, and front-ends can provide their own tree codes. They are implemented as C language unions.
Back end
The behavior of the GCC back end is partly specified by preprocessor macros and functions specific to a target architecture, for instance to define the endianness, word size, and calling conventions. The front part of the back end uses these to help decide RTL generation, so although GCC's RTL is nominally processor-independent, the initial sequence of abstract instructions is already adapted to the target.
The exact set of GCC optimizations varies from release to release as it develops, but includes the standard algorithms, such as jump optimization, jump threading, common subexpression elimination, instruction scheduling, and so forth.
A "reloading" phase changes abstract (pseudo-) registers into real machine registers, using data collected from the patterns describing the target's instruction set. This is a somewhat complicated phase, because it must account for the vagaries of all of GCC's targets.
The final phase is somewhat anticlimactic, since the patterns to match were generally chosen during reloading, and so the assembly code is simply built by running substitutions of registers and addresses into the strings specifying the instructions.
Reference
- Richard M. Stallman, Using and Porting the GNU Compiler Collection (Free Software Foundation, 1988-2004)
See also
- GCC Introspector
- LLVM
External links