In-depth introduction to compilation principles-2-GCC compiler Overview

Source: Internet
Author: User


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.