Overview of intermediate code generation and compiler backend

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

  1. The name in the source program (variable name)
  2. constant
  3. Temporary variables generated by the compiler

Common three address instructions

Insert picture description here

Representation of three address instructions

  1. Quaternion
  2. Ternary
  3. Indirect ternary

Insert picture description here

Insert picture description here

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.

Guess you like

Origin blog.csdn.net/qq_44823898/article/details/108018607