05.10.2013 Views

1 Code Generation Code generator phase ... - VTU e-Learning

1 Code Generation Code generator phase ... - VTU e-Learning

1 Code Generation Code generator phase ... - VTU e-Learning

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Fig 9.6 DAG for the three address code<br />

Fig 9.6 shows the DAG for the expression a = -b * c + d represented as three address code<br />

Example: Consider the following expression<br />

a = b * d + b * d + c<br />

The three address code will be<br />

t1 = b * d<br />

b2 = b * d<br />

t3 = t1 + t2<br />

t4 = t3 + c<br />

a = t4<br />

Fig 9.7 DAG for the three address code<br />

Fig 9.7 shows the DAG for the expression a = b * d + b * d + c represented as three address code.<br />

From the above DAG it is found that node * has 2 labels t1 & t2. Hence there is no necessary to<br />

generate code twice for the same expression. Final code can be generated from DAG by topological<br />

sorting. Topological sorting is the traversal of tree from leaf to root in which children are visited<br />

before their parents. As there can be multiple topological sorts. There can be many code sequences for<br />

single DAG.<br />

Example:<br />

Consider intermediate code<br />

t1 = a + b<br />

a = t1<br />

t2 = b – 1<br />

b = t2<br />

t3 = b + 5<br />

t1, t2 *<br />

b d<br />

t4 , a ⊕<br />

t3 ⊕ c<br />

⊕ t3<br />

a1 t2 ⊕ Ө t2 , b1 5<br />

a0 b 1<br />

18

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!