Example usage for org.objectweb.asm MethodVisitor visitIntInsn

List of usage examples for org.objectweb.asm MethodVisitor visitIntInsn

Introduction

In this page you can find the example usage for org.objectweb.asm MethodVisitor visitIntInsn.

Prototype

public void visitIntInsn(final int opcode, final int operand) 

Source Link

Document

Visits an instruction with a single int operand.

Usage

From source file:org.spongepowered.test.decompile.OperatorTests.java

License:Open Source License

@Test
public void testAdd() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(III)V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);/*  w w w.j a  v  a2  s  .co  m*/
    Label end = new Label();
    mv.visitIntInsn(ILOAD, 1);
    mv.visitIntInsn(ILOAD, 2);
    mv.visitInsn(IADD);
    mv.visitIntInsn(ISTORE, 0);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("i", "I", null, start, end, 0);
    mv.visitLocalVariable("a", "I", null, start, end, 1);
    mv.visitLocalVariable("b", "I", null, start, end, 2);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "i = a + b;";
    Assert.assertEquals(good, insn);
}

From source file:org.spongepowered.test.decompile.OperatorTests.java

License:Open Source License

@Test
public void testSub() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(III)V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);//from w ww. j a va 2  s  .  co  m
    Label end = new Label();
    mv.visitIntInsn(ILOAD, 1);
    mv.visitIntInsn(ILOAD, 2);
    mv.visitInsn(ISUB);
    mv.visitIntInsn(ISTORE, 0);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("i", "I", null, start, end, 0);
    mv.visitLocalVariable("a", "I", null, start, end, 1);
    mv.visitLocalVariable("b", "I", null, start, end, 2);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "i = a - b;";
    Assert.assertEquals(good, insn);
}

From source file:org.spongepowered.test.decompile.OperatorTests.java

License:Open Source License

@Test
public void testMultiply() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(III)V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);//from w w  w. ja va 2s.com
    Label end = new Label();
    mv.visitIntInsn(ILOAD, 1);
    mv.visitIntInsn(ILOAD, 2);
    mv.visitInsn(IMUL);
    mv.visitIntInsn(ISTORE, 0);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("i", "I", null, start, end, 0);
    mv.visitLocalVariable("a", "I", null, start, end, 1);
    mv.visitLocalVariable("b", "I", null, start, end, 2);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "i = a * b;";
    Assert.assertEquals(good, insn);
}

From source file:org.spongepowered.test.decompile.OperatorTests.java

License:Open Source License

@Test
public void testDiv() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(III)V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);/*from w w  w . j  ava2 s  .  c o m*/
    Label end = new Label();
    mv.visitIntInsn(ILOAD, 1);
    mv.visitIntInsn(ILOAD, 2);
    mv.visitInsn(IDIV);
    mv.visitIntInsn(ISTORE, 0);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("i", "I", null, start, end, 0);
    mv.visitLocalVariable("a", "I", null, start, end, 1);
    mv.visitLocalVariable("b", "I", null, start, end, 2);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "i = a / b;";
    Assert.assertEquals(good, insn);
}

From source file:org.spongepowered.test.decompile.OperatorTests.java

License:Open Source License

@Test
public void testRem() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(III)V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);//from  w  w w. j av  a2 s .c o m
    Label end = new Label();
    mv.visitIntInsn(ILOAD, 1);
    mv.visitIntInsn(ILOAD, 2);
    mv.visitInsn(IREM);
    mv.visitIntInsn(ISTORE, 0);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("i", "I", null, start, end, 0);
    mv.visitLocalVariable("a", "I", null, start, end, 1);
    mv.visitLocalVariable("b", "I", null, start, end, 2);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "i = a % b;";
    Assert.assertEquals(good, insn);
}

From source file:org.spongepowered.test.decompile.OperatorTests.java

License:Open Source License

@Test
public void testShr() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(III)V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);//w w  w .  jav  a  2s  . co m
    Label end = new Label();
    mv.visitIntInsn(ILOAD, 1);
    mv.visitIntInsn(ILOAD, 2);
    mv.visitInsn(ISHR);
    mv.visitIntInsn(ISTORE, 0);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("i", "I", null, start, end, 0);
    mv.visitLocalVariable("a", "I", null, start, end, 1);
    mv.visitLocalVariable("b", "I", null, start, end, 2);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "i = a >> b;";
    Assert.assertEquals(good, insn);
}

From source file:org.spongepowered.test.decompile.OperatorTests.java

License:Open Source License

