Translation Models • Machine-dependent – Generate Machine Code • Directly • Through Intermediate Code • Machine-independent – Interpret the source code – Generate intermediate code and then interpret the intermediate code
Single Pass vs. Multi-pass • Single pass – No intermediate code – Limited code optimization – No intermediate files • Multi-pass – Intermediate code could be generated – Optimizations could be done on the intermediate code and the target code – Intermediate files created
Implementing Compilers (1/3) • Bootstrap a compiler for L to run on a bare machine M 1. Choose S subset of L S M 2. Write a Compiler for S to run on M M 3. Write a Compiler for L in S L M S 4. Compile L written in S using the S-Compiler L M L M M S S M M
Implementing Compilers (2/3) • Write a Cross Compiler for Language L that runs on machine (M) and generates code for machine (N). Assume that you have a compiler for L running on M L N M 1. Write a compiler in L in L that generate code for N L N L 2. Compile the compiler produced in step 1 on the compiler of L on M L N L N L M L M M
Implementing Compilers (3/3) • Cascading is the process of conducting compilation in two steps: 1. Compile a program written in L to produced Intermediate Code I 2. Compile the program produced in code I into machine code M L I I M M M
Recommend
More recommend