One of the purposes of using intermediate code in compilers is to :

2023

One of the purposes of using intermediate code in compilers is to :

  1. A.

    make parsing and semantic analysis simpler

  2. B.

    improve error recovery and error reporting

  3. C.

    increase the chances of reusing the machine independent code optimizer in other compilers

  4. D.

    improve the register allocation

Attempted by 128 students.

Show answer & explanation

Correct answer: C

Answer: Using a machine-independent intermediate representation increases the chances of reusing the machine-independent code optimizer in other compilers.

Key points:

  • Machine-independent intermediate code (for example, three-address code or SSA) represents program semantics without target-specific details such as registers or instruction encodings.

  • A machine-independent optimizer can operate on this representation, so the same optimizer can be reused by multiple front ends and back ends; only the front end (to produce the intermediate code) and the back end (to lower it to target code) need retargeting.

  • Parsing, semantic analysis, error recovery, and error reporting are front-end tasks performed before generating intermediate code; they are not primary reasons for introducing intermediate code.

  • Register allocation is a machine-dependent back-end optimization that depends on the target's register set and calling conventions; intermediate code can support analyses, but register allocation itself is solved in the back end.

  • Overall, intermediate code promotes modularity, portability, and reuse of machine-independent optimization components.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Mppsc Assistant Professor