Search in sources :

Example 16 with FieldVisitor

use of org.objectweb.asm.FieldVisitor in project soot by Sable.

the class ExtendedArithmeticLibTest method generate.

@Override
protected void generate(TraceClassVisitor cw) {
    MethodVisitor mv;
    FieldVisitor fv;
    cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/ExtendedArithmeticLib", null, "java/lang/Object", null);
    cw.visitSource("ExtendedArithmeticLib.java", null);
    {
        fv = cw.visitField(ACC_PRIVATE, "i1", "I", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "f1", "F", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "l1", "J", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "d1", "D", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "s1", "S", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "b1", "B", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "i2", "I", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "f2", "F", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "l2", "J", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "d2", "D", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "i3", "I", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "f3", "F", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "l3", "J", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "d3", "D", null, null);
        fv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "doBNeg", "(B)I", null, null);
        mv.visitCode();
        mv.visitVarInsn(ILOAD, 1);
        mv.visitInsn(INEG);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "doCNeg", "(C)I", null, null);
        mv.visitCode();
        mv.visitVarInsn(ILOAD, 1);
        mv.visitInsn(INEG);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "doDNeg", "(D)D", null, null);
        mv.visitCode();
        mv.visitVarInsn(DLOAD, 1);
        mv.visitInsn(DNEG);
        mv.visitInsn(DRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "doFNeg", "(F)F", null, null);
        mv.visitCode();
        mv.visitVarInsn(FLOAD, 1);
        mv.visitInsn(FNEG);
        mv.visitInsn(FRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "doINeg", "(I)I", null, null);
        mv.visitCode();
        mv.visitVarInsn(ILOAD, 1);
        mv.visitInsn(INEG);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    if (targetCompiler == TargetCompiler.eclipse) {
        mv = cw.visitMethod(ACC_PUBLIC, "doInc", "()I", null, null);
        mv.visitCode();
        mv.visitInsn(ICONST_0);
        mv.visitVarInsn(ISTORE, 0);
        mv.visitInsn(ICONST_0);
        mv.visitVarInsn(ISTORE, 1);
        Label l0 = new Label();
        mv.visitJumpInsn(GOTO, l0);
        Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitIincInsn(0, 4);
        mv.visitIincInsn(1, 1);
        mv.visitLabel(l0);
        mv.visitVarInsn(ILOAD, 1);
        mv.visitIntInsn(BIPUSH, 100);
        mv.visitJumpInsn(IF_ICMPLT, l1);
        mv.visitVarInsn(ILOAD, 0);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    } else {
        mv = cw.visitMethod(ACC_PUBLIC, "doInc", "()I", null, null);
        mv.visitCode();
        mv.visitInsn(ICONST_0);
        mv.visitVarInsn(ISTORE, 0);
        mv.visitInsn(ICONST_0);
        mv.visitVarInsn(ISTORE, 1);
        Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitVarInsn(ILOAD, 1);
        mv.visitIntInsn(BIPUSH, 100);
        Label l1 = new Label();
        mv.visitJumpInsn(IF_ICMPGE, l1);
        mv.visitIincInsn(0, 4);
        mv.visitIincInsn(1, 1);
        mv.visitJumpInsn(GOTO, l0);
        mv.visitLabel(l1);
        mv.visitVarInsn(ILOAD, 0);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "doLNeg", "(J)J", null, null);
        mv.visitCode();
        mv.visitVarInsn(LLOAD, 1);
        mv.visitInsn(LRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "doMod", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "i2", "I");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "i3", "I");
        mv.visitInsn(IREM);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "i1", "I");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "f2", "F");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "f3", "F");
        mv.visitInsn(FREM);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "f1", "F");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "l2", "J");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "l3", "J");
        mv.visitInsn(LREM);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "l1", "J");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "d2", "D");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "d3", "D");
        mv.visitInsn(DREM);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "d1", "D");
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "doSNeg", "(S)I", null, null);
        mv.visitCode();
        mv.visitVarInsn(ILOAD, 1);
        mv.visitInsn(INEG);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "doSub", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "i2", "I");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "i3", "I");
        mv.visitInsn(ISUB);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "i1", "I");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "f2", "F");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "f3", "F");
        mv.visitInsn(FSUB);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "f1", "F");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "l2", "J");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "l3", "J");
        mv.visitInsn(LSUB);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "l1", "J");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "d2", "D");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "d3", "D");
        mv.visitInsn(DSUB);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "d1", "D");
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    cw.visitEnd();
}
Also used : Label(org.objectweb.asm.Label) FieldVisitor(org.objectweb.asm.FieldVisitor) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 17 with FieldVisitor

