/** * Returns the label corresponding to the given offset. The default * implementation of this method creates a label for the given offset if it * has not been already created. * * @param offset * a bytecode offset in a method. * @param labels * the already created labels, indexed by their offset. If a * label already exists for offset this method must not create a * new one. Otherwise it must store the new label in this array. * @return a non null Label, which must be equal to labels[offset]. */ protected Label readLabel(int offset, Label[] labels) { if (labels[offset] == null) { labels[offset] = new Label(); } return labels[offset]; }
/** * Ends the current basic block. This method must be used in the case where * the current basic block does not have any successor. */ private void noSuccessor() { if (compute == FRAMES) { Label l = new Label(); l.frame = new Frame(); l.frame.owner = l; l.resolve(this, code.length, code.data); previousBlock.successor = l; previousBlock = l; } else { currentBlock.outputStackMax = maxStackSize; } currentBlock = null; }
@Override public void generate() { DUP dup = OperatorFactory.newOperator(DUP.class, new Class<?>[]{KernelProgramBlock.class, IClass.class}, this, lock.getResultType()); dupSynArgument = var(lock.getResultType(), dup); flag1 = OperatorFactory.newOperator(Marker.class, new Class<?>[]{KernelProgramBlock.class, Label.class}, this, new Label()); body(lock); }
@Override protected void doExecute(MethodExecuteContext context) { Instructions instructions = context.getInstructions(); Label posLbl = new Label(); Label l1 = new Label(); Label l2 = new Label(); if(exp1 instanceof Jumpable){ Jumpable jmp = (Jumpable) exp1; jmp.jumpNegative(context, this, posLbl, l1);//.executeJump(Opcodes.JUMP_NEGATIVE, l1); }else{ exp1.push(context); instructions.unbox(exp1.getResultType().getType()); instructions.ifZCmp(Instructions.EQ, l1); } instructions.mark(posLbl); exp2.push(context); context.getInstructions().getOperandStack().pop(); instructions.goTo(l2); instructions.mark(l1); exp3.push(context); instructions.mark(l2); }
@Override protected void executing(MethodExecuteContext context) { Label andEndLbl = new Label(); Label falseLbl = new Label(); MethodVisitor mv = context.getInstructions().getMv(); OperandStack stack = context.getInstructions().getOperandStack(); jumpNegative(context, this, andEndLbl, falseLbl); mv.visitInsn(Opcodes.ICONST_1); mv.visitJumpInsn(Opcodes.GOTO, andEndLbl); mv.visitLabel(falseLbl); mv.visitInsn(Opcodes.ICONST_0); mv.visitLabel(andEndLbl); stack.pop(); stack.pop(); stack.push(Type.BOOLEAN_TYPE); }
@Override protected void executing(MethodExecuteContext context) { Label trueLbl = new Label(); Label orEndLbl = new Label(); MethodVisitor mv = context.getInstructions().getMv(); OperandStack stack = context.getInstructions().getOperandStack(); jumpPositive(context, this, trueLbl, orEndLbl); mv.visitInsn(Opcodes.ICONST_0); mv.visitJumpInsn(Opcodes.GOTO, orEndLbl); mv.visitLabel(trueLbl); mv.visitInsn(Opcodes.ICONST_1); mv.visitLabel(orEndLbl); stack.pop(); stack.pop(); stack.push(Type.BOOLEAN_TYPE); }
@Override public void jumpNegative(MethodExecuteContext context, KernelParam from, Label posLbl, Label negLbl) { Instructions instructions = context.getInstructions(); MethodVisitor mv = instructions.getMv(); Label rightFactorJudgeLbl = new Label(); Label conditionCheckEnd = new Label(); if(leftFactor instanceof KernelShortCircuitAnd) { ((Jumpable) leftFactor).jumpPositive(context, this, posLbl, rightFactorJudgeLbl); }else if(leftFactor instanceof Jumpable) { ((Jumpable) leftFactor).jumpPositive(context, this, posLbl, negLbl); } else { leftFactor.push(context); instructions.unbox(leftFactor.getResultType().getType()); mv.visitJumpInsn(Opcodes.IFNE, conditionCheckEnd); } instructions.mark(rightFactorJudgeLbl); if(rightFactor instanceof Jumpable) { ((Jumpable) rightFactor).jumpNegative(context, this, posLbl, negLbl); } else { rightFactor.push(context); instructions.unbox(rightFactor.getResultType().getType()); mv.visitJumpInsn(Opcodes.IFEQ, negLbl); } instructions.mark(conditionCheckEnd); }
@Override public void jumpPositive(MethodExecuteContext context, KernelParam from, Label posLbl, Label negLbl) { Instructions instructions = context.getInstructions(); MethodVisitor mv = instructions.getMv(); Label rightFactorJudgeLbl = new Label(); if(leftFactor instanceof KernelShortCircuitAnd) { ((Jumpable) leftFactor).jumpPositive(context, this, posLbl, rightFactorJudgeLbl); } else if(leftFactor instanceof Jumpable) { ((Jumpable) leftFactor).jumpPositive(context, this, posLbl, negLbl); } else { leftFactor.push(context); instructions.unbox(leftFactor.getResultType().getType()); mv.visitJumpInsn(Opcodes.IFNE, posLbl); } instructions.mark(rightFactorJudgeLbl); Label conditionCheckEnd = new Label(); if(rightFactor instanceof KernelShortCircuitAnd) { ((Jumpable) rightFactor).jumpPositive(context, this, posLbl, conditionCheckEnd); } else if(rightFactor instanceof Jumpable) { ((Jumpable) rightFactor).jumpPositive(context, this, posLbl, negLbl); } else { rightFactor.push(context); instructions.unbox(rightFactor.getResultType().getType()); mv.visitJumpInsn(Opcodes.IFNE, posLbl); } instructions.mark(conditionCheckEnd); }
visitLabel(new Label());
@Override protected void doExecute(MethodExecuteContext context) { Instructions instructions = context.getInstructions(); Label posLbl = new Label(); if (condition instanceof Jumpable) { ((Jumpable) condition).jumpNegative(context, null, posLbl, getEnd()); } else { condition.push(context); instructions.unbox(condition.getResultType().getType()); instructions.ifZCmp(Instructions.EQ, getEnd()); } instructions.mark(posLbl); for (InstructionNode exe : getChildren()) { exe.execute(context); } if (nextBranch != null) { instructions.goTo(getSerialEnd()); } }
@Override protected void doExecute(MethodExecuteContext context) { Label posLbl = new Label(); Instructions instructions = context.getInstructions(); instructions.nop(); if (condition instanceof Jumpable) { ((Jumpable) condition).jumpNegative(context, null, posLbl, getEnd()); } else { condition.push(context); instructions.unbox(condition.getResultType().getType()); instructions.ifZCmp(Instructions.EQ, getEnd()); } instructions.mark(posLbl); for (LifeCycle exe : getChildren()) { exe.execute(context); } if (nextBranch != null) { instructions.goTo(getSerialEnd()); } }
@Override public void jumpPositive(MethodExecuteContext context, KernelParam from, Label posLbl, Label negLbl) { Instructions instructions = context.getInstructions(); MethodVisitor mv = instructions.getMv(); Label label4Or = new Label(); if (leftFactor instanceof KernelShortCircuitOr) { ((Jumpable) leftFactor).jumpNegative(context, this, posLbl, label4Or); } else if (leftFactor instanceof Jumpable) { ((Jumpable) leftFactor).jumpNegative(context, this, posLbl, negLbl); } else { leftFactor.push(context); instructions.unbox(leftFactor.getResultType().getType()); mv.visitJumpInsn(Opcodes.IFEQ, negLbl); } if (rightFactor instanceof Jumpable) { ((Jumpable) rightFactor).jumpPositive(context, this, posLbl, negLbl); } else { rightFactor.push(context); instructions.unbox(rightFactor.getResultType().getType()); mv.visitJumpInsn(Opcodes.IFNE, posLbl); } instructions.mark(label4Or); }
@Override public void jumpNegative(MethodExecuteContext context, KernelParam from, Label posLbl, Label negLbl) { Instructions instructions = context.getInstructions(); MethodVisitor mv = instructions.getMv(); Label label4Or = new Label(); if (leftFactor instanceof KernelShortCircuitOr) { ((Jumpable) leftFactor).jumpNegative(context, this, posLbl, label4Or); } else if (leftFactor instanceof Jumpable) { ((Jumpable) leftFactor).jumpNegative(context, this, posLbl, negLbl); } else { leftFactor.push(context); instructions.unbox(leftFactor.getResultType().getType()); mv.visitJumpInsn(Opcodes.IFEQ, negLbl); } if (rightFactor instanceof Jumpable) { ((Jumpable) rightFactor).jumpNegative(context, this, posLbl, negLbl); } else { rightFactor.push(context); instructions.unbox(rightFactor.getResultType().getType()); mv.visitJumpInsn(Opcodes.IFEQ, negLbl); } instructions.mark(label4Or); }