COMS W4115
Programming Languages and Translators
Lecture 15: Intermediate Representations
October 28, 2009
Lecture Outline
- Review
- Intermediate representations
- Three-address code
- Semantic analysis
- Types
1. Review
- Syntax-directed definitions and translation schemes
- Synthesized and inherited attributes
- S-attributed SDDs
- L-attributed SDDs
2. Intermediate Representations
- High-level IR
- Low-level IR
- Syntax trees
- Directed acyclic graphs
- Algorithm 6.3: Value-number method for constructing a DAG (p. 361)
3. Three-Address Code
- Three-address instructions
- Representations for three-address code
- Records
- Quadruples
- Triples
- Static single-assignment form
4. Semantic Analysis
- Uses made of semantic information for a variable
x.
- What kind of value is stored in
x?
- How big is
x?
- Who is responsible for allocating space for
x?
- Who is responsible for initializing
x?
- How long must the value of
x be kept?
- If
x is a procedure, what kinds of arguments does it take and what
kind of return value does it have?
- Storage layout for local names
5. Types
- Type expressions
- Rules for constructing type expressions
- Type equivalence
- Are the following two type declarations in C equivalent?
struct TreeNode { struct Node {
int value; int value;
struct TreeNode *left; struct Node *left;
struct TreeNode *right; struct Node * right;
} }
Forms of type equivalence
- Name equivalence: two types are equivalent iff they have the same name.
- Structural equivalence: two types are equivalent iff they have the same structure.
- To test for structural equivalence, a compiler must encode the structure
of a type in its representation. A tree (or type graph) is typically
used.
6. Reading
aho@cs.columbia.edu