Introduction
Gcc now refers to "GUN compiler set", which is the meaning of "gun c language compiler" in the last century ".
2.1 General Program compilation process
Take gcc as an example:
In general, for example, we have a source file: main. c, which writes our code. To execute the following command, run the gcc main. c command to generate a. out file. Then./a. out can be executed. However, have you noticed this intermediate process? This is what compilation principles need to be studied. This section describes the entire processing process. The details will be discussed later, including lexical analysis, syntax analysis, intermediate code generation and optimization, and machine-independent optimization, concurrency and local optimization. And how to invent a language, and then write a compiler to compile it!
You can add parameters to view the results of each stage.
In, CPP is the abbreviation of "pre-compilation", AST is the abbreviation of "abstract syntax tree", and SSA is the abbreviation of "Static Single Assignment, RTL is short for "register transfer language. Please have a good taste of the meaning.
The process is as follows:
1. Perform lexical analysis and syntax analysis in different languages to obtain the AST of the corresponding language
2. There are slight differences between the AST, and then remove these differences to generate a general AST
3. Generate intermediate code according to AST (three-address code, that is, x = y op z)
4. Optimize the intermediate code. This part of the task is very difficult.
5. Generate the Assembly Language corresponding to the machine architecture based on the Assembly description of the target machine
6. the compiler task is complete, and the remaining assembler is complete.
7. The assembler compiles it into machine code (010100101000101010010101010000101011110 ......)
8. connector ld connects library functions called in source code
9. The last part is the loader, which loads the executable file to the memory and executes it.
2.2 compiler frontend Processing
The following is a simple c statement compilation process.
:
Conclusion 2.3
The execution of a program written in advanced languages takes a long and complex process. This process is often ignored by our programmers.
Salute to compiler creators.
The learning process of compilation principles is generally boring. If you have one more person, you will have more fun and happiness!
Author: rill_zhen