Class CodeGenerator
java.lang.Object
EDU.purdue.cs.bloat.tree.TreeVisitor
EDU.purdue.cs.bloat.codegen.CodeGenerator
- All Implemented Interfaces:
Opcode
CodeGenerator performs some final optimizations and is used (via a visitor)
to generate bytecode for the contents of a control flow graph.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanstatic booleanprotected MethodEditorprotected Blockbooleanstatic booleanUse information about placement of local variables to eliminate loads and stores in favor of stack manipulationsprotected Mapprotected intstatic booleanprotected SetFields inherited from class TreeVisitor
FORWARD, REVERSEFields inherited from interface Opcode
opc_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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidallocReturnAddresses(FlowGraph cfg, RegisterAllocator alloc) Allocate "registers" (LocalVariables) for the return addresses for each subroutine in the method.protected StmtcreateStore(VarExpr target, Expr source) Returns an ExprStmt that contains a store of the source into the target.protected StmtcreateUndefinedStore(VarExpr target) Create a ExprStmt that initializes a target variable to a default value based on the type of the target.voidreplacePhis(FlowGraph cfg) Replace PhiStmts with copies that accomplish what the PhiStmts represent.voidSimplifies the control flow of a method by changing jump and return statements into gotos where appropriate.voidvoidvisitArithExpr(ArithExpr expr) voidvoidvoidvoidvoidvisitCastExpr(CastExpr expr) voidvisitCatchExpr(CatchExpr expr) voidvoidvisitDefExpr(DefExpr expr) voidvoidvisitExprStmt(ExprStmt stmt) voidvisitFieldExpr(FieldExpr expr) voidvisitFlowGraph(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.voidvisitGotoStmt(GotoStmt stmt) voidvisitIfCmpStmt(IfCmpStmt stmt) voidvisitIfZeroStmt(IfZeroStmt stmt) voidvisitInitStmt(InitStmt stmt) voidvoidvisitJsrStmt(JsrStmt stmt) voidvisitLabelStmt(LabelStmt stmt) voidvisitLocalExpr(LocalExpr expr) voidvisitMonitorStmt(MonitorStmt stmt) voidvisitNegExpr(NegExpr expr) voidvoidvisitNewExpr(NewExpr expr) voidvoidvisitPhiStmt(PhiStmt stmt) voidvisitRCExpr(RCExpr expr) voidvisitRetStmt(RetStmt stmt) voidvoidvoidvisitReturnStmt(ReturnStmt stmt) voidvisitSCStmt(SCStmt stmt) voidvisitShiftExpr(ShiftExpr expr) voidvisitSRStmt(SRStmt stmt) voidvisitStackExpr(StackExpr expr) voidvoidvoidvisitStoreExpr(StoreExpr expr) voidvisitSwitchStmt(SwitchStmt stmt) voidvisitThrowStmt(ThrowStmt stmt) voidvisitUCExpr(UCExpr expr) voidMethods inherited from class TreeVisitor
direction, forward, prune, reverse, setPrune, visitBlock, visitCallExpr, visitCheckExpr, visitIfStmt, visitMemExpr, visitMemRefExpr, visitNode, visitPhiCatchStmt, visitPhiJoinStmt, visitStmt, visitTree, visitVarExpr
-
Field Details
-
DEBUG
public static boolean DEBUG -
USE_PERSISTENT
public static boolean USE_PERSISTENT -
OPT_STACK
public static boolean OPT_STACKUse information about placement of local variables to eliminate loads and stores in favor of stack manipulations -
DB_OPT_STACK
public static boolean DB_OPT_STACK -
method
-
visited
-
postponedInstructions
-
next
-
stackHeight
protected int stackHeight -
nowb
public boolean nowb
-
-
Constructor Details
-
CodeGenerator
Constructor.- Parameters:
method- The method for which bytecode is generated.
-
-
Method Details
-
visitFlowGraph
Visits the nodes in the method's control flow graph and ensures that information about the method's basic blocks is consistent and correct.- Overrides:
visitFlowGraphin classTreeVisitor- Parameters:
cfg- The control flow graph associated with this method.
-
simplifyControlFlow
Simplifies the control flow of a method by changing jump and return statements into gotos where appropriate. -
replacePhis
Replace PhiStmts with copies that accomplish what the PhiStmts represent. Then remove the PhiStmts from the control flow graph. -
allocReturnAddresses
Allocate "registers" (LocalVariables) for the return addresses for each subroutine in the method.- Parameters:
cfg- Control flow graph for the methodalloc- Allocation (and information about) the local variables in the method.- See Also:
-
createUndefinedStore
-
createStore
-
visitExpr
- Overrides:
visitExprin classTreeVisitor
-
visitExprStmt
- Overrides:
visitExprStmtin classTreeVisitor
-
visitInitStmt
- Overrides:
visitInitStmtin classTreeVisitor
-
visitGotoStmt
- Overrides:
visitGotoStmtin classTreeVisitor
-
visitIfCmpStmt
- Overrides:
visitIfCmpStmtin classTreeVisitor
-
visitIfZeroStmt
- Overrides:
visitIfZeroStmtin classTreeVisitor
-
visitLabelStmt
- Overrides:
visitLabelStmtin classTreeVisitor
-
visitMonitorStmt
- Overrides:
visitMonitorStmtin classTreeVisitor
-
visitPhiStmt
- Overrides:
visitPhiStmtin classTreeVisitor
-
visitRCExpr
- Overrides:
visitRCExprin classTreeVisitor
-
visitUCExpr
- Overrides:
visitUCExprin classTreeVisitor
-
visitRetStmt
- Overrides:
visitRetStmtin classTreeVisitor
-
visitReturnExprStmt
- Overrides:
visitReturnExprStmtin classTreeVisitor
-
visitReturnStmt
- Overrides:
visitReturnStmtin classTreeVisitor
-
visitStoreExpr
- Overrides:
visitStoreExprin classTreeVisitor
-
visitAddressStoreStmt
- Overrides:
visitAddressStoreStmtin classTreeVisitor
-
visitJsrStmt
- Overrides:
visitJsrStmtin classTreeVisitor
-
visitSwitchStmt
- Overrides:
visitSwitchStmtin classTreeVisitor
-
visitStackManipStmt
- Overrides:
visitStackManipStmtin classTreeVisitor
-
visitThrowStmt
- Overrides:
visitThrowStmtin classTreeVisitor
-
visitSCStmt
- Overrides:
visitSCStmtin classTreeVisitor
-
visitSRStmt
- Overrides:
visitSRStmtin classTreeVisitor
-
visitArithExpr
- Overrides:
visitArithExprin classTreeVisitor
-
visitArrayLengthExpr
- Overrides:
visitArrayLengthExprin classTreeVisitor
-
visitArrayRefExpr
- Overrides:
visitArrayRefExprin classTreeVisitor
-
visitCallMethodExpr
- Overrides:
visitCallMethodExprin classTreeVisitor
-
visitCallStaticExpr
- Overrides:
visitCallStaticExprin classTreeVisitor
-
visitCastExpr
- Overrides:
visitCastExprin classTreeVisitor
-
visitConstantExpr
- Overrides:
visitConstantExprin classTreeVisitor
-
visitFieldExpr
- Overrides:
visitFieldExprin classTreeVisitor
-
visitInstanceOfExpr
- Overrides:
visitInstanceOfExprin classTreeVisitor
-
visitLocalExpr
- Overrides:
visitLocalExprin classTreeVisitor
-
visitNegExpr
- Overrides:
visitNegExprin classTreeVisitor
-
visitNewArrayExpr
- Overrides:
visitNewArrayExprin classTreeVisitor
-
visitNewExpr
- Overrides:
visitNewExprin classTreeVisitor
-
visitNewMultiArrayExpr
- Overrides:
visitNewMultiArrayExprin classTreeVisitor
-
visitReturnAddressExpr
- Overrides:
visitReturnAddressExprin classTreeVisitor
-
visitShiftExpr
- Overrides:
visitShiftExprin classTreeVisitor
-
visitDefExpr
- Overrides:
visitDefExprin classTreeVisitor
-
visitCatchExpr
- Overrides:
visitCatchExprin classTreeVisitor
-
visitStackExpr
- Overrides:
visitStackExprin classTreeVisitor
-
visitStaticFieldExpr
- Overrides:
visitStaticFieldExprin classTreeVisitor
-
visitZeroCheckExpr
- Overrides:
visitZeroCheckExprin classTreeVisitor
-