1.7 A Real-life Compiler – gcc

The GNU C compiler gcc is arguably the best compiler available for C language. In fact it is a suite of compilers, as the package contains g++ − a compiler for C++, and facilities to compile other languages like Objective-C and Objective-C++, FORTRAN in both fixed form and free form (i.e. F90 and F95 versions), ADA, Java. It can handle different dialects of C.

It is also able to generate executable code for the following CPU families: ARC, ARM, AVR, Darwin, DEC Alpha, HPPA, i386 and x86-64, IA-64, Motorola M680x0, MIPS, PDP-11, PowerPC, RS/6000, S/390, SPARC, TMS320C3x/C4x and others.

Thus, gcc is a good example of the ideas presented in Section 1.5.

When you invoke GCC, it normally does pre-processing, compilation, assembly and linking. The “overall options” allow one to stop this process at an intermediate stage. For example,

-c   Compile or assemble the source files, but do not link. The linking stage is not simply done. The ultimate output is in the form of an object file for each source file.

-S   Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file for each non-assembler input file specified.

-E   Stop after the pre-processing stage; do not run the compiler proper. The output is in the form of pre-processed source code, which is sent to the standard output.

-o file   Place output in file file.

-wall   A warning option – displays all possible warnings, very useful during initial debugging of a code.

In fact, gcc has a large complement of options for warnings, debugging, optimization, pre-processor, linker, assembler and target machine/language. You should see the man-page of gcc for full details. In general, the processing steps followed by gcc are:

  • pre-processing (invokes cpp),
  • compilation,
  • assembly (invokes as), see Fig. 1.17,

 

gcc converts from C to obj using assembler

 

Fig. 1.17 gcc converts from C to obj using assembler

 

The linker converts an obj file to an executable

 

Fig. 1.18 gcc: The linker converts an obj file to an executable

 

In gcc, the level of attempted optimization controlled by −0 and other switches, but you have to be careful, specially for embedded and Device-driver codes.

In the subsequent chapters, we shall refer to GCC for indicating how relevant phases of a theoretical compiler get implemented in a real-life compiler suite.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.200.220