A look at Gnu Compiler

Gnu Compiler is one of the strongest and most widely used Compilers today. it is known for its power, flexibility, portability and wide architecture support.
Simply; you can use Gnu Complier on any unix/Linux, Windows or Mac.
you can also compile programs for a wide range of platform, including intel, AMD, ARM, PowerPC, SPARC …etc
Gnu Compiler support Languages like C, C++ (g++), Objective-C, fortran (gfortran), java (gcj), Ada , VHDL ……. use your imagination!!
So, let’s take a look at the architecture of the gnu compiler collection
Gnu Compiler is divided into 3 main components:
- front-end.
- middle-end.
- back-end.
We will take a closer look at theses three Layers:
- The Front-end:
This layer is Language-specific, architecture-neutral to handle the source code file.
Depending on the programming Language used to write the code , we choose the appropriate fornt-end.
for example: for C++ source files we use g++, for java files we use gcj …..
The purpose of the front end is to read the source file, parse it, and convert it into the standard abstract syntax tree (AST) representation. The AST is a dual-type representation: it is a tree where a node can have children and a list of statements where nodes are chained one after another.
INPUT : the source code , a text file contains the program to be compiled.
OUTPUT: a tree-like representation of the source code. Also called the Abstract Syntax Tree (AST).
- The Middle-end:
Language-neutral, architecture-neutral layer for enhancing/optimizing the tree representation of the source code (AST). and generating a register-transfer language (RTL) tree. RTL is a hardware-based representation that corresponds to an abstract target architecture with an infinite number of registers. So, RTL looks like Assembly code BUT IT ISN’T. it is more like architcture independent assembly. Code optimization is done in this stage, eliminating dead code – code can’t be executed – replacing some segements of code – the RTL – with faster segments and so on.
INPUT : Abstract Syntax Tree (AST).
OUTPUT: Register Transfer Language (RTL).
- The back-end:
A Language-neutral, yet Architecture-specific layer that generates the assembly code for the target architecture using the RTL representation -from the previous phase. the back-end stage has a description file for each hardware architecture that includes information about what’s available of the processor – the actual registers and so on. these descriptions are used to map the RTL instructions to the actual and appropriate assembly segment. As you can see, this phase tells us why gnu compilera are flixible, efficient and portable. for each chip/family, you can have a description file that tells the compiler WHAT availbale and how to use it. So, the compiler generates a very efficient assembly code for each processor chip.
INPUT : the RTL
OUTPUT: the Object file – the executable file
the following figure explains the output of each component :

the output of each compoenet of the gcc : 1)AST 2)RTL 3)Object Code
nice artiقle
Ahmed Farrag
March 3, 2009 at 2:28 am