T-Diagrams
Compose compilers drawn as T-diagrams to model cross compilers, retargeting, and bootstrapping.
- Lecture reference: Intro (cont’d): Preprocessors, bootstrapping, history
Bootstrapping a compiler
Lecture reference: Intro (cont’d): Preprocessors, bootstrapping, historyGiven 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
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
- L′ is simple subset of L
- M′ is inefficient M-code
Workbench
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.
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
Goal
Retargetable compiler architecture
- Separate compilers
- 3 × 3 = 9
- Components
- 3 + 1 + 3 = 7
Languages 3
- C
- Fortran
- Ada
Targets 3
- X86
- PowerPC
- ARM