The point
Answer the retargeting question with evidence rather than a feeling. The useful comparison is about your own compiler's structure, not about instruction sets.
Do this
- Take one function from your own compiler's output — something with an
ifand a loop — and print the MIPS. - Hand-translate it to ARM. You need the shape, not fluency. The mapping table in the lecture notes is enough.
- Count. Instructions in each version. Where did the counts differ, and why?
- The interesting difference. Rewrite
if (a > 0) x = 1;usingcmpand a predicatedmovgt, with no branch at all. Compare against the MIPS version and say what the compiler would have to decide before it could do this automatically. - The condition-code difference. Our IR produces a comparison value. ARM would rather have a comparison that sets flags. Which of Dragon's two translations of boolean expressions (§6.6) suits ARM better, and what would change in your TAC generator if you adopted it?
- Now the real question. Go file by file through your compiler and mark each unchanged, small changes, or rewritten. Then say in one sentence what that list tells you about why the compiler has an IR.
- Within the back end, list the specific functions that would change. Be precise — this is the answer to the objective.
What step 6 should come out as
Scanner, parser, AST, semantic analyzer and TAC generator: unchanged. Symbol table: unchanged in interface, possibly a different word size. Code generator: rewritten. Roughly 85% of the compiler is target-independent, and that is not an accident — it is what phase 4 exists to buy you, and it is the strongest single thing you can say about the architecture.
Deliverable
Both listings with instruction counts; your predicated version and what the compiler would have to decide; your answer on flags versus values; the file-by-file table; and the list of back-end functions that would change.