public class CodeGenerator extends TreeVisitor implements Opcode
FlowGraph| Modifier and Type | Field and Description |
|---|---|
static boolean |
DB_OPT_STACK |
static boolean |
DEBUG |
protected MethodEditor |
method |
protected Block |
next |
boolean |
nowb |
static boolean |
OPT_STACK
Use information about placement of local variables to eliminate loads and
stores in favor of stack manipulations
|
protected java.util.Map |
postponedInstructions |
protected int |
stackHeight |
static boolean |
USE_PERSISTENT |
protected java.util.Set |
visited |
FORWARD, REVERSEopc_aaload, opc_aastore, opc_aconst_null, opc_aload, opc_aload_0, opc_aload_1, opc_aload_2, opc_aload_3, opc_anewarray, opc_areturn, opc_arraylength, opc_astore, opc_astore_0, opc_astore_1, opc_astore_2, opc_astore_3, opc_aswizzle, opc_aswrange, opc_athrow, opc_aupdate, opc_baload, opc_bastore, opc_bipush, opc_breakpoint, opc_caload, opc_castore, opc_checkcast, opc_d2f, opc_d2i, opc_d2l, opc_dadd, opc_daload, opc_dastore, opc_dcmpg, opc_dcmpl, opc_dconst_0, opc_dconst_1, opc_ddiv, opc_dload, opc_dload_0, opc_dload_1, opc_dload_2, opc_dload_3, opc_dmul, opc_dneg, opc_drem, opc_dreturn, opc_dstore, opc_dstore_0, opc_dstore_1, opc_dstore_2, opc_dstore_3, opc_dsub, opc_dup, opc_dup_x1, opc_dup_x2, opc_dup2, opc_dup2_x1, opc_dup2_x2, opc_f2d, opc_f2i, opc_f2l, opc_fadd, opc_faload, opc_fastore, opc_fcmpg, opc_fcmpl, opc_fconst_0, opc_fconst_1, opc_fconst_2, opc_fdiv, opc_fload, opc_fload_0, opc_fload_1, opc_fload_2, opc_fload_3, opc_fmul, opc_fneg, opc_frem, opc_freturn, opc_fstore, opc_fstore_0, opc_fstore_1, opc_fstore_2, opc_fstore_3, opc_fsub, opc_getfield, opc_getstatic, opc_goto, opc_goto_w, opc_i2b, opc_i2c, opc_i2d, opc_i2f, opc_i2l, opc_i2s, opc_iadd, opc_iaload, opc_iand, opc_iastore, opc_iconst_0, opc_iconst_1, opc_iconst_2, opc_iconst_3, opc_iconst_4, opc_iconst_5, opc_iconst_m1, opc_idiv, opc_if_acmpeq, opc_if_acmpne, opc_if_icmpeq, opc_if_icmpge, opc_if_icmpgt, opc_if_icmple, opc_if_icmplt, opc_if_icmpne, opc_ifeq, opc_ifge, opc_ifgt, opc_ifle, opc_iflt, opc_ifne, opc_ifnonnull, opc_ifnull, opc_iinc, opc_iload, opc_iload_0, opc_iload_1, opc_iload_2, opc_iload_3, opc_imul, opc_ineg, opc_instanceof, opc_invokeinterface, opc_invokespecial, opc_invokestatic, opc_invokevirtual, opc_ior, opc_irem, opc_ireturn, opc_ishl, opc_ishr, opc_istore, opc_istore_0, opc_istore_1, opc_istore_2, opc_istore_3, opc_isub, opc_iushr, opc_ixor, opc_jsr, opc_jsr_w, opc_l2d, opc_l2f, opc_l2i, opc_ladd, opc_laload, opc_land, opc_lastore, opc_lcmp, opc_lconst_0, opc_lconst_1, opc_ldc, opc_ldc_w, opc_ldc2_w, opc_ldiv, opc_lload, opc_lload_0, opc_lload_1, opc_lload_2, opc_lload_3, opc_lmul, opc_lneg, opc_lookupswitch, opc_lor, opc_lrem, opc_lreturn, opc_lshl, opc_lshr, opc_lstore, opc_lstore_0, opc_lstore_1, opc_lstore_2, opc_lstore_3, opc_lsub, opc_lushr, opc_lxor, opc_monitorenter, opc_monitorexit, opc_multianewarray, opc_new, opc_newarray, opc_nop, opc_pop, opc_pop2, opc_putfield, opc_putfield_nowb, opc_putstatic, opc_putstatic_nowb, opc_rc, opc_ret, opc_return, opc_saload, opc_sastore, opc_sipush, opc_supdate, opc_swap, opc_tableswitch, opc_wide, opc_xxxunusedxxx, opcNames, opcSize, opcx_aaload, opcx_aastore, opcx_aload, opcx_areturn, opcx_arraylength, opcx_astore, opcx_aswizzle, opcx_aswrange, opcx_athrow, opcx_aupdate, opcx_baload, opcx_bastore, opcx_caload, opcx_castore, opcx_checkcast, opcx_d2f, opcx_d2i, opcx_d2l, opcx_dadd, opcx_daload, opcx_dastore, opcx_dcmpg, opcx_dcmpl, opcx_ddiv, opcx_dload, opcx_dmul, opcx_dneg, opcx_drem, opcx_dreturn, opcx_dstore, opcx_dsub, opcx_dup, opcx_dup_x1, opcx_dup_x2, opcx_dup2, opcx_dup2_x1, opcx_dup2_x2, opcx_f2d, opcx_f2i, opcx_f2l, opcx_fadd, opcx_faload, opcx_fastore, opcx_fcmpg, opcx_fcmpl, opcx_fdiv, opcx_fload, opcx_fmul, opcx_fneg, opcx_frem, opcx_freturn, opcx_fstore, opcx_fsub, opcx_getfield, opcx_getstatic, opcx_goto, opcx_i2b, opcx_i2c, opcx_i2d, opcx_i2f, opcx_i2l, opcx_i2s, opcx_iadd, opcx_iaload, opcx_iand, opcx_iastore, opcx_idiv, opcx_if_acmpeq, opcx_if_acmpne, opcx_if_icmpeq, opcx_if_icmpge, opcx_if_icmpgt, opcx_if_icmple, opcx_if_icmplt, opcx_if_icmpne, opcx_ifeq, opcx_ifge, opcx_ifgt, opcx_ifle, opcx_iflt, opcx_ifne, opcx_ifnonnull, opcx_ifnull, opcx_iinc, opcx_iload, opcx_imul, opcx_ineg, opcx_instanceof, opcx_invokeinterface, opcx_invokespecial, opcx_invokestatic, opcx_invokevirtual, opcx_ior, opcx_irem, opcx_ireturn, opcx_ishl, opcx_ishr, opcx_istore, opcx_isub, opcx_iushr, opcx_ixor, opcx_jsr, opcx_l2d, opcx_l2f, opcx_l2i, opcx_ladd, opcx_laload, opcx_land, opcx_lastore, opcx_lcmp, opcx_ldc, opcx_ldiv, opcx_lload, opcx_lmul, opcx_lneg, opcx_lor, opcx_lrem, opcx_lreturn, opcx_lshl, opcx_lshr, opcx_lstore, opcx_lsub, opcx_lushr, opcx_lxor, opcx_monitorenter, opcx_monitorexit, opcx_multianewarray, opcx_new, opcx_newarray, opcx_nop, opcx_pop, opcx_pop2, opcx_putfield, opcx_putfield_nowb, opcx_putstatic, opcx_putstatic_nowb, opcx_rc, opcx_ret, opcx_return, opcx_saload, opcx_sastore, opcx_supdate, opcx_swap, opcx_switch, opcXMap, VARIABLE| Constructor and Description |
|---|
CodeGenerator(MethodEditor method)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
allocReturnAddresses(FlowGraph cfg,
RegisterAllocator alloc)
Allocate "registers" (LocalVariables) for the return addresses for each
subroutine in the method.
|
protected Stmt |
createStore(VarExpr target,
Expr source)
Returns an ExprStmt that contains a store of the source into the target.
|
protected Stmt |
createUndefinedStore(VarExpr target)
Create a ExprStmt that initializes a target variable to a default value
based on the type of the target.
|
void |
replacePhis(FlowGraph cfg)
Replace PhiStmts with copies that accomplish what the PhiStmts represent.
|
void |
simplifyControlFlow(FlowGraph cfg)
Simplifies the control flow of a method by changing jump and return
statements into gotos where appropriate.
|
void |
visitAddressStoreStmt(AddressStoreStmt stmt) |
void |
visitArithExpr(ArithExpr expr) |
void |
visitArrayLengthExpr(ArrayLengthExpr expr) |
void |
visitArrayRefExpr(ArrayRefExpr expr) |
void |
visitCallMethodExpr(CallMethodExpr expr) |
void |
visitCallStaticExpr(CallStaticExpr expr) |
void |
visitCastExpr(CastExpr expr) |
void |
visitCatchExpr(CatchExpr expr) |
void |
visitConstantExpr(ConstantExpr expr) |
void |
visitDefExpr(DefExpr expr) |
void |
visitExpr(Expr expr) |
void |
visitExprStmt(ExprStmt stmt) |
void |
visitFieldExpr(FieldExpr expr) |
void |
visitFlowGraph(FlowGraph cfg)
Visits the nodes in the method's control flow graph and ensures that
information about the method's basic blocks is consistent and correct.
|
void |
visitGotoStmt(GotoStmt stmt) |
void |
visitIfCmpStmt(IfCmpStmt stmt) |
void |
visitIfZeroStmt(IfZeroStmt stmt) |
void |
visitInitStmt(InitStmt stmt) |
void |
visitInstanceOfExpr(InstanceOfExpr expr) |
void |
visitJsrStmt(JsrStmt stmt) |
void |
visitLabelStmt(LabelStmt stmt) |
void |
visitLocalExpr(LocalExpr expr) |
void |
visitMonitorStmt(MonitorStmt stmt) |
void |
visitNegExpr(NegExpr expr) |
void |
visitNewArrayExpr(NewArrayExpr expr) |
void |
visitNewExpr(NewExpr expr) |
void |
visitNewMultiArrayExpr(NewMultiArrayExpr expr) |
void |
visitPhiStmt(PhiStmt stmt) |
void |
visitRCExpr(RCExpr expr) |
void |
visitRetStmt(RetStmt stmt) |
void |
visitReturnAddressExpr(ReturnAddressExpr expr) |
void |
visitReturnExprStmt(ReturnExprStmt stmt) |
void |
visitReturnStmt(ReturnStmt stmt) |
void |
visitSCStmt(SCStmt stmt) |
void |
visitShiftExpr(ShiftExpr expr) |
void |
visitSRStmt(SRStmt stmt) |
void |
visitStackExpr(StackExpr expr) |
void |
visitStackManipStmt(StackManipStmt stmt) |
void |
visitStaticFieldExpr(StaticFieldExpr expr) |
void |
visitStoreExpr(StoreExpr expr) |
void |
visitSwitchStmt(SwitchStmt stmt) |
void |
visitThrowStmt(ThrowStmt stmt) |
void |
visitUCExpr(UCExpr expr) |
void |
visitZeroCheckExpr(ZeroCheckExpr expr) |
direction, forward, prune, reverse, setPrune, visitBlock, visitCallExpr, visitCheckExpr, visitIfStmt, visitMemExpr, visitMemRefExpr, visitNode, visitPhiCatchStmt, visitPhiJoinStmt, visitStmt, visitTree, visitVarExprpublic static boolean DEBUG
public static boolean USE_PERSISTENT
public static boolean OPT_STACK
public static boolean DB_OPT_STACK
protected MethodEditor method
protected java.util.Set visited
protected java.util.Map postponedInstructions
protected Block next
protected int stackHeight
public boolean nowb
public CodeGenerator(MethodEditor method)
method - The method for which bytecode is generated.public void visitFlowGraph(FlowGraph cfg)
visitFlowGraph in class TreeVisitorcfg - The control flow graph associated with this method.public void simplifyControlFlow(FlowGraph cfg)
public void replacePhis(FlowGraph cfg)
public void allocReturnAddresses(FlowGraph cfg, RegisterAllocator alloc)
cfg - Control flow graph for the methodalloc - Allocation (and information about) the local variables in the
method.LocalVariable,
LocalExprprotected Stmt createUndefinedStore(VarExpr target)
protected Stmt createStore(VarExpr target, Expr source)
public void visitExpr(Expr expr)
visitExpr in class TreeVisitorpublic void visitExprStmt(ExprStmt stmt)
visitExprStmt in class TreeVisitorpublic void visitInitStmt(InitStmt stmt)
visitInitStmt in class TreeVisitorpublic void visitGotoStmt(GotoStmt stmt)
visitGotoStmt in class TreeVisitorpublic void visitIfCmpStmt(IfCmpStmt stmt)
visitIfCmpStmt in class TreeVisitorpublic void visitIfZeroStmt(IfZeroStmt stmt)
visitIfZeroStmt in class TreeVisitorpublic void visitLabelStmt(LabelStmt stmt)
visitLabelStmt in class TreeVisitorpublic void visitMonitorStmt(MonitorStmt stmt)
visitMonitorStmt in class TreeVisitorpublic void visitPhiStmt(PhiStmt stmt)
visitPhiStmt in class TreeVisitorpublic void visitRCExpr(RCExpr expr)
visitRCExpr in class TreeVisitorpublic void visitUCExpr(UCExpr expr)
visitUCExpr in class TreeVisitorpublic void visitRetStmt(RetStmt stmt)
visitRetStmt in class TreeVisitorpublic void visitReturnExprStmt(ReturnExprStmt stmt)
visitReturnExprStmt in class TreeVisitorpublic void visitReturnStmt(ReturnStmt stmt)
visitReturnStmt in class TreeVisitorpublic void visitStoreExpr(StoreExpr expr)
visitStoreExpr in class TreeVisitorpublic void visitAddressStoreStmt(AddressStoreStmt stmt)
visitAddressStoreStmt in class TreeVisitorpublic void visitJsrStmt(JsrStmt stmt)
visitJsrStmt in class TreeVisitorpublic void visitSwitchStmt(SwitchStmt stmt)
visitSwitchStmt in class TreeVisitorpublic void visitStackManipStmt(StackManipStmt stmt)
visitStackManipStmt in class TreeVisitorpublic void visitThrowStmt(ThrowStmt stmt)
visitThrowStmt in class TreeVisitorpublic void visitSCStmt(SCStmt stmt)
visitSCStmt in class TreeVisitorpublic void visitSRStmt(SRStmt stmt)
visitSRStmt in class TreeVisitorpublic void visitArithExpr(ArithExpr expr)
visitArithExpr in class TreeVisitorpublic void visitArrayLengthExpr(ArrayLengthExpr expr)
visitArrayLengthExpr in class TreeVisitorpublic void visitArrayRefExpr(ArrayRefExpr expr)
visitArrayRefExpr in class TreeVisitorpublic void visitCallMethodExpr(CallMethodExpr expr)
visitCallMethodExpr in class TreeVisitorpublic void visitCallStaticExpr(CallStaticExpr expr)
visitCallStaticExpr in class TreeVisitorpublic void visitCastExpr(CastExpr expr)
visitCastExpr in class TreeVisitorpublic void visitConstantExpr(ConstantExpr expr)
visitConstantExpr in class TreeVisitorpublic void visitFieldExpr(FieldExpr expr)
visitFieldExpr in class TreeVisitorpublic void visitInstanceOfExpr(InstanceOfExpr expr)
visitInstanceOfExpr in class TreeVisitorpublic void visitLocalExpr(LocalExpr expr)
visitLocalExpr in class TreeVisitorpublic void visitNegExpr(NegExpr expr)
visitNegExpr in class TreeVisitorpublic void visitNewArrayExpr(NewArrayExpr expr)
visitNewArrayExpr in class TreeVisitorpublic void visitNewExpr(NewExpr expr)
visitNewExpr in class TreeVisitorpublic void visitNewMultiArrayExpr(NewMultiArrayExpr expr)
visitNewMultiArrayExpr in class TreeVisitorpublic void visitReturnAddressExpr(ReturnAddressExpr expr)
visitReturnAddressExpr in class TreeVisitorpublic void visitShiftExpr(ShiftExpr expr)
visitShiftExpr in class TreeVisitorpublic void visitDefExpr(DefExpr expr)
visitDefExpr in class TreeVisitorpublic void visitCatchExpr(CatchExpr expr)
visitCatchExpr in class TreeVisitorpublic void visitStackExpr(StackExpr expr)
visitStackExpr in class TreeVisitorpublic void visitStaticFieldExpr(StaticFieldExpr expr)
visitStaticFieldExpr in class TreeVisitorpublic void visitZeroCheckExpr(ZeroCheckExpr expr)
visitZeroCheckExpr in class TreeVisitor