@Test
public void testUshr() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(III)V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);//from   ww  w.j  a v  a  2s .co m
    Label end = new Label();
    mv.visitIntInsn(ILOAD, 1);
    mv.visitIntInsn(ILOAD, 2);
    mv.visitInsn(IUSHR);
    mv.visitIntInsn(ISTORE, 0);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("i", "I", null, start, end, 0);
    mv.visitLocalVariable("a", "I", null, start, end, 1);
    mv.visitLocalVariable("b", "I", null, start, end, 2);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "i = a >>> b;";
    Assert.assertEquals(good, insn);
}

From source file:org.spongepowered.test.decompile.OperatorTests.java

License:Open Source License

@Test
public void testShl() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(III)V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);// w  ww.  j a v  a 2  s. c  o m
    Label end = new Label();
    mv.visitIntInsn(ILOAD, 1);
    mv.visitIntInsn(ILOAD, 2);
    mv.visitInsn(ISHL);
    mv.visitIntInsn(ISTORE, 0);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("i", "I", null, start, end, 0);
    mv.visitLocalVariable("a", "I", null, start, end, 1);
    mv.visitLocalVariable("b", "I", null, start, end, 2);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "i = a << b;";
    Assert.assertEquals(good, insn);
}

From source file:org.spongepowered.test.decompile.OperatorTests.java

License:Open Source License

@Test
public void testFloatCompare() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(ZFF)V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);//from w ww  . j av a 2  s . co m
    Label end = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    mv.visitIntInsn(FLOAD, 1);
    mv.visitIntInsn(FLOAD, 2);
    mv.visitInsn(FCMPG);
    mv.visitJumpInsn(IFGT, l1);
    mv.visitInsn(ICONST_1);
    mv.visitJumpInsn(GOTO, l2);
    mv.visitLabel(l1);
    mv.visitInsn(ICONST_0);
    mv.visitLabel(l2);
    mv.visitIntInsn(ISTORE, 0);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("i", "Z", null, start, end, 0);
    mv.visitLocalVariable("a", "F", null, start, end, 1);
    mv.visitLocalVariable("b", "F", null, start, end, 2);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "i = a <= b;";
    Assert.assertEquals(good, insn);
}

From source file:org.spongepowered.test.decompile.SwitchTests.java

License:Open Source License

