compiler interpreter and_bootstrapping

13

Click here to load reader

Upload: sandeep-manzhi

Post on 16-Jul-2015

132 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Compiler interpreter and_bootstrapping

01/04/15 1

Submitted to:-Sandeep Manzhi

TECHNOCRATS INSTITUTEOF TECHNOLOGY & SCIENCE

Bootstrapping

Page 2: Compiler interpreter and_bootstrapping

2

Bootstrapping

• a number of techniques which rely on partial/inefficient compiler version to create a full/better version

• often compiling a translator expressed in its own language

Page 3: Compiler interpreter and_bootstrapping

3

Full Bootstrapping

• A full bootstrap is necessary when we are building a new compiler from scratch.

• Example:• We want to implement an Ada

compiler for machine M. We don’t currently have access to any Ada compiler (not on M, nor on any other machine).

• Idea: Ada is very large, we will implement the compiler in a subset of Ada and bootstrap it from a subset of Ada compiler in another language. (e.g. C)

Page 4: Compiler interpreter and_bootstrapping

4

Full Bootstrapping continued

• Step 1: build a compiler for Ada-S in another language

Ada-S ->M

C

v1

Ada-S ->M

C

v1

Step 1a: build a compiler (v1) for Ada-S in another language.

Page 5: Compiler interpreter and_bootstrapping

5

Full bootstrapping

Ada-S ->M

C

v1

Ada-S->M

v1

Step 1b: Compile v1 compiler on M

M

C->M

MThis compiler can be used for bootstrapping on machine M but we do not want to rely on it permanently!

Page 6: Compiler interpreter and_bootstrapping

6

Full Bootstrapping continued

Ada-S ->M

Ada-S

v2

Step 2a: Implement v2 of Ada-S compiler in Ada-S

Ada-S ->M

Ada-S

v2

M

M

Ada-S->M

v2

Step 2b: Compile v2 compiler with v1 compiler

Ada-S ->M

M

v1

We are now no longer dependent on the availability of

a C compiler!

Page 7: Compiler interpreter and_bootstrapping

7

Full Bootstrapping continued

Step 3a: Build a full Ada compiler in Ada-S

Ada->M

Ada-S

v3

Step 3b: Compile with v2 compiler

M

Ada->M

v3

Ada-S ->MM

v2Ada->M

Ada-S

v3

M

From this point on we can maintain the compiler in Ada. Subsequent versions v4,v5,... of the compiler in Ada and compile each with the the previous version.

Page 8: Compiler interpreter and_bootstrapping

8

Half BootstrappingWe discussed full bootstrapping which is required when we have no access to a compiler for our language at all.

Q: What if we have access to an compiler for our language on a different machine HM but want to develop one for TM ?

Ada->HMHM

Ada->HMAda

Ada->TMTM

We have We want

Idea: we can use cross compilation from HM to TM to

bootstrap the TM compiler

Page 9: Compiler interpreter and_bootstrapping

Cross compiler:

running on HM but emits

TM code

9

Half Bootstrapping continued

Step 1: Implement Ada->TM compiler in Ada

Ada->TMAda

Step 2: Compile on HM

Ada->TMAda

HM

Ada->HMHM

Ada->TM

HM

Page 10: Compiler interpreter and_bootstrapping

10

Half Bootstrapping continued

Step 3: Cross compile our TM compiler.

Ada->TMAda Ada-

>TMHM

HM

DONE!

TM

From now on we can develop subsequent versions of the compiler completely on TM

Ada->TM

Page 11: Compiler interpreter and_bootstrapping

11

Bootstrap to improve efficiency

The efficiency of programs and compilers:Efficiency of programs:

- memory usage- runtime

Efficiency of compilers: - Efficiency of the compiler itself- Efficiency of the emitted code

Idea: We start from a simple compiler (generating inefficient code) and develop more sophisticated version of it. We can then use bootstrapping to improve performance of the compiler.

Page 12: Compiler interpreter and_bootstrapping

12

Bootstrap to improve efficiency

Ada->MslowAda

Ada-> MslowMslow

Ada->MfastAda

Ada->Mfast

Ada

M

Ada->MfastMslow

Step 1

Ada-> MslowMslow

We have We want

Page 13: Compiler interpreter and_bootstrapping

13

Bootstrap to improve efficiency

Step 2Ada->MfastAda

M

Ada->MfastMfastAda->

MfastMslow

Fast compiler that emits fast

code!