Java Code Examples for org.objectweb.asm.MethodVisitor#visitIincInsn()

The following examples show how to use org.objectweb.asm.MethodVisitor#visitIincInsn() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicTests.java    From Despector with MIT License 5 votes vote down vote up
@Test
public void testLocals() {
    TestMethodBuilder builder = new TestMethodBuilder("main", "()V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);
    Label end = new Label();
    mv.visitLdcInsn("Hello");
    mv.visitVarInsn(ASTORE, 0);
    Label start2 = new Label();
    mv.visitLabel(start2);
    mv.visitInsn(ICONST_2);
    mv.visitVarInsn(ISTORE, 1);
    mv.visitIincInsn(1, 5);
    mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", true);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("s", "Ljava/lang/String;", null, start, end, 0);
    mv.visitLocalVariable("a", "I", null, start2, end, 1);

    String insn = KotlinTestHelper.getMethodAsString(builder.finish(), "main");
    String good = "fun main() {\n"
            + "    val s: String = \"Hello\"\n"
            + "    var a: Int = 2\n"
            + "    a += 5\n"
            + "    println(s)\n"
            + "}";
    Assert.assertEquals(good, insn);
}
 
Example 2
Source File: WhileTests.java    From Despector with MIT License 5 votes vote down vote up
@Test
public void testFor() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(I)V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);
    Label end = new Label();
    Label l1 = new Label();
    mv.visitInsn(ICONST_0);
    mv.visitVarInsn(ISTORE, 0);
    mv.visitLabel(l1);
    mv.visitVarInsn(ILOAD, 0);
    mv.visitInsn(ICONST_5);
    mv.visitJumpInsn(IF_ICMPGE, end);
    mv.visitMethodInsn(INVOKESTATIC, THIS_TYPE.getInternalName(), "body", "()V", false);
    mv.visitIincInsn(0, 1);
    mv.visitJumpInsn(GOTO, l1);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("i", "I", null, start, end, 0);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "for (i = 0; i < 5; i++) {\n"
            + "    org.spongepowered.test.decompile.WhileTests.body();\n"
            + "}";
    Assert.assertEquals(good, insn);
}
 
Example 3
Source File: WhileTests.java    From Despector with MIT License 5 votes vote down vote up
@Test
public void testForInverse() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(I)V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);
    Label end = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    mv.visitInsn(ICONST_0);
    mv.visitVarInsn(ISTORE, 0);
    mv.visitJumpInsn(GOTO, l2);
    mv.visitLabel(l1);
    mv.visitMethodInsn(INVOKESTATIC, THIS_TYPE.getInternalName(), "body", "()V", false);
    mv.visitIincInsn(0, 1);
    mv.visitLabel(l2);
    mv.visitVarInsn(ILOAD, 0);
    mv.visitInsn(ICONST_5);
    mv.visitJumpInsn(IF_ICMPLT, l1);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("i", "I", null, start, end, 0);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "for (i = 0; i < 5; i++) {\n"
            + "    org.spongepowered.test.decompile.WhileTests.body();\n"
            + "}";
    Assert.assertEquals(good, insn);
}
 
Example 4
Source File: IincInsnNode.java    From Cafebabe with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void accept(final MethodVisitor methodVisitor) {
	methodVisitor.visitIincInsn(var, incr);
	acceptAnnotations(methodVisitor);
}
 
Example 5
Source File: IincInsnNode.java    From Concurnas with MIT License 4 votes vote down vote up
@Override
public void accept(final MethodVisitor methodVisitor) {
  methodVisitor.visitIincInsn(var, incr);
  acceptAnnotations(methodVisitor);
}
 
Example 6
Source File: IInc.java    From OSRS-Deobfuscator with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void accept(MethodVisitor visitor)
{
	visitor.visitIincInsn(index, inc);
}
 
Example 7
Source File: BFCompiler.java    From cs-summary-reflection with Apache License 2.0 4 votes vote down vote up
private int storeP(final MethodVisitor mv, final int p) {
    if (p != 0) {
        mv.visitIincInsn(V_P, p);
    }
    return 0;
}
 
Example 8
Source File: IincInsnNode.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void accept(final MethodVisitor mv) {
  mv.visitIincInsn(var, incr);
  acceptAnnotations(mv);
}
 
Example 9
Source File: StaticTypesStatementWriter.java    From groovy with Apache License 2.0 4 votes vote down vote up
private void writeOptimizedForEachLoop(
        CompileStack compileStack,
        OperandStack operandStack,
        MethodVisitor mv,
        ForStatement loop,
        Expression collectionExpression,
        ClassNode collectionType,
        Parameter loopVariable) {
    BytecodeVariable variable = compileStack.defineVariable(loopVariable, false);

    Label continueLabel = compileStack.getContinueLabel();
    Label breakLabel = compileStack.getBreakLabel();

    AsmClassGenerator acg = controller.getAcg();

    // load array on stack
    collectionExpression.visit(acg);
    mv.visitInsn(DUP);
    int array = compileStack.defineTemporaryVariable("$arr", collectionType, true);
    mv.visitJumpInsn(IFNULL, breakLabel);

    // $len = array.length
    mv.visitVarInsn(ALOAD, array);
    mv.visitInsn(ARRAYLENGTH);
    operandStack.push(ClassHelper.int_TYPE);
    int arrayLen = compileStack.defineTemporaryVariable("$len", ClassHelper.int_TYPE, true);

    // $idx = 0
    mv.visitInsn(ICONST_0);
    operandStack.push(ClassHelper.int_TYPE);
    int loopIdx = compileStack.defineTemporaryVariable("$idx", ClassHelper.int_TYPE, true);

    mv.visitLabel(continueLabel);
    // $idx<$len?
    mv.visitVarInsn(ILOAD, loopIdx);
    mv.visitVarInsn(ILOAD, arrayLen);
    mv.visitJumpInsn(IF_ICMPGE, breakLabel);

    // get array element
    loadFromArray(mv, variable, array, loopIdx);

    // $idx++
    mv.visitIincInsn(loopIdx, 1);

    // loop body
    loop.getLoopBlock().visit(acg);

    mv.visitJumpInsn(GOTO, continueLabel);

    mv.visitLabel(breakLabel);

    compileStack.removeVar(loopIdx);
    compileStack.removeVar(arrayLen);
    compileStack.removeVar(array);
}
 
Example 10
Source File: IincInsnNode.java    From JReFrameworker with MIT License 4 votes vote down vote up
@Override
public void accept(final MethodVisitor methodVisitor) {
  methodVisitor.visitIincInsn(var, incr);
  acceptAnnotations(methodVisitor);
}
 
Example 11
Source File: IincInsnNode.java    From JReFrameworker with MIT License 4 votes vote down vote up
@Override
public void accept(final MethodVisitor methodVisitor) {
  methodVisitor.visitIincInsn(var, incr);
  acceptAnnotations(methodVisitor);
}
 
Example 12
Source File: MethodVariableAccess.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) {
    methodVisitor.visitIincInsn(offset, value);
    return new Size(0, 0);
}