The point
Translate a syntax tree to three-address code by hand, then make the compiler agree with you. Where you differ, one of you has made a design decision without noticing.
Do this
- By hand. Write the TAC for
Useint a; int b; int c; a = 1 + 2; b = a + a; c = a + b + 3; print(c);t0, t1, …for temporaries and number every instruction. - Now as quadruples. Redraw your listing as a four-column table — op, arg1, arg2, result — exactly as in §9 of the lecture notes.
- Count your temporaries. How many did you use in total? How many were live at once? Those are different numbers, and the second is the one a register allocator cares about.
- Compare with a partner. Different instruction counts mean different choices — find out what they were.
- Now the compiler. Implement the TAC generation and read
out.tac. Reconcile every difference from your listing. - Hand-execute your TAC. With a table of variable values, step through the listing and confirm it prints what the source should. This is how you will debug phase 6 next week.
Deliverable
Your handwritten TAC, the same listing as quadruples, the compiler's out.tac, and a numbered list of the differences with an explanation for each. This is Lab Question 8.