[19] C language learning record compilation process

How this lesson C language compiler language study program. Level of understanding of the compiler determines the quality of the code.

 

intermediate code file.i

file.s assembly file

file.o binary file

Precompiled (text processing)

1) for all notes, instead of a space;

2) delete all #define and expand all the macro definitions;

3) processing conditional compilation command, # if, # ifdef, # elif, # else, # endif

4) processing #include, expand the file to be included;

5) Reserved #pragma compiler command you want to use;

Example preprocessing directives:

gcc -It file.c -a file.i

Compile

1) pretreatment file lexical analysis, syntax analysis and semantic analysis;

       a> lexical analysis: keyword analysis, indicators, such as the number of immediate legality;

       b> syntax analysis: Analysis Expressions compliance with the principles of grammar;

       c> semantic analysis: further analysis of expression is legitimate on the basis of grammatical analysis;

  1. Code optimization corresponding assembly code file generated after analysis;

Examples of compiler directives:

gcc –S file.i –o file.s

Assembler (compiler work relatively simple)

1) The assembler assembly code into machine code that can be executed;

2) Each compiled statement almost each machine instruction;

Example assembly instructions:

gcc -c file.s -o file.o

summary:

Compilation process consists of pretreatment, compile, assemble and link four stages.

1) Pretreatment: annotation process, the beginning of the macro and the symbol #;

2) compilation: lexical analysis, parsing and semantic analysis;

3) Assembly: The assembly code translated into machine instructions of the target file;

Guess you like

Origin blog.csdn.net/haibing_x/article/details/94591367