List of usage examples for org.objectweb.asm MethodVisitor visitIntInsn
public void visitIntInsn(final int opcode, final int operand)
From source file:org.spongepowered.test.decompile.TernaryTests.java
License:Open Source License
@Test public void testSimple() { TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(ZI)V"); MethodVisitor mv = builder.getGenerator(); Label start = new Label(); mv.visitLabel(start);/*w ww . java 2s . c om*/ Label end = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitIntInsn(ILOAD, 0); mv.visitJumpInsn(IFEQ, l1); mv.visitIntInsn(BIPUSH, 6); mv.visitJumpInsn(GOTO, l2); mv.visitLabel(l1); mv.visitInsn(ICONST_3); mv.visitLabel(l2); mv.visitIntInsn(ISTORE, 1); mv.visitLabel(end); mv.visitInsn(RETURN); mv.visitLocalVariable("a", "Z", null, start, end, 0); mv.visitLocalVariable("i", "I", null, start, end, 1); String insn = TestHelper.getAsString(builder.finish(), "test_mth"); String good = "i = a ? 6 : 3;"; Assert.assertEquals(good, insn); }
From source file:org.spongepowered.test.decompile.TernaryTests.java
License:Open Source License
@Test public void testToField() { TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(ZI)V"); MethodVisitor mv = builder.getGenerator(); Label start = new Label(); mv.visitLabel(start);/*from w w w . jav a 2 s.com*/ Label end = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitIntInsn(ILOAD, 0); mv.visitJumpInsn(IFEQ, l1); mv.visitIntInsn(BIPUSH, 6); mv.visitJumpInsn(GOTO, l2); mv.visitLabel(l1); mv.visitInsn(ICONST_3); mv.visitLabel(l2); mv.visitFieldInsn(PUTSTATIC, THIS_TYPE.getInternalName(), "afield", "I"); mv.visitLabel(end); mv.visitInsn(RETURN); mv.visitLocalVariable("a", "Z", null, start, end, 0); mv.visitLocalVariable("i", "I", null, start, end, 1); String insn = TestHelper.getAsString(builder.finish(), "test_mth"); String good = "org.spongepowered.test.decompile.TernaryTests.afield = a ? 6 : 3;"; Assert.assertEquals(good, insn); }
From source file:org.spongepowered.test.decompile.TernaryTests.java
License:Open Source License
@Test public void testNested() { TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(ZIZ)V"); MethodVisitor mv = builder.getGenerator(); Label start = new Label(); mv.visitLabel(start);/*www. j a va 2 s .c om*/ Label end = new Label(); Label l1 = new Label(); Label l2 = new Label(); Label l3 = new Label(); mv.visitIntInsn(ILOAD, 0); mv.visitJumpInsn(IFEQ, l1); mv.visitIntInsn(ILOAD, 2); mv.visitJumpInsn(IFEQ, l3); mv.visitInsn(ICONST_4); mv.visitJumpInsn(GOTO, l2); mv.visitLabel(l3); mv.visitInsn(ICONST_5); mv.visitJumpInsn(GOTO, l2); mv.visitLabel(l1); mv.visitInsn(ICONST_3); mv.visitLabel(l2); mv.visitIntInsn(ISTORE, 1); mv.visitLabel(end); mv.visitInsn(RETURN); mv.visitLocalVariable("a", "Z", null, start, end, 0); mv.visitLocalVariable("i", "I", null, start, end, 1); mv.visitLocalVariable("b", "Z", null, start, end, 2); String insn = TestHelper.getAsString(builder.finish(), "test_mth"); String good = "i = a ? b ? 4 : 5 : 3;"; Assert.assertEquals(good, insn); }
From source file:org.spongepowered.test.decompile.TernaryTests.java
License:Open Source License
@Test public void testNested2() { TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(ZIZ)V"); MethodVisitor mv = builder.getGenerator(); Label start = new Label(); mv.visitLabel(start);// w ww . ja v a2 s. c om Label end = new Label(); Label l1 = new Label(); Label l2 = new Label(); Label l3 = new Label(); mv.visitIntInsn(ILOAD, 0); mv.visitJumpInsn(IFEQ, l1); mv.visitInsn(ICONST_3); mv.visitJumpInsn(GOTO, l2); mv.visitLabel(l1); mv.visitIntInsn(ILOAD, 2); mv.visitJumpInsn(IFEQ, l3); mv.visitInsn(ICONST_4); mv.visitJumpInsn(GOTO, l2); mv.visitLabel(l3); mv.visitInsn(ICONST_5); mv.visitLabel(l2); mv.visitIntInsn(ISTORE, 1); mv.visitLabel(end); mv.visitInsn(RETURN); mv.visitLocalVariable("a", "Z", null, start, end, 0); mv.visitLocalVariable("i", "I", null, start, end, 1); mv.visitLocalVariable("b", "Z", null, start, end, 2); String insn = TestHelper.getAsString(builder.finish(), "test_mth"); String good = "i = a ? 3 : b ? 4 : 5;"; Assert.assertEquals(good, insn); }
From source file:org.spongepowered.test.decompile.TernaryTests.java
License:Open Source License
@Test public void testReturned() { TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(ZI)I"); MethodVisitor mv = builder.getGenerator(); Label start = new Label(); mv.visitLabel(start);/*from w w w.j ava 2 s . c o m*/ Label end = new Label(); Label l1 = new Label(); mv.visitIntInsn(ILOAD, 0); mv.visitJumpInsn(IFEQ, l1); mv.visitIntInsn(BIPUSH, 6); mv.visitJumpInsn(GOTO, end); mv.visitLabel(l1); mv.visitInsn(ICONST_3); mv.visitLabel(end); mv.visitInsn(IRETURN); mv.visitLocalVariable("a", "Z", null, start, end, 0); mv.visitLocalVariable("i", "I", null, start, end, 1); String insn = TestHelper.getAsString(builder.finish(), "test_mth"); String good = "return a ? 6 : 3;"; Assert.assertEquals(good, insn); }
From source file:org.spongepowered.test.decompile.TryCatchTests.java
License:Open Source License
@Test public void testTryCatchReturnedTernary() { TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(Z)I"); MethodVisitor mv = builder.getGenerator(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception"); mv.visitLabel(l0);/* www . jav a2 s.c o m*/ mv.visitVarInsn(ILOAD, 1); Label l3 = new Label(); mv.visitJumpInsn(IFEQ, l3); mv.visitIntInsn(BIPUSH, 6); mv.visitJumpInsn(GOTO, l1); mv.visitLabel(l3); mv.visitInsn(ICONST_3); mv.visitLabel(l1); mv.visitInsn(IRETURN); mv.visitLabel(l2); mv.visitVarInsn(ASTORE, 2); Label l4 = new Label(); mv.visitLabel(l4); mv.visitInsn(ICONST_0); mv.visitInsn(IRETURN); Label l5 = new Label(); mv.visitLabel(l5); mv.visitLocalVariable("a", "Z", null, l0, l5, 1); mv.visitLocalVariable("e", "Ljava/lang/Exception;", null, l4, l5, 2); String insn = TestHelper.getAsString(builder.finish(), "test_mth"); String good = "try {\n" + " return a ? 6 : 3;\n" + "} catch (Exception e) {\n" + " return 0;\n" + "}"; Assert.assertEquals(good, insn); }
From source file:org.spongepowered.test.kotlin.OperatorTests.java
License:Open Source License
@Test public void testIntConstant() { TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(I)V"); MethodVisitor mv = builder.getGenerator(); Label start = new Label(); mv.visitLabel(start);//from ww w .j a va 2 s. c om Label end = new Label(); mv.visitIntInsn(BIPUSH, 65); mv.visitIntInsn(ISTORE, 0); mv.visitLabel(end); mv.visitInsn(RETURN); mv.visitLocalVariable("i", "I", null, start, end, 0); String insn = KotlinTestHelper.getMethodAsString(builder.finish(), "test_mth"); String good = "fun test_mth(i: Int) {\n" + " i = 65\n" + "}"; Assert.assertEquals(good, insn); }
From source file:org.spongepowered.test.kotlin.OperatorTests.java
License:Open Source License
@Test public void testNegative() { TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(II)V"); MethodVisitor mv = builder.getGenerator(); Label start = new Label(); mv.visitLabel(start);// ww w .ja va 2 s.co m Label end = new Label(); mv.visitIntInsn(ILOAD, 1); mv.visitInsn(INEG); 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); String insn = KotlinTestHelper.getMethodAsString(builder.finish(), "test_mth"); String good = "fun test_mth(i: Int, a: Int) {\n" + " i = -a\n" + "}"; Assert.assertEquals(good, insn); }
From source file:org.spongepowered.test.kotlin.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);//from w w w .j a v a 2 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 = KotlinTestHelper.getMethodAsString(builder.finish(), "test_mth"); String good = "fun test_mth(i: Int, a: Int, b: Int) {\n" + " i = a + b\n" + "}"; Assert.assertEquals(good, insn); }
From source file:org.spongepowered.test.kotlin.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 v a 2 s . c o 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 = KotlinTestHelper.getMethodAsString(builder.finish(), "test_mth"); String good = "fun test_mth(i: Int, a: Int, b: Int) {\n" + " i = a - b\n" + "}"; Assert.assertEquals(good, insn); }