Compiler-Intermediate Code Generation & Code Optimization
- Three Address Code
- Control Sequence
- Variable Declaration
Intermediate Code
Intermediate code separates the front end and the back end. It is an intermediate level between
- a high level parse tree and
- low level microprocessor instructions.
It is internal to compilers. Different compilers may have different intermediate codes.
Possible types of intermediate code:
- Syntax trees
- Static single assignment
- Three address code
Three Address Code
Each 3AC instruction consists of at most
- one operator (binary or unary) and three address (variable number)
For example,
(binary operator) (unary operator) (copy/ assignment) (unconditional , is the label of the destination) (conditional goto)
To convert a parse tree to 3AC, we need two synthesized attributes for each node in the parse tree.
Suppose we have a grammar production
stores the name of the variable containing the value of . stores the sequence of 3AC that computes the value if .
The function
Example
Define the attributes for the following grammar
- "||" means "followed by"
- No
because is an assignment, not computing a value.
(intrinsic) (nothing to compute)