use of org.objectweb.asm.FieldVisitor in project soot by Sable.

the class ArithmeticTest method generate.

@Override
protected void generate(TraceClassVisitor cw) {
    FieldVisitor fv;
    MethodVisitor mv;
    cw.visit(V1_2, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/ArithmeticLib", null, "java/lang/Object", null);
    cw.visitSource("ArithmeticLib.java", null);
    {
        fv = cw.visitField(ACC_PRIVATE, "rInt", "I", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "rFloat", "F", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "rLong", "J", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "rDouble", "D", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "rShort", "S", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "rChar", "C", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE, "rByte", "B", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_FINAL, "cInt", "I", null, new Integer(1));
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_FINAL, "cFloat", "F", null, new Float("1.0"));
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_FINAL, "cLong", "J", null, new Long(1L));
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_FINAL, "cDouble", "D", null, new Double("1.0"));
        fv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(ICONST_1);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "cInt", "I");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(FCONST_1);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "cFloat", "F");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(LCONST_1);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "cLong", "J");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(DCONST_1);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "cDouble", "D");
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "castInt2Byte", "()B", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rInt", "I");
        mv.visitInsn(I2B);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rByte", "B");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rByte", "B");
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "castInt2Char", "()C", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rInt", "I");
        mv.visitInsn(I2C);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rChar", "C");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rChar", "C");
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "castInt2Short", "()S", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rInt", "I");
        mv.visitInsn(I2S);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rShort", "S");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rShort", "S");
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "doCompDouble", "(D)D", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(DLOAD, 1);
        mv.visitInsn(DCONST_1);
        mv.visitInsn(DDIV);
        mv.visitInsn(D2I);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rInt", "I");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(DLOAD, 1);
        mv.visitLdcInsn(new Double("6.0"));
        mv.visitInsn(DMUL);
        mv.visitInsn(D2L);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rLong", "J");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(DLOAD, 1);
        mv.visitInsn(DCONST_0);
        mv.visitInsn(DADD);
        mv.visitInsn(D2F);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rFloat", "F");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(DLOAD, 1);
        mv.visitLdcInsn(new Double("4.0"));
        mv.visitInsn(DSUB);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rDouble", "D");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rDouble", "D");
        mv.visitInsn(DRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "doCompFloat", "(F)F", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(FLOAD, 1);
        mv.visitLdcInsn(new Float("13.0"));
        mv.visitInsn(FDIV);
        mv.visitInsn(F2I);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rInt", "I");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(FLOAD, 1);
        mv.visitLdcInsn(new Float("3.0"));
        mv.visitInsn(FMUL);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rFloat", "F");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(FLOAD, 1);
        mv.visitInsn(FCONST_2);
        mv.visitInsn(FSUB);
        mv.visitInsn(F2L);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rLong", "J");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(FLOAD, 1);
        mv.visitInsn(FCONST_1);
        mv.visitInsn(FADD);
        mv.visitInsn(F2D);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rDouble", "D");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rFloat", "F");
        mv.visitInsn(FRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "doCompInt", "(I)I", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ILOAD, 1);
        mv.visitInsn(ICONST_M1);
        mv.visitInsn(IDIV);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rInt", "I");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ILOAD, 1);
        mv.visitIntInsn(BIPUSH, 17);
        mv.visitInsn(IMUL);
        mv.visitInsn(I2F);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rFloat", "F");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ILOAD, 1);
        mv.visitInsn(ICONST_5);
        mv.visitInsn(IADD);
        mv.visitInsn(I2L);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rLong", "J");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ILOAD, 1);
        mv.visitInsn(ICONST_2);
        mv.visitInsn(ISUB);
        mv.visitInsn(I2D);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rDouble", "D");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rInt", "I");
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "doCompLong", "(J)J", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(LLOAD, 1);
        mv.visitLdcInsn(new Long(5L));
        mv.visitInsn(LMUL);
        mv.visitInsn(L2I);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rInt", "I");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(LLOAD, 1);
        mv.visitLdcInsn(new Long(2L));
        mv.visitInsn(LADD);
        mv.visitInsn(L2F);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rFloat", "F");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(LLOAD, 1);
        mv.visitLdcInsn(new Long(6L));
        mv.visitInsn(LMUL);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rLong", "J");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(LLOAD, 1);
        mv.visitLdcInsn(new Long(6L));
        mv.visitInsn(LDIV);
        mv.visitInsn(L2D);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rDouble", "D");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rLong", "J");
        mv.visitInsn(LRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    cw.visitEnd();
}
Also used : FieldVisitor(org.objectweb.asm.FieldVisitor) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 18 with FieldVisitor

