Question
One of the purposes of using intermediate code in compilers is to
Official answer and solution
- Official answer
- C
- From
- Official GATE 2014 answer key
Solution
Recall the fundamental role of intermediate representation (IR) in decoupling compiler front-ends from target architecture back-ends.
-
In compiler design, intermediate representations (IR) separate the source-language specific front-end (lexical analysis, parsing, semantic analysis) from the target-machine specific back-end (instruction selection, register allocation, machine code generation).
-
By using a machine-independent intermediate code:
- Machine-independent optimizations (such as common subexpression elimination, loop invariant code motion, dead code elimination, and constant folding) can be implemented once on the IR.
- This optimizer module can then be reused across different source languages and target architectures without modifying machine-specific code.
-
Other options are incorrect:
- Parsing and semantic analysis precede intermediate code generation, so IR does not simplify them (option A).
- Error detection and reporting predominantly occur in the front-end (option B).
- Register allocation is an architecture-specific phase performed during target code generation (option D).
Hence, intermediate code allows reusing the machine-independent code optimizer in other compilers (option C).
C
Thinking intermediate code simplifies parsing, whereas parsing happens before intermediate code is generated.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2014 Computer Science and Information Technology (CS) Session 3
- Question
- 27 of 65, printed as CS Q.17
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.