Chapter 2: Introduction to compilers

How to translate?

The high level languages and machine languages differ in level of abstraction. At machine level we deal with memory locations, registers whereas these resources are never accessed in high level languages. But the level of abstraction differs from language to language and some languages are farther from machine code than others

. Goals of translation

- Good performance for the generated code

Good performance for generated code : The metric for the quality of the generated code is the ratio between the size of handwritten code and compiled machine code for same program. A better compiler is one which generates smaller code. For optimizing compilers this ratio will be lesser.

- Good compile time performance

Good compile time performance : A handwritten machine code is more efficient than a compiled code in terms of the performance it produces. In other words, the program handwritten in machine code will run faster than compiled code. If a compiler produces a code which is 20-30% slower than the handwritten code then it is considered to be acceptable. In addition to this, the compiler itself must run fast (compilation time must be proportional to program size).

- Maintainable code

- High level of abstraction

. Correctness is a very important issue.

Correctness : A compiler's most important goal is correctness - all valid programs must compile correctly. How do we check if a compiler is correct i.e. whether a compiler for a programming language generates correct machine code for programs in the language. The complexity of writing a correct compiler is a major limitation on the amount of optimization that can be done.

Can compilers be proven to be correct? Very tedious!

. However, the correctness has an implication on the development cost