Java Reference
In-Depth Information
optimizer. However, it can significantly improve code and is often useful for
“cleaning up” after earlier compiler phases.
1.5.7 The Code Generator
The IR code produced by the translator is mapped into target machine code by
the code generator . This phase requires detailed information about the target
machine and includesmachine-specific optimization such as register allocation
and code scheduling. Normally, code generators are hand-coded and can be
quite complex, since generation of good target code requires consideration of
many special cases.
The notion of automatic construction of code generators has been actively
studied. The basic approach is to match a low-level IR to target-instruction
templates, with the code generator automatically choosing instructions that
bestmatch IR instructions. This approach localizes the target-machine specifics
of a compiler and, at least in principle, makes it easy to retarget a compiler
to a new target machine. Automatic retargeting is an especially desirable
goal, since a great deal of work is usually needed to move a compiler to a
new machine. The ability to retarget by simply changing the set of target
machine templates and generating (from the templates) a new code generator
is compelling.
A well-known compiler using these techniques is the GCC [GNU]. GCC
is a heavily optimizing compiler that can target over thirty computer architec-
tures (including Intel R
,Sparc TM ,andPowerPC R
) and has at least six front
ends (including C, C
++
,Fortran,Ada,andJava).
1.5.8 Compiler Writing Tools
Finally, note that in discussing compiler design and construction, we often talk
of compiler writing tools . These are often packaged as compiler generators
or compiler compilers . Such packages usually include scanner and parser
generators. Some also include symbol table managers, attribute grammar
evaluators, and code-generation tools. More advanced packages may aid in
error repair generation.
These sorts of generators greatly assist the crafting of compilers, but much
of the e
ort in crafting a compiler lies in writing and debugging the semantic
phases. These routines can be numerous (a type checker and translator is
apparently needed for each distinct AST node) and are usually hand coded.
Judicious application of the visitor pattern can significantly reduce this e
ff
ort
and make the compiler easier to maintain. Chapters 2 and 7 introduce ap-
plication of the visitor pattern to semantic analysis. This treatment continues
beyond Chapter 7 as specific semantic issues are addressed.
ff
 
 
 
Search WWH ::




Custom Search