DV1465 / DV1505 / DV1511:

Compiler and Interpreter Technology

08:15 Wednesday 30th March, 2016

Representations and semantics of programs

Table of Contents
SemanticsBasic Blocks
RepresentationsSemantic Values
3-address codeAttribute Grammars vs Tree-rewriting

1. Compiler Structure

  • A compiler is a series of phases that transform the representation of a program.
  • In the analysis-synthesis model these split cleanly into two parts:
    • The front-end analyses the source program, to discover its meaning.
    • The back-end synthesizes an equivalent target program.

2. Semantics

  • As an example, one kind of equivalence is I/O equivalence.
  • Two programs are equal if we can't find an input that produces different outputs.
  • The semantics of the program could be represented by the I/O mapping.
  • They may differ in other behaviour we do not consider.

3. Semantics of a parse-tree : interpreter

  • The semantics of each part of the tree was defined locally.
    • A piece of code that executes the program in that part of the tree.
    • Recursive (hierarchical) definition of the semantics.
    • The meaning of a program was a combination of the meanings of its parts.

4. General features of the source language

5. The intermediate representation

6. Program Semantics

Main Theme.
How the program under compilation propagates through several equivalent representations during compilation.

7. Representation of Programs

Why use different representations?
The sub-problems that we must solve to manipulate code have different complexities on different representations.

8. Representations: Sequences

  • Lowest-level representation of programs.
    • The (linear) sequence of instructions is completely explicit (blue).
    • No way to represent loops, calls directly (green).
    • We need to add something (e.g. labels and jumps) to achieve this (red).
  • The placement of instructions is completely explicit.
    • But this may not reflect their execution order (superscalar despatch).
    • Modern processor is really reading a partial order of instructions.
    • This is still the representation in memory.
  • Data-flow is all implicit: match registers/values between instructions (green).

9. Representations: Trees

10. Representations: DAGs

11. Representations: Graphs

12. Standard choices

13. Intermediate Representation: 3-address code

14. Intermediate Representation: 3-address code

Break (15mins)


15. Intermediate Representation: Basic Blocks

16. Intermediate Representation: Control Flow Graph

17. The "code as data" Duality

18. Semantic Values

19. Semantic Values

20. Approaches

21. Attribute Grammar Approach

22. Synthetic and Inherited Attributes

23. Tree Rewriting Approach

24. Issue: Modularity

25. Issue: Tooling

26. Issue: Productivity Trade-off

27. Issue: Efficiency

28. Summary