The big picture

T-Diagrams

Compose compilers drawn as T-diagrams to model cross compilers, retargeting, and bootstrapping.

  • Lecture reference: Intro (cont’d): Preprocessors, bootstrapping, history · slides 3–8

Bootstrapping a compiler

Lecture reference: Intro (cont’d): Preprocessors, bootstrapping, history · slide 8

Given machine M and language L, build T(L → M / M) from an L → M compiler written in L′ and a quick L′ compiler written in M. L′ is a simple subset of L; M′ is inefficient M-code, which runs on M.

But what about first compilers? Lecture reference: Intro (cont’d): Preprocessors, bootstrapping, history · slide 7

Show answer

A compiler for L can be written in L itself without a pre-existing L compiler: write it in a simple subset L′, compile it once with a quick L′ compiler written in machine code, then compile it again with the result. That is bootstrapping.

Bootstrapping, step by step

Lecture reference: Intro (cont’d): Preprocessors, bootstrapping, history · slide 8
Step 1 of 5
Given machine M and language L, we want T(L → M / M): an L → M compiler that runs on M. Writing it directly is tough.
  • L′ is simple subset of L
  • M′ is inefficient M-code
Given machine Mand language LBut toughdirectly!Want thisGiven machine Mand language LBut toughdirectly!Want this

Workbench

Want this T(L → M / M) Not yet
1compile2with

Press Enter to choose a diagram for Compose: first the one to compile, then the translator. With a pointer, drag a diagram onto another one’s left arm.

sourcetargethost

T(L → M / L′) translates L to M and is written in L′.

Drag a diagram onto another one’s left arm, or choose two above and press Compose. The first is compiled; the second, the translator, must read the language the first is written in and must run directly.

Toolbox 2 of 12

T(S → T / H) translates S to T and is written in H. Type ' for a prime (L' → L′, L'' → L″) and _ for a subscript (M_OTHER → MOTHER).

Diagrams

Subsets

A compiler written in a subset can be translated by one that reads the larger language.

Run directly

Machine languages, separated by commas. A translator must be written in one of them (or in a subset of one).

Goal

Retargetable compiler architecture

Lecture reference: Intro (cont’d): Preprocessors, bootstrapping, history · slide 6
Separate compilers
3 × 3 = 9
Components
3 + 1 + 3 = 7
CFortranAdaX86PowerPCARMC FrontendFortran FrontendAda FrontendCommonOptimizerX86 BackendPowerPC BackendARM Backend

Languages 3

  • C
  • Fortran
  • Ada

Targets 3

  • X86
  • PowerPC
  • ARM