Questions: Intermediate Code Representation

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A compiler team wants to support 5 source languages targeting 4 hardware architectures. Without IR, how many separate translators do they need? With a shared IR?

AWithout IR: 9 (5 + 4); with IR: 20 (5 × 4)
BWithout IR: 20 (5 × 4); with IR: 9 (5 + 4)
CWithout IR: 20 (5 × 4); with IR: 5 (one per source language)
DThe number is the same either way; IR only affects optimization quality, not translator count
Question 2 Multiple Choice

Why is three-address code (TAC) better than an AST as a target for optimization passes like dead code elimination or constant folding?

ATAC is closer to machine code, so optimization passes run faster
BTAC eliminates all temporary variables before optimization, reducing state to track
CTAC mirrors source language syntax, making it easier to preserve programmer intent
DTAC flattens expressions into sequential instructions with named temporaries, making data flow and control flow explicit and easy to analyze
Question 3 True / False

A single set of optimization passes (e.g., dead code elimination) written for an IR can be applied to programs from multiple source languages.

TTrue
FFalse
Question 4 True / False

Using an IR layer typically produces slower machine code than a direct source-to-machine translation, because the extra translation step introduces inefficiency.

TTrue
FFalse
Question 5 Short Answer

Why is three-address code a better target for optimization than an abstract syntax tree, even though both represent the same program?

Think about your answer, then reveal below.