Example usage for org.objectweb.asm.tree InsnList get

List of usage examples for org.objectweb.asm.tree InsnList get

Introduction

In this page you can find the example usage for org.objectweb.asm.tree InsnList get.

Prototype

public AbstractInsnNode get(final int index) 

Source Link

Document

Returns the instruction whose index is given.

Usage

From source file:de.sanandrew.core.manpack.transformer.InstructionComparator.java

License:Creative Commons License

private static InsnListSection insnListMatchesL(InsnList haystack, InsnList needle, int start,
        HashSet<LabelNode> controlFlowLabels) {
    int h = start, n = 0;

    for (; h < haystack.size() && n < needle.size(); h++) {
        AbstractInsnNode insn = haystack.get(h);

        if (insn.getType() == 15) {
            continue;
        }/*from  w  w  w. j  a va 2  s . c o m*/
        if (insn.getType() == 8 && !controlFlowLabels.contains(insn)) {
            continue;
        }
        if (!insnEqual(haystack.get(h), needle.get(n))) {
            return null;
        }
        n++;
    }
    if (n != needle.size()) {
        return null;
    }

    return new InsnListSection(haystack, start, h - 1);
}

From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreterTest.java

License:Open Source License

/**
 * Tests that arithmeticExpressionInterpreter() of the Testobject is working correctly
 * for logical or expressions.//from  www. ja  v a 2s  . co  m
 */
@Test
public void testArithmeticExpressionInterpreterLogicalIntOr() {
    // INIT
    builder.addInsn(new InsnNode(Opcodes.ICONST_1)).//
            addInsn(new InsnNode(Opcodes.ICONST_2)).//
            addInsn(new InsnNode(Opcodes.IOR)).//
            addInsn(new InsnNode(Opcodes.RETURN));

    final InsnList optimized = interpreter.optimize(builder.getMethod("testMethod").instructions,
            builder.getMethod("testMethod"));

    assertEquals(2, optimized.size());
    assertEquals(3, NodeHelper.getNumberValue(optimized.get(0)));
}

From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreterTest.java

License:Open Source License

/**
 * Tests that arithmeticExpressionInterpreter() of the Testobject is working correctly
 * for logical xor expressions.//from w  ww  . j a  va  2s.c o  m
 */
@Test
public void testArithmeticExpressionInterpreterLogicalIntXOr() {
    // INIT
    builder.addInsn(new InsnNode(Opcodes.ICONST_1)).//
            addInsn(new InsnNode(Opcodes.ICONST_2)).//
            addInsn(new InsnNode(Opcodes.IXOR)).//
            addInsn(new InsnNode(Opcodes.RETURN));

    final InsnList optimized = interpreter.optimize(builder.getMethod("testMethod").instructions,
            builder.getMethod("testMethod"));

    assertEquals(2, optimized.size());
    assertEquals(3, NodeHelper.getNumberValue(optimized.get(0)));
}

From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreterTest.java

License:Open Source License

/**
 * Tests that arithmeticExpressionInterpreter() of the Testobject is working correctly
 * for logical and expressions.//w  w  w  . j a  v a  2 s.c o  m
 */
@Test
public void testArithmeticExpressionInterpreterLogicalIntAnd() {
    // INIT
    builder.addInsn(new InsnNode(Opcodes.ICONST_1)).//
            addInsn(new InsnNode(Opcodes.ICONST_2)).//
            addInsn(new InsnNode(Opcodes.IAND)).//
            addInsn(new InsnNode(Opcodes.RETURN));

    final InsnList optimized = interpreter.optimize(builder.getMethod("testMethod").instructions,
            builder.getMethod("testMethod"));

    assertEquals(2, optimized.size());
    assertEquals(0, NodeHelper.getNumberValue(optimized.get(0)));
}

From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreterTest.java

License:Open Source License

/**
 * Tests that arithmeticExpressionInterpreter() of the Testobject is working correctly
 * for logical or expressions./*from w w  w .j a  v a 2 s  .c o  m*/
 */
@Test
public void testArithmeticExpressionInterpreterLogicalLongOr() {
    // INIT
    builder.addInsn(new InsnNode(Opcodes.LCONST_1)).//
            addInsn(new InsnNode(Opcodes.LCONST_1)).//
            addInsn(new InsnNode(Opcodes.LOR)).//
            addInsn(new InsnNode(Opcodes.RETURN));

    final InsnList optimized = interpreter.optimize(builder.getMethod("testMethod").instructions,
            builder.getMethod("testMethod"));

    assertEquals(2, optimized.size());
    assertEquals(1l, NodeHelper.getNumberValue(optimized.get(0)));
}

