Java Reference
In-Depth Information
The IDIV instruction is a zero-argument instruction. The operands that it operates on
must to be loaded on the operand stack prior to executing the instruction.
Testing the Changes
Finally, we need to test the addition of the new (division operator) construct to j--. This
can be done at the command prompt by running
>ant
which compiles our tests using the hand-written scanner and parser, and then tests them.
The results of compiling and running the tests are written to the console ( STDOUT ).
Alternatively, one could compile and run the tests using Eclipse; Appendix A describes
how.
1.6 Organization of This Topic
This topic is organized like a compiler. You may think of this rst chapter as the main
program, the driver if you like. It gives the overall structure of compilers in general, and of
our j-- compiler in particular.
In Chapter 2 we discuss the scanning of tokens, that is, lexical analysis.
In Chapter 3 we discuss context-free grammars and parsing. We first address the re-
cursive descent parsing technique, which is the strategy the parser uses to parse j--. We
then go on to examine the LL and LR parsing strategies, both of which are used in various
compilers today.
In Chapter 4 we discuss type checking, or semantic analysis. There are two passes re-
quired for this in the j-- compiler, and we discuss both of them. We also discuss the use of
attribute grammars for declaratively specifying semantic analysis.
In Chapter 5 we discuss JVM code generation. Again we address the peculiarities of code
generation in our j-- compiler, and then some other more general issues in code generation.
In Chapter 6 we discuss translating JVM code to instructions native to a MIPS com-
puter; MIPS is a register-based RISC architecture. We discuss what is generally called
optimization, a process by which the compiler produces better (that is, faster and smaller)
target programs. Although our compiler has no optimizations other than register allocation,
a general introduction to them is important.
In Chapter 7 register allocation is the principal challenge.
In Chapter 8 we discuss several celebrity compilers.
Appendix A gives instructions on setting up a j-- development environment.
Appendix B contains the lexical and syntactic grammar for j--.
Appendix C contains the lexical and syntactic grammar for Java.
Appendix D describes the CLEmitter interface and also provides a group-wise summary
of the JVM instruction set.
Appendix E describes James Larus's SPIM simulator for the MIPS family of computers
and how to write j-- programs that target SPIM.
 
Search WWH ::




Custom Search