
Chapter 5
JVM Code Generation
5.1 Introduction
Once the AST has been fully analyzed, all variables and expressions have been typed and
any necessary tree rewriting has been done. Also a certain amount of setup needed for code
generation has been accomplished. The compiler is now ready to traverse the AST one more
time to generate the Java Virtual Machine (JVM) code, that is, build the class file for the
program.
For example, consider the following very simple program:
public class Square {
public int square ( int x) {
return x * x ;
}
}
Compiling this with our j-- compiler,
> $j / j - -/ bin/j - - Square . java
produces a class file, Square.class. If we run