Q7Compiler Design
Question
2 marks
What is Intermediate Code?
Answer
Intermediate Code is a machine-independent, source-language-independent representation of the source program, generated between the front end and back end of the compiler.
Intermediate Code (Intermediate Representation, IR) is a form of the program generated by the compiler's front end and consumed by the back end. It is designed to be independent of both the source language and the target machine, making it easy to retarget the compiler and to perform machine-independent optimizations.
- Three-Address Code (TAC): Instructions of the form x = y op z, each with at most three addresses.
- Quadruples: Table form of TAC — each instruction stored as (op, arg1, arg2, result).
- Triples: Like quadruples but without the result field — results referenced by instruction number.
- DAG (Directed Acyclic Graph): Graph representation of basic block that identifies common subexpressions.
- Abstract Syntax Tree (AST): Tree form showing hierarchical structure of expressions and statements.
- Bytecode: Stack-based IR used by virtual machines (e.g., JVM bytecode).