Overview of intermediate code generation and compiler backend
Intermediate code generation
After lexical analysis, grammatical analysis, and semantic analysis, it comes to the intermediate code generation stage
There are two forms of intermediate code:
- Three address code
- Syntax structure tree (referred to as syntax tree) , which is different from the previous syntax analysis tree
Three address code
The three-address code consists of a sequence of instructions similar to assembly language, and each instruction has up to three operands, so it is called three-address code
Address can have three forms
- The name in the source program (variable name)
- constant
- Temporary variables generated by the compiler
Common three address instructions
Representation of three address instructions
- Quaternion
- Ternary
- Indirect ternary
Object code generation
After the intermediate code is generated, its code will be optimized to a certain extent, and then it will enter the target code generation
The object code generator takes the intermediate code as input and maps it to the target language.At the same time, another important task of the object code generator is to allocate registers for variables .
Machine code related optimizer
An important task is to allocate registers for variables .
Machine code related optimizer
The equivalent program transformations made to improve the code make it run faster and take up less space.