Java Reference
In-Depth Information
FIGURE 5.2 The effect of various duplication instructions.
The table above suggests that all of this is very complicated, but there is a pattern here,
which we may take advantage of in clarifying what code to generate.
5.5.3 Factoring Assignment-Like Operations
The table above suggests four sub-operations common to most of the assignment-like oper-
ations in j--. They may also be useful if and when we want to extend j-- and when adding
additional operations. These four sub-operations are
1. codegenLoadLhsLvalue() { this generates code to load any up-front data for the
left-hand side of an assignment needed for an eventual store, that is, its l-value.
2. codegenLoadLhsRvalue() { this generates code to load the r-value of the left-hand
side, needed for implementing, for example, the += operator.
3. codegenDuplicateRvalue() { this generates code to duplicate an r-value on the stack
and put it in a place where it will be on top of the stack once the store is executed.
4. codegenStore() { this generates the code necessary to perform the actual store.
The code needed for each of these differs for each potential left-hand side of an assignment:
a simple local variable x , an indexed array element a[i] , an instance field o.f , and a static
field C.sf . The code necessary for each of the four operations, and for each left-hand side
form, is illustrated in the table below.
 
Search WWH ::




Custom Search