A usual way for the compiler to go about the transform of the source code to actual assembler code in the compiling process, is to model it around a series of steps.

The reason for this is that it is desired to go over code several times to do - besides syntax checking - type checking, semantic analysis and optimizations.

An example of a set of steps would be:

Generating an Abstract Syntax Tree
Generating an Intermediate Representation Tree.
Various optimizations
Generating "real code"


Generating an Abstract Syntax Tree. The Abstract Syntax is a tree representation of the original source code. In the process of it's creation, syntax checking is performed.


Generating an Intermediate Representation Tree. As the Abstract Syntax has been checked as far as Types and Semantics, the Intermediate Representation is created. This tree could be thought of as a pseudo assembler, which still is independant of target platform.

As this tree is generated, a similar intermediate form of register and memory allocation is created.


Various Optimizations Once the Intermediate Representation is generated, this tree will be transformed by various optimizing algorithms to enhance program flow and ease the process of instruction selection.


Generating "real code" This is where the platform dependent modules are added to the compiler. Extracting the instructions from the intermediate representation is a careful process, where chunks of psuedo code are selected and converted to actual assembler. All dependent of the individual processor and operating system.

Log in or register to write something here or to contact authors.