Noeud:The Compiler, Noeud « Next »:, Noeud « Previous »:The Preprocessor, Noeud « Up »:GCC Commands



The Compiler

The compiler's task is to produce assembly code from the preprocessed source file utilising several different stages: lexical, syntax and semantic analysis, intermediate code generation, optimization and code generation.

gcc uses an intermediate language known as RTL - register transfer language, during the compilation stage. RTL is produced as the parse tree is built, and as functions etc. are defined, they are turned into RTL instructions and a number of optimizations are performed on the RTL code.

To produce a file output from the compiler, invoke gcc using the -S flag. The output will be a number of files in assembler with the .s extension. You can pass either a .c or preprocessed .i file to the compiler; gcc will determine by the file extension what needs to be done in terms of whether or not to pass the file(s) to the preprocessor first or not. Producing assembler sources may not seem very useful, but can be helpful if you want to write an assembler routine, and want to see how it is done (write a C program to do it, then run it through gcc with -S and check out the assembly language produced in the corresponding .s file).

As with the preprocessor, you don't need to pass the file(/s) directly to gcc - you can pass them to the compiler, cc1, passing the --help flag to the compiler if you need to know the options available.