Pilers and Interpreters
Pilers and Interpreters
Examples of translators:
– compilers
– assemblers
– high-level translators
– decompilers.
3-2
Translators (2)
3-3
Translators (3)
3-4
Interpreters (1)
3-5
Interpreters (2)
3-6
Interpreters (3)
3-7
Example of interpreters (1)
Basic interpreter:
– A Basic program is a sequence of simple commands
linked by unconditional and conditional jumps.
– The Basic interpreter fetches, parses, and executes
one simple command at a time.
JVM interpreter:
– A JVM program consists of “bytecodes”.
– The interpreter fetches, decodes, and executes one
bytecode at a time.
– Note: The JVM interpreter is available stand-alone
(java) or as a component of a web browser.
3-8
Example of interpreters (2)
3-9
Compilers vs interpreters
3-10
Tombstone diagrams
Software:
P
an ordinary program P,
L expressed in language L
S → T
an S → T translator,
L expressed in language L
S
an S interpreter,
L expressed in language L
Hardware:
M a machine M (which can only
execute M ’s machine code)
3-11
Examples: tombstones (1)
Ordinary programs:
Interpreters:
JVM JVM Basic
C x86 x86
3-12
Examples: tombstones (2)
Translators:
Java → JVM C → x86as C → x86
C x86 x86
3-13
Tombstone diagrams: running programs
P
M
these must match
M
3-14
Examples: running ordinary programs
Possible:
sort sort
x86 PPC
x86 PPC
Impossible:
sort sort
× ×
x86 C
PPC PPC
3-15
Tombstone diagrams: translation
Given:
– an S → T translator, expressed in M machine code
– a program P, expressed in language S
P P
object
S S → T T program
M
these these must
must M match
match
3-16
Example: compiling a program
compile-time run-time
3-17
Example: compiling a program in stages
compile-time run-time
3-18
Example: cross-compiling a program
compile-time run-time
3-19
Example: compiling a compiler
3-20
Examples: what can and can’t be done
Possible:
phone phone
Java4 Java5→JVM JVM
OK – Java4 is a PPC
subset of Java5 PPC
Impossible:
phone
C → PPC
Java C → PPC
PPC
x86× × PPC
PPC
3-21
Tombstone diagrams: interpretation
Given:
– an S interpreter, expressed in M machine code
– a program P, expressed in language S
we can interpret P:
P
S
these must match
S
M
these must match
M
3-22
Examples: interpreting ordinary
programs
Possible: Impossible:
sort sort
×
Basic C
Basic Basic
PPC PPC
PPC PPC
3-23
Real machines vs virtual machines
3-24
Example: hardware emulation (1)
3-25
Example: hardware emulation (2)
3-26
Example: hardware emulation (3)
3-27
Interpretive compilers (1)
3-28
Interpretive compilers (2)
3-30
Example: JDK (2)
3-31
Example: JDK (3)
3-32
Example: JDK (4)
3-34
Example: a Java JIT compiler
3-35
Selective JIT compilers
3-36
Portable compilers
3-37
Example: portable compiler kit (1)
3-38
Example: portable compiler kit (2)
3-39
Example: portable compiler kit (3)
3-42
Example: bootstrapping (2)
3-43
Example: bootstrapping (3)
3-44
Example: bootstrapping (4)
3-45
Example: bootstrapping (5)
3-46