private static void generateSwitchSyntheticEclipse(ClassWriter cw) {

    MethodVisitor mv = cw.visitMethod(ACC_STATIC + ACC_SYNTHETIC,
            "$SWITCH_TABLE$org$spongepowered$test$decompile$SwitchTests$TestEnum", "()[I", null, null);
    mv.visitCode();/*www  .j a va2s.  c  o m*/
    Label l0 = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    mv.visitTryCatchBlock(l0, l1, l2, "java/lang/NoSuchFieldError");
    Label l3 = new Label();
    Label l4 = new Label();
    Label l5 = new Label();
    mv.visitTryCatchBlock(l3, l4, l5, "java/lang/NoSuchFieldError");
    Label l6 = new Label();
    Label l7 = new Label();
    Label l8 = new Label();
    mv.visitTryCatchBlock(l6, l7, l8, "java/lang/NoSuchFieldError");
    Label l9 = new Label();
    Label l10 = new Label();
    Label l11 = new Label();
    mv.visitTryCatchBlock(l9, l10, l11, "java/lang/NoSuchFieldError");
    Label l12 = new Label();
    Label l13 = new Label();
    Label l14 = new Label();
    mv.visitTryCatchBlock(l12, l13, l14, "java/lang/NoSuchFieldError");
    Label l15 = new Label();
    Label l16 = new Label();
    Label l17 = new Label();
    mv.visitTryCatchBlock(l15, l16, l17, "java/lang/NoSuchFieldError");
    Label l18 = new Label();
    Label l19 = new Label();
    Label l20 = new Label();
    mv.visitTryCatchBlock(l18, l19, l20, "java/lang/NoSuchFieldError");
    Label l21 = new Label();
    Label l22 = new Label();
    Label l23 = new Label();
    mv.visitTryCatchBlock(l21, l22, l23, "java/lang/NoSuchFieldError");
    Label l24 = new Label();
    Label l25 = new Label();
    Label l26 = new Label();
    mv.visitTryCatchBlock(l24, l25, l26, "java/lang/NoSuchFieldError");
    Label l27 = new Label();
    Label l28 = new Label();
    Label l29 = new Label();
    mv.visitTryCatchBlock(l27, l28, l29, "java/lang/NoSuchFieldError");
    Label l30 = new Label();
    mv.visitLabel(l30);
    mv.visitLineNumber(28, l30);
    mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests",
            "$SWITCH_TABLE$org$spongepowered$test$decompile$SwitchTests$TestEnum", "[I");
    Label l31 = new Label();
    mv.visitJumpInsn(IFNULL, l31);
    mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests",
            "$SWITCH_TABLE$org$spongepowered$test$decompile$SwitchTests$TestEnum", "[I");
    mv.visitInsn(ARETURN);
    mv.visitLabel(l31);
    mv.visitMethodInsn(INVOKESTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "values",
            "()[Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;", false);
    mv.visitInsn(ARRAYLENGTH);
    mv.visitIntInsn(NEWARRAY, T_INT);
    mv.visitVarInsn(ASTORE, 0);
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "EIGHT",
            "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I",
            false);
    mv.visitIntInsn(BIPUSH, 8);
    mv.visitInsn(IASTORE);
    mv.visitLabel(l1);
    mv.visitJumpInsn(GOTO, l3);
    mv.visitLabel(l2);
    mv.visitInsn(POP);
    mv.visitLabel(l3);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "FIVE",
            "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I",
            false);
    mv.visitInsn(ICONST_5);
    mv.visitInsn(IASTORE);
    mv.visitLabel(l4);
    mv.visitJumpInsn(GOTO, l6);
    mv.visitLabel(l5);
    mv.visitInsn(POP);
    mv.visitLabel(l6);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "FOUR",
            "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I",
            false);
    mv.visitInsn(ICONST_4);
    mv.visitInsn(IASTORE);
    mv.visitLabel(l7);
    mv.visitJumpInsn(GOTO, l9);
    mv.visitLabel(l8);
    mv.visitInsn(POP);
    mv.visitLabel(l9);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "NINE",
            "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I",
            false);
    mv.visitIntInsn(BIPUSH, 9);
    mv.visitInsn(IASTORE);
    mv.visitLabel(l10);
    mv.visitJumpInsn(GOTO, l12);
    mv.visitLabel(l11);
    mv.visitInsn(POP);
    mv.visitLabel(l12);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ONE",
            "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I",
            false);
    mv.visitInsn(ICONST_1);
    mv.visitInsn(IASTORE);
    mv.visitLabel(l13);
    mv.visitJumpInsn(GOTO, l15);
    mv.visitLabel(l14);
    mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/NoSuchFieldError" });
    mv.visitInsn(POP);
    mv.visitLabel(l15);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "SEVEN",
            "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I",
            false);
    mv.visitIntInsn(BIPUSH, 7);
    mv.visitInsn(IASTORE);
    mv.visitLabel(l16);
    mv.visitJumpInsn(GOTO, l18);
    mv.visitLabel(l17);
    mv.visitInsn(POP);
    mv.visitLabel(l18);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "SIX",
            "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I",
            false);
    mv.visitIntInsn(BIPUSH, 6);
    mv.visitInsn(IASTORE);
    mv.visitLabel(l19);
    mv.visitJumpInsn(GOTO, l21);
    mv.visitLabel(l20);
    mv.visitInsn(POP);
    mv.visitLabel(l21);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "TEN",
            "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I",
            false);
    mv.visitIntInsn(BIPUSH, 10);
    mv.visitInsn(IASTORE);
    mv.visitLabel(l22);
    mv.visitJumpInsn(GOTO, l24);
    mv.visitLabel(l23);
    mv.visitInsn(POP);
    mv.visitLabel(l24);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "THREE",
            "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I",
            false);
    mv.visitInsn(ICONST_3);
    mv.visitInsn(IASTORE);
    mv.visitLabel(l25);
    mv.visitJumpInsn(GOTO, l27);
    mv.visitLabel(l26);
    mv.visitInsn(POP);
    mv.visitLabel(l27);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "TWO",
            "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I",
            false);
    mv.visitInsn(ICONST_2);
    mv.visitInsn(IASTORE);
    mv.visitLabel(l28);
    Label l32 = new Label();
    mv.visitJumpInsn(GOTO, l32);
    mv.visitLabel(l29);
    mv.visitInsn(POP);
    mv.visitLabel(l32);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitInsn(DUP);
    mv.visitFieldInsn(PUTSTATIC, "org/spongepowered/test/decompile/SwitchTests",
            "$SWITCH_TABLE$org$spongepowered$test$decompile$SwitchTests$TestEnum", "[I");
    mv.visitInsn(ARETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}