use of org.objectweb.asm.FieldVisitor in project soot by Sable.

the class ControlStructuresTest method generate.

@Override
protected void generate(TraceClassVisitor cw) {
    MethodVisitor mv;
    FieldVisitor fv;
    cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/ControlStructures", null, "java/lang/Object", null);
    cw.visitSource("ControlStructures.java", null);
    {
        fv = cw.visitField(0, "result", "Ljava/util/List;", "Ljava/util/List<Ljava/lang/Integer;>;", null);
        fv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PROTECTED, "get", "(I)Ljava/util/List;", "(I)Ljava/util/List<Ljava/lang/Integer;>;", null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitTypeInsn(NEW, "java/util/ArrayList");
        mv.visitInsn(DUP);
        mv.visitMethodInsn(INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V", false);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;");
        mv.visitVarInsn(ILOAD, 1);
        Label l0 = new Label();
        Label l1 = new Label();
        Label l2 = new Label();
        Label l3 = new Label();
        mv.visitTableSwitchInsn(1, 3, l3, new Label[] { l0, l1, l2 });
        mv.visitLabel(l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;");
        mv.visitInsn(ICONST_1);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
        mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true);
        mv.visitInsn(POP);
        Label l4 = new Label();
        mv.visitJumpInsn(GOTO, l4);
        mv.visitLabel(l1);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;");
        mv.visitInsn(ICONST_2);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
        mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true);
        mv.visitInsn(POP);
        mv.visitLabel(l2);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;");
        mv.visitInsn(ICONST_3);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
        mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true);
        mv.visitInsn(POP);
        mv.visitJumpInsn(GOTO, l4);
        mv.visitLabel(l3);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;");
        mv.visitInsn(ACONST_NULL);
        mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true);
        mv.visitInsn(POP);
        mv.visitLabel(l4);
        mv.visitVarInsn(ILOAD, 1);
        Label l5 = new Label();
        Label l6 = new Label();
        Label l7 = new Label();
        Label l8 = new Label();
        Label l9 = new Label();
        mv.visitLookupSwitchInsn(l9, new int[] { 1, 10, 100, 1000 }, new Label[] { l5, l6, l7, l8 });
        mv.visitLabel(l5);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;");
        mv.visitInsn(ICONST_1);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
        mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true);
        mv.visitInsn(POP);
        mv.visitLabel(l6);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;");
        mv.visitIntInsn(BIPUSH, 10);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
        mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true);
        mv.visitInsn(POP);
        mv.visitLabel(l7);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;");
        mv.visitIntInsn(BIPUSH, 100);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
        mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true);
        mv.visitInsn(POP);
        mv.visitLabel(l8);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;");
        mv.visitIntInsn(SIPUSH, 1000);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
        mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true);
        mv.visitInsn(POP);
        mv.visitLabel(l9);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;");
        mv.visitInsn(ACONST_NULL);
        mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true);
        mv.visitInsn(POP);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;");
        mv.visitInsn(ARETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    cw.visitEnd();
}
Also used : Label(org.objectweb.asm.Label) FieldVisitor(org.objectweb.asm.FieldVisitor) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 19 with FieldVisitor

