File Lectures.html    Author McKeeman    Copyright © 2007    index

A Short Course in Compilers

Course Materials

These lectures are designed for a 10-session class. It is assumed that the students know MATLAB and introductory level college mathematics.

The planned course format is an hour of lecture followed by an hour of in-class lab work. There is not enough time to go into everything in a 10 meeting format. Much of the material is designed for home study. The student is encouraged to read the rest of the material after each class.

The overheads (links below) are designed for a classroom setting. They are useful mostly as bullets which show the order of classroom lecture subtopics. The overheads can be ignored during home study.

If a project is going to be attempted, it should be done simultaneously.

Order of Presentation

Most compilers, including xcom, have a front end and a back end corresponding the analysis and synthesis. This presentation of the front end follows the data flow in the compiler, lex to parse to tree to symbols. The presentation of the back end is in reverse order, assember to emitter to generator. This order is just one example of the old Polish proverb When crossing a swamp, keep one foot on solid ground. At each end of the compiler we have simplicity: ASCII text in, hardware instructions out. The data at each end can be understood on its own. The further we move towards the middle, the more new knowledge is in play.

Both ends to the middle is appropriate for xcom for another reason; the front end components transform inputs into explicit outputs, but the back end does not. In the front end there is a lex pass, a parse pass, a tree building pass, and a symbol table pass. Each front end component leaves behind an intermediate data structure. The back end components run simultaneously, each calling for services in the next component on the fly. This is not fundamental -- intermediate forms could have been invented and the back end could also have proceeded in passes. But it does not.

Lecture 1 (overheads)

Lab 1

Lecture 2 (overheads)

Lab 2

Lecture 3 (overheads)

Lab 3

Lecture 4 (overheads)

  • (10 min) Changing the xcom top-down Parser
  • (40 min) Parsing a programming language

Lab 4

Lecture 5 (overheads)

Lab 5

  • (60 min) Examine and test syntax trees and symbols tables.
  • Challenge: Adding abs to X (in Symbols.m)
  • Challenge: Rewrite Symbols.m so that it uses hash lookup.

Lecture 6 (overheads)

Lab 6

  • (60 min) Examine and test the use of the computing hardware.
  • Challenge: add abs to X (in AsmX86.m)
  • Challenge: Implement AsmA64.m

Lecture 7 (overheads)

Lab 7

  • (05 min) Read about changing the xcom code emitter
  • (05 min) Read about changing the xcom generator
  • (50 min) Examine and test code selection.
  • Challenge: Add abs to X (in EmitX86.m and Generator.m)
  • Challenge: Implement EmitA64.m (Intel 64-bit)

Lecture 8 (overheads)

Lab 8

  • (60 min) Experiment with GEM

Lecture 9 (overheads)

  • (20 min) Tradeoffs between interpreters, JITs and production compilers
  • (30 min) Conventional Optimization Strategies

Lab 9

  • Add an instruction to the mxcom emulator:
          >> edit mxcom/m/EmulateX86
    See the Intel X86 reference for details.
  • Challenge: Compare the speed of a C compiler at various levels of optimization. Compare the speed of the compiled C code for each.
  • Challenge: Implement Constant Folding for X as a peephole.

Lecture 10

Lab 10

Final Exam