Compiling process in terms of a simple c++ program

This question already has an answer here:

  • How does the compilation/linking process work? 5 answers

  • This is a very broad question in general but i'll try to answer as briefly as possible. A typical language processing system has the following phases :

    1. Preprocessing Phase - In this phase all preprocessors and macros are handled and code is generated which is free from these. This involves replacing macro calls with macro body and replacing the formal parameters with the actual parameter.

    2. Compilation Phase - This has several smaller phases such as: Lexical Analysis , Syntax Analysis , Semantic Analysis , Intermediate code generation , code optimization , target code generation , etc. The Compilation phase may/may not produce assembly code. There are separate pros and cons of both the approaches. We will assume that assembly code was produced in this discussion.

    3. Assembly Phase - The assembler converts the output of compiler to target code . Assemblers can be one pass or two pass in nature.

    4. Linking Phase - The code that has been produced has many references and calls to subroutines which are defined in other modules. Such modules are linked to the code in this phase and the addresses are assigned to such instructions which have outside references.

    5. Loading Phase - In this phase , all the segments which are produced in the previous phase get loaded into the RAM for actual execution and control is passed to the first instruction.

    All components listed in this answer have many intricacies and sub-parts and in no way are a complete explanation of a language processor.

    There are books such by authors DM Dhamdere , Tannenbaum and Alfred Aho on these topics which are useful.

    链接地址: http://www.djcxy.com/p/73306.html

    上一篇: 为什么生成目标文件

    下一篇: 用一个简单的c ++程序编译过程