use of org.objectweb.asm.FieldVisitor in project soot by Sable.

the class InnerClass2Test method generate.

@Override
protected void generate(TraceClassVisitor cw) {
    MethodVisitor mv;
    FieldVisitor fv;
    cw.visit(V1_1, ACC_SUPER, "soot/asm/backend/targets/InnerClass$1", null, "java/lang/Object", new String[] { "soot/asm/backend/targets/Measurable" });
    cw.visitSource("InnerClass.java", null);
    cw.visitOuterClass("soot/asm/backend/targets/InnerClass", "doInner", "()V");
    cw.visitInnerClass("soot/asm/backend/targets/InnerClass$1", null, null, 0);
    {
        fv = cw.visitField(ACC_FINAL + ACC_SYNTHETIC, "this$0", "Lsoot/asm/backend/targets/InnerClass;", null, null);
        fv.visitEnd();
    }
    {
        mv = cw.visitMethod(0, "<init>", "(Lsoot/asm/backend/targets/InnerClass;)V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/InnerClass$1", "this$0", "Lsoot/asm/backend/targets/InnerClass;");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    cw.visitEnd();
}
Also used : FieldVisitor(org.objectweb.asm.FieldVisitor) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 20 with FieldVisitor

use of org.objectweb.asm.FieldVisitor in project soot by Sable.

the class AnnotatedFieldTest method generate.

@Override
protected void generate(TraceClassVisitor cw) {
    FieldVisitor fv;
    MethodVisitor mv;
    AnnotationVisitor av0;
    cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/AnnotatedField", null, "java/lang/Object", null);
    cw.visitSource("AnnotatedField.java", null);
    {
        fv = cw.visitField(0, "a", "Ljava/lang/String;", null, null);
        {
            av0 = fv.visitAnnotation("Lsoot/asm/backend/targets/MyTestAnnotation;", true);
            av0.visit("iVal", new Integer(124));
            av0.visit("fVal", new Float("5132.0"));
            av0.visit("lVal", new Long(5123L));
            av0.visit("dVal", new Double("745.0"));
            av0.visit("zVal", Boolean.TRUE);
            av0.visit("bVal", new Byte((byte) 1));
            av0.visit("sVal", new Short((short) 123));
            av0.visit("strVal", "435243");
            av0.visit("rVal", Type.getType("Lsoot/asm/backend/targets/AnnotatedClass;"));
            av0.visit("iAVal", new int[] { 123, 234, 345, 456 });
            {
                AnnotationVisitor av1 = av0.visitArray("sAVal");
                av1.visit(null, "A");
                av1.visit(null, "B");
                av1.visit(null, "C");
                av1.visitEnd();
            }
            av0.visitEnd();
        }
        fv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    cw.visitEnd();
}
Also used : AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) FieldVisitor(org.objectweb.asm.FieldVisitor) MethodVisitor(org.objectweb.asm.MethodVisitor)

Aggregations

FieldVisitor (org.objectweb.asm.FieldVisitor)90 MethodVisitor (org.objectweb.asm.MethodVisitor)59 Label (org.objectweb.asm.Label)33 ClassWriter (org.objectweb.asm.ClassWriter)28 AnnotationVisitor (org.objectweb.asm.AnnotationVisitor)9 ClassReader (org.objectweb.asm.ClassReader)8 Type (org.objectweb.asm.Type)7 Method (java.lang.reflect.Method)6 ClassVisitor (org.objectweb.asm.ClassVisitor)6 IOException (java.io.IOException)4 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 LitString (lucee.transformer.expression.literal.LitString)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 PrintWriter (java.io.PrintWriter)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URL (java.net.URL)2