List of usage examples for org.objectweb.asm Opcodes ISUB
int ISUB
To view the source code for org.objectweb.asm Opcodes ISUB.
Click Source Link
From source file:org.evosuite.instrumentation.error.TestIntOverflow.java
License:Open Source License
@Test public void testSubOverflow() { int result = ErrorConditionChecker.overflowDistance(x, y, Opcodes.ISUB); assertOverflow((long) x - (long) y, result); }
From source file:org.evosuite.instrumentation.error.TestIntUnderflow.java
License:Open Source License
@Test public void testSubUnderflow() { int result = ErrorConditionChecker.underflowDistance(x, y, Opcodes.ISUB); assertUnderflow((long) x - (long) y, result); }
From source file:org.evosuite.instrumentation.ErrorConditionChecker.java
License:Open Source License
/** * <p>//from w w w . ja va 2 s . c om * overflowDistance * </p> * * @param op1 * a int. * @param op2 * a int. * @param opcode * a int. * @return a int. */ public static int overflowDistance(int op1, int op2, int opcode) { switch (opcode) { case Opcodes.IADD: int result = overflowDistanceAdd(op1, op2); logger.debug("O: {} + {} = {} -> {}", op1, op2, op1 + op2, result); return result; case Opcodes.ISUB: return overflowDistanceSub(op1, op2); case Opcodes.IMUL: return overflowDistanceMul(op1, op2); case Opcodes.IDIV: return overflowDistanceDiv(op1, op2); } return Integer.MAX_VALUE; }
From source file:org.evosuite.instrumentation.ErrorConditionChecker.java
License:Open Source License
public static int underflowDistance(int op1, int op2, int opcode) { switch (opcode) { case Opcodes.IADD: int result = underflowDistanceAdd(op1, op2); logger.debug("U: {} + {} = {} -> {}", op1, op2, op1 + op2, result); return result; case Opcodes.ISUB: return underflowDistanceSub(op1, op2); case Opcodes.IMUL: return underflowDistanceMul(op1, op2); }/*from ww w . j a v a 2 s .c o m*/ return Integer.MAX_VALUE; }
From source file:org.evosuite.instrumentation.mutation.ReplaceArithmeticOperator.java
License:Open Source License
/** * <p>calculate</p>//from w ww . j a va2 s.c o m * * @param x a int. * @param y a int. * @param opcode a int. * @return a int. */ public static int calculate(int x, int y, int opcode) { switch (opcode) { case Opcodes.IADD: return x + y; case Opcodes.ISUB: return x - y; case Opcodes.IMUL: return x * y; case Opcodes.IDIV: return x / y; case Opcodes.IREM: return x % y; } throw new RuntimeException("Unknown integer opcode: " + opcode); }
From source file:org.evosuite.javaagent.ErrorConditionCheckerTest.java
License:Open Source License
@Test public void testIntSubOverflow() { int distance = ErrorConditionChecker.overflowDistance(Integer.MAX_VALUE, -2, Opcodes.ISUB); assertTrue(distance <= 0);//from w ww. j a va2 s . c o m distance = ErrorConditionChecker.overflowDistance(Integer.MAX_VALUE, Integer.MIN_VALUE, Opcodes.ISUB); assertTrue(distance <= 0); distance = ErrorConditionChecker.overflowDistance(Integer.MAX_VALUE, -1, Opcodes.ISUB); assertTrue(distance <= 0); distance = ErrorConditionChecker.overflowDistance(Integer.MAX_VALUE, 0, Opcodes.ISUB); assertEquals(1, distance); distance = ErrorConditionChecker.overflowDistance(0, Integer.MIN_VALUE, Opcodes.ISUB); assertTrue(distance <= 0); distance = ErrorConditionChecker.overflowDistance(-1, Integer.MIN_VALUE, Opcodes.ISUB); assertTrue(distance > 0); distance = ErrorConditionChecker.overflowDistance(Integer.MIN_VALUE, Integer.MIN_VALUE, Opcodes.ISUB); assertEquals(Integer.MAX_VALUE - 1, distance); int distance1 = ErrorConditionChecker.overflowDistance(10, 10, Opcodes.ISUB); assertTrue("Expected value greater 0 but got " + distance1, distance1 > 0); int distance2 = ErrorConditionChecker.overflowDistance(10, 1000, Opcodes.ISUB); assertTrue("Expected value greater 0 but got " + distance2, distance2 > 0); assertTrue("Invalid ranking: " + distance1 + ", " + distance2, distance2 > distance1); distance1 = ErrorConditionChecker.overflowDistance(100, -100, Opcodes.ISUB); assertTrue("Expected value greater 0 but got " + distance1, distance1 > 0); distance2 = ErrorConditionChecker.overflowDistance(-100, 100, Opcodes.ISUB); assertTrue("Expected value greater 0 but got " + distance2, distance2 > 0); assertTrue(distance1 < distance2); int distance3 = ErrorConditionChecker.overflowDistance(-100, 10, Opcodes.ISUB); assertTrue("Expected value greater 0 but got " + distance3, distance3 > 0); assertTrue(distance3 < distance2); distance3 = ErrorConditionChecker.overflowDistance(-50, 10, Opcodes.ISUB); assertTrue("Expected value greater 0 but got " + distance3, distance3 > 0); assertTrue(distance3 < distance2); }
From source file:org.evosuite.javaagent.ErrorConditionCheckerTest.java
License:Open Source License
@Test public void testIntSubUnderflow() { int distance = ErrorConditionChecker.underflowDistance(Integer.MIN_VALUE, 2, Opcodes.ISUB); assertTrue(distance <= 0);/* ww w . j a v a 2s . com*/ distance = ErrorConditionChecker.underflowDistance(Integer.MIN_VALUE, -2, Opcodes.ISUB); assertTrue(distance > 0); distance = ErrorConditionChecker.underflowDistance(-2, Integer.MAX_VALUE, Opcodes.ISUB); assertTrue(distance <= 0); int distance1 = ErrorConditionChecker.underflowDistance(10, 10, Opcodes.ISUB); assertTrue("Expected value greater 0 but got " + distance1, distance1 > 0); int distance2 = ErrorConditionChecker.underflowDistance(1000, 1000, Opcodes.ISUB); assertTrue("Expected value greater 0 but got " + distance2, distance2 > 0); assertTrue("Invalid ranking: " + distance1 + ", " + distance2, distance1 < distance2); distance1 = ErrorConditionChecker.underflowDistance(10, -10, Opcodes.ISUB); assertTrue("Expected value greater 0 but got " + distance1, distance1 > 0); distance2 = ErrorConditionChecker.underflowDistance(1000, -1000, Opcodes.ISUB); assertTrue("Expected value greater 0 but got " + distance2, distance2 > 0); assertTrue("Invalid ranking: " + distance1 + ", " + distance2, distance1 < distance2); }
From source file:org.formulacompiler.compiler.internal.bytecode.ExpressionCompiler.java
License:Open Source License
private final void compileIndex(ExpressionNodeForArrayReference _array, ExpressionNode _row, ExpressionNode _col) throws CompilerException { final GeneratorAdapter mv = mv(); final MethodCompiler mtd = method(); final ExpressionCompilerForNumbers numCompiler = mtd.numericCompiler(); // Push receiver for index switch method. mtd.compileObjectInContext();/* w w w . j a v a2 s. c o m*/ // Compute index value. final ArrayDescriptor desc = _array.arrayDescriptor(); final int cols = desc.numberOfColumns(); if (cols == 1 && isNullOrZeroOrOne(_col)) { // <row> - 1; numCompiler.compileInt(_row); mv.push(1); mv.visitInsn(Opcodes.ISUB); } else { final int rows = desc.numberOfRows(); if (rows == 1 && isNullOrZeroOrOne(_row)) { // <col> - 1; numCompiler.compileInt(_col); mv.push(1); mv.visitInsn(Opcodes.ISUB); } else { // Push receiver for linearizer method. mtd.compileObjectInContext(); numCompiler.compileInt(_row); numCompiler.compileInt(_col); section().getLinearizerFor(rows, cols).compileCall(mv); } } section().getIndexerFor(_array).compileCall(mv); }
From source file:org.formulacompiler.compiler.internal.bytecode.LinearizerCompiler.java
License:Open Source License
@Override protected void compileBody() throws CompilerException { final GeneratorAdapter mv = mv(); final Label outOfRange = mv.newLabel(); // range check row mv.visitVarInsn(Opcodes.ILOAD, 1); // row mv.push(1);/*from w w w .j ava2 s . c om*/ mv.ifICmp(mv.LT, outOfRange); mv.visitVarInsn(Opcodes.ILOAD, 1); // row mv.push(this.rows); mv.ifICmp(mv.GT, outOfRange); // range check col mv.visitVarInsn(Opcodes.ILOAD, 2); // col mv.push(1); mv.ifICmp(mv.LT, outOfRange); mv.visitVarInsn(Opcodes.ILOAD, 2); // col mv.push(this.cols); mv.ifICmp(mv.GT, outOfRange); // (<row> - 1) * <num_cols>) + (<col> - 1); mv.visitVarInsn(Opcodes.ILOAD, 1); // row mv.push(1); mv.visitInsn(Opcodes.ISUB); mv.push(this.cols); mv.visitInsn(Opcodes.IMUL); mv.visitVarInsn(Opcodes.ILOAD, 2); // col mv.push(1); mv.visitInsn(Opcodes.ISUB); mv.visitInsn(Opcodes.IADD); mv.visitInsn(Opcodes.IRETURN); mv.visitLabel(outOfRange); mv.throwException(ExpressionCompiler.FORMULA_ERROR_TYPE, "#VALUE/REF! because index is out of range in INDEX"); }
From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java
private void handleNumberOperator(ASTNode node, Operator op, Type type) throws ASTVisitorException { if (op.equals(Operator.PLUS)) { // FIXME: IADD or DADD, etc. // use type.getOpcode(Opcodes.IADD) to avoid if-then mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IADD))); } else if (op.equals(Operator.MINUS)) { // FIXME: ISUB or DSUB, etc. // use type.getOpcode() to avoid if-then mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.ISUB))); } else if (op.equals(Operator.MULTIPLY)) { // FIXME: IMUL or DMUL, etc. // use type.getOpcode() to avoid if-then mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IMUL))); } else if (op.equals(Operator.DIVISION)) { // FIXME: IDIV or DDIV, etc. // use type.getOpcode() to avoid if-then mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IDIV))); } else if (op.isRelational()) { if (type.equals(Type.DOUBLE_TYPE)) { mn.instructions.add(new InsnNode(Opcodes.DCMPG)); JumpInsnNode jmp = null;//from w ww .j a va 2 s. c o m switch (op) { case EQUAL: jmp = new JumpInsnNode(Opcodes.IFEQ, null); mn.instructions.add(jmp); break; case NOT_EQUAL: jmp = new JumpInsnNode(Opcodes.IFNE, null); mn.instructions.add(jmp); break; case GREATER: jmp = new JumpInsnNode(Opcodes.IFGT, null); mn.instructions.add(jmp); break; case GREATER_EQUAL: jmp = new JumpInsnNode(Opcodes.IFGE, null); mn.instructions.add(jmp); break; case LESS: jmp = new JumpInsnNode(Opcodes.IFLT, null); mn.instructions.add(jmp); break; case LESS_EQUAL: jmp = new JumpInsnNode(Opcodes.IFLE, null); mn.instructions.add(jmp); break; default: ASTUtils.error(node, "Operator not supported"); break; } mn.instructions.add(new InsnNode(Opcodes.ICONST_0)); LabelNode endLabelNode = new LabelNode(); mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode)); LabelNode trueLabelNode = new LabelNode(); jmp.label = trueLabelNode; mn.instructions.add(trueLabelNode); mn.instructions.add(new InsnNode(Opcodes.ICONST_1)); mn.instructions.add(endLabelNode); } else if (type.equals(Type.INT_TYPE)) { LabelNode trueLabelNode = new LabelNode(); switch (op) { case EQUAL: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPEQ, trueLabelNode)); break; case NOT_EQUAL: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPNE, trueLabelNode)); break; case GREATER: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPGT, trueLabelNode)); break; case GREATER_EQUAL: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPGE, trueLabelNode)); break; case LESS: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPLT, trueLabelNode)); break; case LESS_EQUAL: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPLE, trueLabelNode)); break; default: break; } mn.instructions.add(new InsnNode(Opcodes.ICONST_0)); LabelNode endLabelNode = new LabelNode(); mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode)); mn.instructions.add(trueLabelNode); mn.instructions.add(new InsnNode(Opcodes.ICONST_1)); mn.instructions.add(endLabelNode); } else { ASTUtils.error(node, "Cannot compare such types."); } } else { ASTUtils.error(node, "Operator not recognized."); } }