Software Building Basics--building processes

Source: Internet
Author: User

The building of the software is decomposed into 4 steps, namely preprocessing (prepressing), compiling (compilation), compiling (Assembly), linking (linking).

The following is a C language for example, the 4 steps to do a brief explanation:

Pretreatment

Preprocessing is mainly the "#" in the source file to start the command to process, mainly for:

1. Expand the macro definition (#define) in the source file reference location intact (so use the macro definition to wrap the entire definition with parentheses).

2, the processing conditions pre-compilation (#ifdef ...), to obtain the correct condition process.

3, the corresponding header file is expanded at the precompiled Place (#include) of the containing file, and if the header file contains other files, it is expanded recursively.

4. Delete comments in code

5, add line number and file name identification, easy compiler debugging or warning, etc. can display line number

6. Keep compiler settings directive (#pragma) for compiler

After preprocessing the file is ". I" suffix, we can view this file to determine whether the compiled code is correct.

Compile

Compilation is the process of processing the ". I" File as a ". S" assembly file, which undergoes lexical analysis, grammatical analysis, semantic analysis, and optimization steps.

Lexical analysis:

Scan the code one by one, sorting out keywords, identifiers, special symbols, literals, etc. according to the rules of the language currently in use to generate an ordered table.

Syntax Analysis:

Based on the grammatical rules of the language used, the lexical analysis table is checked for syntax and a syntax tree is generated. The syntax tree also indicates the priority and order of operations in a line of code.

If there is a grammatical error, you will get an error at this step.

Semantic Analysis:

Semantic analysis of the syntax tree, after language analysis, the type of identifiers can be determined (to determine whether the need to cast and so on).

If there is a semantic error, you will get an error in this step (e.g. two pointers multiplied).

Optimization:

The final syntax tree is converted to intermediate code after optimization, resulting in hardware-related assembly code.

Assembly

The assembler compiles the generated assembly files into the corresponding machine code files according to the hardware architecture, also called the object file (the ". O" suffix).

Note: in a compiled file, the final address of internal variables and functions needs to be determined by linking.

Link

The link modifies the directives in multiple target files and their address references to other symbols to generate executable files.

This includes steps such as address and space allocation (addresses and Storage Allocation), symbol resolution (symbol Resolution), relocation (relocation), and so on.

Software Building Basics--building processes

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: info-contact@alibabacloud.com 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.