Example usage for org.objectweb.asm Opcodes RETURN

List of usage examples for org.objectweb.asm Opcodes RETURN

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes RETURN.

Prototype

int RETURN

To view the source code for org.objectweb.asm Opcodes RETURN.

Click Source Link

Usage

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 va2 s .c om
 */
@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.//from   www.  j  a v a  2s  .  c om
 */
@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  ww  .ja va  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 . j  a 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 w w  .  jav a 2s.  c om*/
 */
@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.ClassNodeBuilder.java

License:Open Source License

/**
 * Appends a Constructor with the given descriptors.
 * //from   w  ww  .jav  a2s. c  o m
 * @param constructorDesc
 *          the constructor desc
 * @param superConstructorDesc
 *          the super constructor desc
 * @return the class node builder
 */
public ClassNodeBuilder addConstructor(final String constructorDesc, final String superConstructorDesc) {
    if (isInterface) {
        return this;
    }
    addMethod("<init>", constructorDesc);//
    lastConstructorVarIndex = 1;
    final InsnList list = new InsnList();
    list.add(new VarInsnNode(Opcodes.ALOAD, 0));
    final Type methodType = Type.getMethodType(superConstructorDesc);
    for (final Type parameterType : methodType.getArgumentTypes()) {
        list.add(new VarInsnNode(parameterType.getOpcode(ILOAD), lastConstructorVarIndex));
        lastConstructorVarIndex += parameterType.getSize();
    }
    list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, classNode.superName, "<init>", superConstructorDesc));
    list.add(new InsnNode(Opcodes.RETURN));
    addToConstructor(list);
    return this;
}

From source file:de.tuberlin.uebb.jbop.optimizer.ClassNodeBuilder.java

License:Open Source License

/**
 * Creates a setter for the last added field.
 * /*from  w w  w .  java  2 s.  c  o  m*/
 * @return the class node builder
 */
public ClassNodeBuilder withSetter() {
    if (isInterface) {
        return this;
    }
    final String name = lastField.name;
    final String desc = lastField.desc;
    addMethod("set" + Character.toUpperCase(name.charAt(0)) + name.substring(1), "(" + desc + ")V");
    final Type type = Type.getType(desc);
    addInsn(new VarInsnNode(Opcodes.ALOAD, 0));
    addInsn(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), 1));
    addInsn(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, name, desc));
    addInsn(new InsnNode(Opcodes.RETURN));
    return this;
}

From source file:de.tuberlin.uebb.jbop.optimizer.ClassNodeBuilder.java

License:Open Source License

/**
 * adds a new empty void-method containing only the returnstatement.
 * /*  ww w . j a  v  a  2 s. c om*/
 * @param methodName
 *          the method name
 * @return the class node builder
 */
public ClassNodeBuilder addEmptyMethod(final String methodName) {
    if ("<init>".equals(methodName)) {
        return this;
    }
    addMethod(methodName, "()V");
    if (isInterface) {
        return this;
    }
    addInsn(new InsnNode(Opcodes.RETURN));
    return this;
}

From source file:de.tuberlin.uebb.jbop.optimizer.controlflow.ConstantIfInlinerTest.java

License:Open Source License

/**
 * Tests that constantIfInliner is working correctly.
 * /* ww  w.  j  a  v a 2 s .c om*/
 * Input is
 * 
 * <pre>
 * if(1<2)
 * ...
 * </pre>
 * 
 * @throws JBOPClassException
 *           the jBOP class exception
 */

@Test
public void testConstantIfInlinerIF_CMPEG() throws JBOPClassException {
    // INIT
    final LabelNode label = new LabelNode();
    builder.addInsn(new InsnNode(Opcodes.ICONST_1)).//
            addInsn(new InsnNode(Opcodes.ICONST_2)).//
            addInsn(new JumpInsnNode(Opcodes.IF_ICMPGE, label)).//
            addInsn(new InsnNode(Opcodes.NOP)).//
            addInsn(label).//
            addInsn(new InsnNode(Opcodes.RETURN));

    // RUN
    assertEquals(6, method.instructions.size());
    final InsnList optimized = constantIfInliner.optimize(method.instructions, method);

    // ASSERT
    assertEquals(3, optimized.size());
    assertEquals(Opcodes.NOP, optimized.get(0).getOpcode());
}

From source file:de.tuberlin.uebb.jbop.optimizer.controlflow.ConstantIfInlinerTest.java

License:Open Source License

/**
 * Tests that constantIfInliner is working correctly.
 * /*from  w ww  . jav  a 2 s  .  c o m*/
 * Input is
 * 
 * <pre>
 * if(1<=2)
 * ...
 * </pre>
 * 
 * @throws JBOPClassException
 *           the jBOP class exception
 */

@Test
public void testConstantIfInlinerIF_ICMPGT() throws JBOPClassException {
    // INIT
    final LabelNode label = new LabelNode();
    builder.addInsn(new InsnNode(Opcodes.ICONST_1)).//
            addInsn(new InsnNode(Opcodes.ICONST_2)).//
            addInsn(new JumpInsnNode(Opcodes.IF_ICMPGT, label)).//
            addInsn(new InsnNode(Opcodes.NOP)).//
            addInsn(label).//
            addInsn(new InsnNode(Opcodes.RETURN));

    // RUN
    assertEquals(6, method.instructions.size());
    final InsnList optimized = constantIfInliner.optimize(method.instructions, method);

    // ASSERT
    assertEquals(3, optimized.size());
    assertEquals(Opcodes.NOP, optimized.get(0).getOpcode());
}