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

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

Introduction

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

Prototype

InsnList

Source Link

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));
    }/* w w w.  j  a  v a  2s.  c o m*/
    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  ww. j  a  v a2s . co 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));
    }//www  .j  a va 2s  .  c  o  m
    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 w  w w .j  ava2 s. co  m*/
    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  .j av  a  2s.  com*/
        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   w w w. j  a  v  a 2  s  . c  om
    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 w  w  . ja  v  a 2s .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;// w  w w  .  j a  v a2s .  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;/*  www .ja v  a2  s .  co m*/
}

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");
    }//from  www . j a  va2s .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;
}