Example usage for org.objectweb.asm.tree InsnList add

List of usage examples for org.objectweb.asm.tree InsnList add

Introduction

In this page you can find the example usage for org.objectweb.asm.tree InsnList add.

Prototype

public void add(final InsnList insnList) 

Source Link

Document

Adds the given instructions to the end of this list.

Usage

From source file:pl.clareo.coroutines.core.CodeGenerationUtils.java

License:Apache License

static InsnList box_double(int varIndex, int typeSort) {
    InsnList insn = new InsnList();
    if (varIndex >= 0) {
        insn.add(new VarInsnNode(DLOAD, varIndex));
    }//from ww w  . j a  va2  s .  com
    if (typeSort != Type.DOUBLE) {
        throw new CoroutineGenerationException("box_double:Not a double");
    }
    insn.add(new MethodInsnNode(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;"));
    return insn;
}

From source file:pl.clareo.coroutines.core.CodeGenerationUtils.java

License:Apache License

static InsnList box_float(int varIndex, int typeSort) {
    InsnList insn = new InsnList();
    if (varIndex >= 0) {
        insn.add(new VarInsnNode(FLOAD, varIndex));
    }/*w  w w.jav a 2s  . c o  m*/
    if (typeSort != Type.FLOAT) {
        throw new CoroutineGenerationException("box_float:Not a float");
    }
    insn.add(new MethodInsnNode(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;"));
    return insn;
}

From source file:pl.clareo.coroutines.core.CodeGenerationUtils.java

License:Apache License

static InsnList box_int(int varIndex, int typeSort) {
    InsnList result = new InsnList();
    if (varIndex >= 0) {
        result.add(new VarInsnNode(ILOAD, varIndex));
    }//from ww  w .  j  av a 2  s  .com
    switch (typeSort) {
    /*
     * case Type.BOOLEAN: result.add(new MethodInsnNode(INVOKESTATIC,
     * "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;"));
     * break; case Type.CHAR: result.add(new
     * MethodInsnNode(INVOKESTATIC, "java/lang/Character", "valueOf",
     * "(C)Ljava/lang/Character;")); break; case Type.BYTE:
     * result.add(new MethodInsnNode(INVOKESTATIC, "java/lang/Byte",
     * "valueOf", "(B)Ljava/lang/Byte;")); break; case Type.SHORT:
     * result.add(new MethodInsnNode(INVOKESTATIC, "java/lang/Short",
     * "valueOf", "(S)Ljava/lang/Short;")); break;
     */
    case Type.BOOLEAN:
    case Type.CHAR:
    case Type.BYTE:
    case Type.INT:
    case Type.SHORT:
        result.add(new MethodInsnNode(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;"));
        break;
    default:
        throw new CoroutineGenerationException("box_int:Not an int");
    }
    return result;
}

From source file:pl.clareo.coroutines.core.CodeGenerationUtils.java

License:Apache License

static InsnList box_long(int varIndex, int typeSort) {
    InsnList insn = new InsnList();
    if (varIndex >= 0) {
        insn.add(new VarInsnNode(LLOAD, varIndex));
    }//from   ww w  . ja  v  a2s. c om
    if (typeSort != Type.LONG) {
        throw new CoroutineGenerationException("box_long:Not a long");
    }
    insn.add(new MethodInsnNode(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;"));
    return insn;
}

From source file:pl.clareo.coroutines.core.CodeGenerationUtils.java

License:Apache License

static InsnList getloc(int frameArrayIndex, int varIndex, int fromIndex, Type type) {
    InsnList insn = new InsnList();
    int typeSort = type.getSort();
    if (typeSort == Type.VOID) {
        insn.add(new InsnNode(ACONST_NULL));
        insn.add(new VarInsnNode(ASTORE, varIndex));
    } else {//  w w w.ja v a  2  s .  c  o  m
        insn.add(new VarInsnNode(ALOAD, frameArrayIndex));
        insn.add(makeInt(fromIndex));
        insn.add(new InsnNode(AALOAD));
        switch (typeSort) {
        case Type.BOOLEAN:
        case Type.CHAR:
        case Type.BYTE:
        case Type.SHORT:
        case Type.INT:
            insn.add(unbox_int(varIndex, typeSort));
            break;
        case Type.FLOAT:
            insn.add(unbox_float(varIndex, typeSort));
            break;
        case Type.LONG:
            insn.add(unbox_long(varIndex, typeSort));
            break;
        case Type.DOUBLE:
            insn.add(unbox_double(varIndex, typeSort));
            break;
        case Type.ARRAY:
        case Type.OBJECT:
            if (!type.equals(JAVA_LANG_OBJECT)) {
                insn.add(new TypeInsnNode(CHECKCAST, type.getInternalName()));
            }
            insn.add(new VarInsnNode(ASTORE, varIndex));
            break;
        }
    }
    return insn;
}

From source file:pl.clareo.coroutines.core.CodeGenerationUtils.java

License:Apache License

static InsnList getlocs(int frameArrayIndex, int startIndex, int fromIndex, Type... types) {
    int varIndex = startIndex;
    int i = 0;/*from   www . j  a va2s . co  m*/
    InsnList insn = new InsnList();
    while (i < types.length) {
        Type type = types[i];
        insn.add(getloc(frameArrayIndex, varIndex, fromIndex, type));
        varIndex += type.getSize();
        fromIndex += type.getSize();
        i++;
    }
    return insn;
}

From source file:pl.clareo.coroutines.core.CodeGenerationUtils.java

License:Apache License

static InsnList saveloc(int frameArrayIndex, int varIndex, int toIndex, Type type) {
    InsnList insn = new InsnList();
    insn.add(new VarInsnNode(ALOAD, frameArrayIndex));
    insn.add(makeInt(toIndex));/*from w ww .  j a v a 2 s .  co  m*/
    int typeSort = type.getSort();
    switch (typeSort) {
    case Type.BOOLEAN:
    case Type.CHAR:
    case Type.BYTE:
    case Type.SHORT:
    case Type.INT:
        insn.add(box_int(varIndex, typeSort));
        break;
    case Type.FLOAT:
        insn.add(box_float(varIndex, typeSort));
        break;
    case Type.LONG:
        insn.add(box_long(varIndex, typeSort));
        break;
    case Type.DOUBLE:
        insn.add(box_double(varIndex, typeSort));
        break;
    case Type.ARRAY:
    case Type.OBJECT:
        insn.add(new VarInsnNode(ALOAD, varIndex));
        break;
    case Type.VOID:
        insn.add(new InsnNode(ACONST_NULL));
        break;
    }
    insn.add(new InsnNode(AASTORE));
    return insn;
}

From source file:pl.clareo.coroutines.core.CodeGenerationUtils.java

License:Apache License

static InsnList savelocs(int frameArrayIndex, int startIndex, int toIndex, Type... types) {
    InsnList insn = new InsnList();
    int varIndex = startIndex;
    int i = 0;/*ww  w . j a  v a  2s .c o m*/
    while (i < types.length) {
        Type type = types[i];
        insn.add(saveloc(frameArrayIndex, varIndex, toIndex, type));
        varIndex += type.getSize();
        toIndex += type.getSize();
        i++;
    }
    return insn;
}

From source file:pl.clareo.coroutines.core.CodeGenerationUtils.java

License:Apache License

static InsnList throwex(String ex) {
    InsnList insn = new InsnList();
    insn.add(new TypeInsnNode(NEW, ex));
    insn.add(new InsnNode(DUP));
    insn.add(new MethodInsnNode(INVOKESPECIAL, ex, "<init>", "()V"));
    insn.add(new InsnNode(ATHROW));
    return insn;//ww w  . ja  v  a2  s.  com
}

From source file:pl.clareo.coroutines.core.CodeGenerationUtils.java

License:Apache License

static InsnList unbox_double(int varIndex, int typeSort) {
    if (typeSort != Type.DOUBLE) {
        throw new CoroutineGenerationException("unbox_double:Not a double");
    }/*www  . j  a va2 s .  c o m*/
    InsnList insn = new InsnList();
    insn.add(new TypeInsnNode(CHECKCAST, "java/lang/Double"));
    insn.add(new MethodInsnNode(INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D"));
    if (varIndex >= 0) {
        insn.add(new VarInsnNode(DSTORE, varIndex));
    }
    return insn;
}