Java Reference
In-Depth Information
Can be further decomposed into a sequence of analysis phases such as that illustrated
in Figure 1.4.
FIGURE 1.4 The front end: Analysis.
The scanner is responsible for breaking the input stream of characters into a stream of
tokens: identifiers, literals, reserved words, (one-, two-, three-, and four-character) operators,
and separators.
The parser is responsible for taking this sequence of lexical tokens and parsing against a
grammar to produce an abstract syntax tree (AST), which makes the syntax that is implicit
in the source program, explicit.
The semantics phase is responsible for semantic analysis: declaring names in a symbol
table, looking up names as they are referenced for determining their types, assigning types
to expressions, and checking the validity of types. Sometimes, a certain amount of storage
analysis is also done, for example, assigning addresses or offsets to variables (as we do in our
j-- compiler). When a programming language allows one to refer to a name that is declared
later on in the program, the semantics phase must really involve at least two phases (or two
passes over the program).
1.3.2 Back End
A compiler's back end
Is that part of the compiler that takes the IR and produces (synthesizes) a target
machine program having the same meaning, and so
Is target language dependent (and source language independent); moreover, it
May be further decomposed into a sequence of synthesis phases such as that illustrated
in Figure 1.5.
FIGURE 1.5 The back end: Synthesis.
The code generation phase is responsible for choosing what target machine instructions
to generate. It makes use of information collected in earlier phases.
The peephole phase implements a peephole optimizer, which scans through the generated
instructions looking locally for wasteful instruction sequences such as branches to branches
and unnecessary load/store pairs (where a value is loaded onto a stack or into a register
and then immediately stored back at the original location).
Finally, the object phase links together any modules produced in code generation and
constructs a single machine code executable program.
 
Search WWH ::




Custom Search