OK. Here's the deal. Way back when, compiler specialists implemented
an idea called bootstrapping. What's bootstrapping? You break a compiler
into 5 different section. The later sections are machine dependant, but
the first sections can be re-used for any machine on any platform. How
can it be re-used? (next section)
Highlevel instructions are automatically translated into a tripplet or
a quadrouplet (i'll call them trips or quads from here on). A trip or
a quad is a machine independent pseudo assembly language.
eg:
a = b + c * e;
* c e t1
+ b t1 t2
= t2 0 a
This is a quad example. The first column is the operation to
perform. The second and third are the operands and the fourth
column is where to store the result of the operation.
Note : t1 t2 ... refer to temporary variable. These could represent
actual memory locations or registers down the line
The quads generated say the following:
multiply 'c' and 'e' and store the result in 't1'
add 'b' and 't1' and store the result in 't2'
copy 't2' and store it into 'a' (0 is an empty operand)
These quads are not optimized yet. Durring compilation, the computer
has no way of knowing whats coming next so it store results in temps
and uses alot of them.
Here's where machine independant optimization comes into play.
* c e t1
+ b t1 t2
= t2 0 a
These quads can be optimized simply by storing the last
addition result in a
* c e t1
+ b t1 a
These have the same effect. However, this basic block can be
reduced to variables only by noting that 'a' never is used in
the formula and 'a' can be used as a temp variable
* c e a
+ b a a
This is an example of machine independant optimization, and guess what?
Most compilers are made using the bootstrapping method so If I wrote
a pascal compiler and c++ compiler I could re-use the optimizer and
code generator for both.
Parts of a compiler
scanner -> parser -> intermediate code generator -> optimizer -> code
generatro
The optimization spoken of lately resides in the code generator for
machine specific optimization.
--- GEcho 1.00
---------------
* Origin: Digital OnLine Magazine! - (409)838-8237 (1:3811/350)
|