Académique Documents
Professionnel Documents
Culture Documents
Intermediate codes are machine independent codes, but they are close to machine instructions.
The given program in a source language is converted to an equivalent program in an intermediate language by the intermediate code generator.
Intermediate language can be many different languages, and the designer of the compiler decides this intermediate language.
syntax trees can be used as an intermediate language. postfix notation can be used as an intermediate language. three-address code (Quadruples) can be used as an intermediate language
DAG
No built-up arithmetic expressions are allowed. As a result, x:=y + z * w should be represented as t1:=z * w t1 , t2 compiler generated temporary names t2:=y + t1 x:=t2 Observe that given the syntax-tree or the dag of the graphical representation we can easily derive a three address code for assignments as above. In fact three-address code is a linearization of the syntax tree. Three-address code is useful: related to machine-language/ simple/ optimizable.
Syntax tree
Dag
x:=y[ i ] x[ i ]:=y
Quadruples
A quadruple is a record structure with four fields: op, arg1, arg2, and result
The op field contains an internal code for an operator Statements with unary operators do not use arg2 Operators like param use neither arg2 nor result The target label for conditional and unconditional jumps are in result
The contents of fields arg1, arg2, and result are typically pointers to symbol table entries
op
(0) (1) (2) (3) uminus * uminus *
arg1
c b c b
arg2
result
t1
t1
t2
t3
t4
(4) (5)
+ :=
t2 t5
t4
t5 a
Triples
Triples refer to a temporary value by the position of the statement that computes it
Statements can be represented by a record with only three fields: op, arg1, and arg2 Avoids the need to enter temporary names into the symbol table Pointer into symbol table (for programmer defined names) Pointer into triple structure (for temporaries)
op
(0) (1) (2) (3) uminus * uminus *
arg1
c b c b
arg2
(0)
(2)
(4) (5)
+ assign
(1) a
(3) (4)
Indirect Triples
Consist of a listing of pointer to triples, rather than a listing of triples themselves. With indirect triples an optimizing compiler can move an instruction by reordering the instructions list without affecting the triples themselves.
arg1 c b
arg2
(0) (1)
(14) (15)
(14)
(2)
(3) (4) (5)
(16)
(17) (18) (19)
(16) uminus
(17) * (18) + (19) assign
c
b (15) a (16) (17) (18)