Akhil Kaushik
Asstt. Prof., CE Deptt.,
TIT Bhiwani
Bootstrapping
Translator
Compiling a Compiler
Tombstone Diagrams
• Diagrams consist of a set of “puzzle pieces” that
can be used to reason about language
processors and programs.
• Different kinds of pieces.
• Combination rules (not all diagrams are “well
formed”).
Tombstone Diagrams
• The rules for T-diagrams are very simple.
• A compiler written in some language “C” that
translates programs in language A to language B
looks like this:-
Tombstone Diagrams
Tombstone Diagrams
• The combination rules of Tombstone diagrams
can vary:
Tombstone Diagrams
• The combination rules of Tombstone diagrams
can vary:
Tombstone Diagrams
• Compilation of C programs on an x86 machine:
Bootstrapping
• It refers to the
seemingly
impossible task
of pulling oneself
up by the
bootstraps.
Bootstrapping
The idea of bootstrapping is quite simple:-
• You write your compiler in language A (but still let
it target B) and then let it compile itself. The result
is a compiler from A to B written in B.
• In order to use the compiler to compile a program,
we must already have compiled it, and to do this
we must use the compiler.
• In a way, it is a bit like the chicken-and-egg
paradox.
Bootstrapping
Note that the languages
match at every connection
and that the source and
target program aren't
standing on anything, as they
aren't executed in this
diagram.
Bootstrapping
• The basic idea in bootstrapping is to use compilers
to compile themselves or other compilers.
• Target -> we want a compiler for ML to Pentium
machine code and want this to run on a Pentium.
• We have -> an ML-compiler that generates HP
machine code and runs on an HP machine.
Bootstrapping
• One way of obtaining the desired compiler would
be to do binary translation, i.e.,
• Write a compiler from HP machine code to
Pentium machine code.
• This is a very tedious and herculean task and
some efficiency will be lost in it.
Bootstrapping
• A better solution is to write an ML-to-Pentium
compiler in ML (a high-level language).
• We can compile this using the ML compiler on the
HP:
Bootstrapping
• The output is: we get a program that converts ML
code into P code and now written in HP machine
code (a new compiler).
Bootstrapping
• Now, we can run the ML-to-Pentium compiler on
the HP and let it compile itself i.e. –
• We input our original program to the newly
generated compiler.
Bootstrapping
• Finally, we get the required compiler which
converts ML code into P code and also written in
P language (a low-level language).
Bootstrapping
• The whole process can be combined as follows:
Bootstrapping
Bootstrapping for Cross-compiler
• Cross-compiler: It’s a compiler which runs on
one machine (the host machine) but emits code
for another machine (the target machine).
• T-diagrams can help generating cross-compilers.
• For example, a compiler that runs on a Windows
10 PC but generates code that runs
on Android smartphone is a cross compiler.
Bootstrapping for Cross-compiler
• C “cross compiler” from x86 to PPC
Bootstrapping for Cross-compiler
• Two Stage Compilation: It is a combination of
2 translators. The output of the first translator is
provided as input to the second translator.
Akhil Kaushik
akhilkaushik05@gmail.com
9416910303
CONTACT ME AT:
Akhil Kaushik
akhilkaushik05@gmail.com
9416910303
THANK YOU !!!

Bootstrapping in Compiler

  • 1.
    Akhil Kaushik Asstt. Prof.,CE Deptt., TIT Bhiwani Bootstrapping
  • 2.
  • 3.
  • 4.
    Tombstone Diagrams • Diagramsconsist of a set of “puzzle pieces” that can be used to reason about language processors and programs. • Different kinds of pieces. • Combination rules (not all diagrams are “well formed”).
  • 5.
    Tombstone Diagrams • Therules for T-diagrams are very simple. • A compiler written in some language “C” that translates programs in language A to language B looks like this:-
  • 6.
  • 7.
    Tombstone Diagrams • Thecombination rules of Tombstone diagrams can vary:
  • 8.
    Tombstone Diagrams • Thecombination rules of Tombstone diagrams can vary:
  • 9.
    Tombstone Diagrams • Compilationof C programs on an x86 machine:
  • 10.
    Bootstrapping • It refersto the seemingly impossible task of pulling oneself up by the bootstraps.
  • 11.
    Bootstrapping The idea ofbootstrapping is quite simple:- • You write your compiler in language A (but still let it target B) and then let it compile itself. The result is a compiler from A to B written in B. • In order to use the compiler to compile a program, we must already have compiled it, and to do this we must use the compiler. • In a way, it is a bit like the chicken-and-egg paradox.
  • 12.
    Bootstrapping Note that thelanguages match at every connection and that the source and target program aren't standing on anything, as they aren't executed in this diagram.
  • 13.
    Bootstrapping • The basicidea in bootstrapping is to use compilers to compile themselves or other compilers. • Target -> we want a compiler for ML to Pentium machine code and want this to run on a Pentium. • We have -> an ML-compiler that generates HP machine code and runs on an HP machine.
  • 14.
    Bootstrapping • One wayof obtaining the desired compiler would be to do binary translation, i.e., • Write a compiler from HP machine code to Pentium machine code. • This is a very tedious and herculean task and some efficiency will be lost in it.
  • 15.
    Bootstrapping • A bettersolution is to write an ML-to-Pentium compiler in ML (a high-level language). • We can compile this using the ML compiler on the HP:
  • 16.
    Bootstrapping • The outputis: we get a program that converts ML code into P code and now written in HP machine code (a new compiler).
  • 17.
    Bootstrapping • Now, wecan run the ML-to-Pentium compiler on the HP and let it compile itself i.e. – • We input our original program to the newly generated compiler.
  • 18.
    Bootstrapping • Finally, weget the required compiler which converts ML code into P code and also written in P language (a low-level language).
  • 19.
    Bootstrapping • The wholeprocess can be combined as follows:
  • 20.
  • 21.
    Bootstrapping for Cross-compiler •Cross-compiler: It’s a compiler which runs on one machine (the host machine) but emits code for another machine (the target machine). • T-diagrams can help generating cross-compilers. • For example, a compiler that runs on a Windows 10 PC but generates code that runs on Android smartphone is a cross compiler.
  • 22.
    Bootstrapping for Cross-compiler •C “cross compiler” from x86 to PPC
  • 23.
    Bootstrapping for Cross-compiler •Two Stage Compilation: It is a combination of 2 translators. The output of the first translator is provided as input to the second translator.
  • 24.
    Akhil Kaushik akhilkaushik05@gmail.com 9416910303 CONTACT MEAT: Akhil Kaushik akhilkaushik05@gmail.com 9416910303 THANK YOU !!!