Introduction
Code Generator is one of the core components involved during the process of Code generation while compilation is taking place. Since Code Generation is the last phase of generating assembly code/machine-readable code during compilation. Some significant properties of this activity are given as
- Absolute quality code
- Efficient Use of Resources
-
Quick Code
Example:
Let us take the three address statements a:= b+c.
It consists of the following sequence of codes.
MOV a, R0
ADD b, R0
The code generator ensures that the code generation is efficiently happening using fast memory accesses through memory registers instead of cache. Since registers are an expensive memory resource, they are limited and must be used effectively. Performing different operations on registers is much more efficient as registers are faster than cache memory. Therefore, to try and use a minimum number of registers to incur a minimal overall cost, a 'Code generator is used to generate the target code for three-address statements to store the intermediate operands in which registers play a crucial role.
Also See, Top Down Parsing
Address and Register Descriptors
Consider the following three address statements -
a:= b + c
It can have the following sequence of codes:
A register descriptor contains the track of what is currently in each register. It shows that all the registers are initially empty.
And an address descriptor that is used to store the location where one can find the current value of the name at run time.
The code generator then uses these descriptors to keep track of the executed set of instructions efficiently in the limited set of registers.