From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreterTest.java

License:Open Source License

/**
 * Tests that arithmeticExpressionInterpreter() of the Testobject is working correctly
 * for logical xor expressions.//from  w  w w . ja  v  a2  s .  c o  m
 */
@Test
public void testArithmeticExpressionInterpreterLogicalLongXOr() {
    // INIT
    builder.addInsn(new InsnNode(Opcodes.LCONST_1)).//
            addInsn(new InsnNode(Opcodes.LCONST_1)).//
            addInsn(new InsnNode(Opcodes.LXOR)).//
            addInsn(new InsnNode(Opcodes.RETURN));

    final InsnList optimized = interpreter.optimize(builder.getMethod("testMethod").instructions,
            builder.getMethod("testMethod"));

    assertEquals(2, optimized.size());
    assertEquals(0l, NodeHelper.getNumberValue(optimized.get(0)));
}

From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreterTest.java

License:Open Source License

/**
 * Tests that arithmeticExpressionInterpreter() of the Testobject is working correctly
 * for logical and expressions.// w  ww.jav a2  s  .  co m
 */
@Test
public void testArithmeticExpressionInterpreterLogicalLongAnd() {
    // INIT
    builder.addInsn(new InsnNode(Opcodes.LCONST_1)).//
            addInsn(new InsnNode(Opcodes.LCONST_1)).//
            addInsn(new InsnNode(Opcodes.LAND)).//
            addInsn(new InsnNode(Opcodes.RETURN));

    final InsnList optimized = interpreter.optimize(builder.getMethod("testMethod").instructions,
            builder.getMethod("testMethod"));

    assertEquals(2, optimized.size());
    assertEquals(1l, NodeHelper.getNumberValue(optimized.get(0)));
}

From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreterTest.java

License:Open Source License

/**
 * Tests that arithmeticExpressionInterpreter() of the Testobject is working correctly
 * for logical and expressions./*ww w .ja va 2s  . co m*/
 */
@Test
public void testArithmeticExpressionComplexChain() {
    // INIT
    builder.getMethod("testMethod").desc = "()D";
    builder.add(DCONST_1).//
            loadConstant(2.0).//
            loadConstant(5.0).//
            add(DMUL).//
            add(DADD).//
            loadConstant(6.0).//
            add(DDIV).//
            add(ICONST_3).//
            add(ICONST_4).//
            add(IOR).//
            add(ICONST_5).//
            add(IAND).//
            add(I2D).//
            add(DMUL).//
            addReturn();
    final InsnList optimized = interpreter.optimize(builder.getMethod("testMethod").instructions,
            builder.getMethod("testMethod"));

    assertEquals(2, optimized.size());
    assertEquals(9.166666666666666, NodeHelper.getNumberValue(optimized.get(0)).doubleValue(), .0000001);
}

From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreterTest.java

License:Open Source License

/**
 * (1234&FF00)>>>8//from  w  ww. j  ava2  s.c  om
 */
@Test
public void testArithmeticExpressionShiftAnd() {
    // INIT
    builder.getMethod("testMethod").desc = "()I";
    builder.add(LDC, 0x1234).//
            add(LDC, 0xff00).//
            add(IAND).//
            add(BIPUSH, 8).//
            add(IUSHR).//
            addReturn();
    final InsnList optimized = interpreter.optimize(builder.getMethod("testMethod").instructions,
            builder.getMethod("testMethod"));

    assertEquals(2, optimized.size());
    assertEquals(0x12, NodeHelper.getNumberValue(optimized.get(0)).intValue());
}

From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreterTest.java

License:Open Source License

/**
 * int x = (int) 1.0 * 1.0;/*from w  ww.  j  ava2s  .c o m*/
 */
@Test
public void testArithmeticExpressionNarrow() {
    // INIT
    builder.getMethod("testMethod").desc = "()I";
    builder.add(DCONST_1).//
            add(DCONST_1).//
            add(DMUL).//
            add(D2I).//
            addReturn();
    final InsnList optimized = interpreter.optimize(builder.getMethod("testMethod").instructions,
            builder.getMethod("testMethod"));

    assertEquals(3, optimized.size());
    assertEquals(1, NodeHelper.getNumberValue(optimized.get(0)).intValue());
}