Download presentation
Presentation is loading. Please wait.
1
T-diagrams “Mommy, where do compilers come from?” Adapted from: http://www.cse.buffalo.edu/~drpierce/cse/443S2005/lectures/T-diagrams.ppt
2
T-diagrams Different diagrams for different kinds of programs Visual explanation of interactions involving compilers and interpreters
3
Programs Program P written in language L Example: Sort program written in Java L P Java sort
4
Machines Machine executing language M Example: Sun workstation executing SPARC machine code Msparc
5
Executing Programs Program implementation language must match machine sparc sort sparc
6
Interpreters Interpreter executing language L written in language M Example: Lisp interpreter running on sparc L M Lisp sparc
7
Interpreting Programs Interpreter mediates between programming language and machine language Lisp sort sparc Lisp sparc
8
Virtual Machines Interpreter creates a “virtual machine” Lisp sort sparc Lisp sparcLisp sort Lisp
9
Compilers Compiler translating from source language S to target language T implemented in M Example: C compiler for sparc platform ST M C sparc -->
10
Compiling Programs Compiler inputs program in source language, outputs in target language C sort C sparc sort sparc sort sparc
11
Compiler Correctness Compiled target program has the same meaning as the source program sparc sort sparc C sort C ==
12
Java Programming Environment Javac : Java to Java byte code (JBC) compiler Java : Java Virtual Machine byte code interpreter Java JBC MJava P JBC P P M M M “javac”“java”
13
Where Do Compilers Come From? 1. Write it in machine code L M M A lot of work
14
Where Do Compilers Come From? 1. Write it in machine code 2. Write it in a lower level language and compile it using an existing compiler L M C C M M L M M But where did the C compiler come from?
15
Where Do Compilers Come From? 1. Write it in machine code 2. Write it in a lower level language and compile it using an existing compiler 3. Write it in the same language that it compiles and bootstrap L M L
16
Bootstrapping a Compiler Write the compiler in its own language (#0) Write a simple native compiler (#1) Use compiler #1 to compile #0 to get native compiler with more frills (#2) Repeat as desired
17
Bootstrapping a Compiler L M L L --> M M L M M #0 (the real thing) #1 (simple) #2 (real thing compiled)
18
Bootstrapping a Compiler, Stage 2 L M L L M M L M M #0 (the real thing) #2 (the real thing compiled) #3 (compiled with the real thing) Consistency test: #2 = #3 literally
19
Porting a Compiler 1. Rewrite back end to target new machine 1. Compile on new machine L M C L N C
20
Porting a Compiler 1. Rewrite back end to target new machine 1. Compile on new machine L N C C N N L N N
21
Porting a Compiler II Rewrite back end to target new machine Compile using native compiler L N L L M M L N M “cross compiler”
22
Cross Compilers A cross compiler compiles to a target language different from the language of the machine it runs on
23
Porting a Compiler II Rewrite back end to target new machine Compile using native compiler Recompile using cross compiler L N L L N M L N N
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.