patternModerate
Cross Compiler's T diagram
Viewed 0 times
crossdiagramcompiler
Problem
I'm studying Bootstrapping from Red Dragon Book Compilers and found the T diagram for cross compiler pretty confusing. I can't understand what is meant by "Run compiler1 through compiler2". Can anyone provide some better explanation, analogy or an example to relate with some real world compiler?
Some notation first. By
$LSN=$
I mean a compiler for language $L$
written in language $S$ that produces output language/machine code $N$.
This is a tombstone or T-diagrams.
Compiling a Compiler
-
Suppose we have cross-compiler for a new language L
in implementation language S generating code for machine N.
$LSN=$
-
Suppose we also have an existing S compiler running on machine M
implementing code for machine M:
$SMM=$
-
Run LSN through SMM to produce LMN
Compiler Construction
$LMN = LSN + SMM$
Some notation first. By
$LSN=$
I mean a compiler for language $L$
written in language $S$ that produces output language/machine code $N$.
This is a tombstone or T-diagrams.
Compiling a Compiler
-
Suppose we have cross-compiler for a new language L
in implementation language S generating code for machine N.
$LSN=$
-
Suppose we also have an existing S compiler running on machine M
implementing code for machine M:
$SMM=$
-
Run LSN through SMM to produce LMN
Compiler Construction
$LMN = LSN + SMM$
Solution
The T-diagrams (which you had omitted from the original version of your question) are crucial for understanding this sort of question. Let's look at the last T-diagram.
The first T describes a compiler from L to N written in S.
The second T describes a compiler from S to M written in M (or running on M). This will be your compiler compiler.
Applying the second T to the first T compiles the first T so that it runs on machine M. The result is thus a compiler from L to N running on machine M.
The fact that the second T also runs on machine M is captures that you are running the compiler compiler on the machine which you will run the compiler, rather than having to use a cross compiler (which would be the case if the bottom M were different).
The first T describes a compiler from L to N written in S.
The second T describes a compiler from S to M written in M (or running on M). This will be your compiler compiler.
Applying the second T to the first T compiles the first T so that it runs on machine M. The result is thus a compiler from L to N running on machine M.
The fact that the second T also runs on machine M is captures that you are running the compiler compiler on the machine which you will run the compiler, rather than having to use a cross compiler (which would be the case if the bottom M were different).
Context
StackExchange Computer Science Q#1281, answer score: 12
Revisions (0)
No revisions yet.