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:edu.mit.streamjit.util.bytecode.MethodUnresolver.java

License:Open Source License

private void emit(ReturnInst i, InsnList insns) {
    ReturnType rt = i.getReturnType();/*from  w ww  . j a v  a  2s  .c om*/
    if (rt instanceof VoidType)
        insns.add(new InsnNode(Opcodes.RETURN));
    else {
        load(i.getOperand(0), insns);
        if (rt instanceof ReferenceType)
            insns.add(new InsnNode(Opcodes.ARETURN));
        else if (rt.isSubtypeOf(intType))
            insns.add(new InsnNode(Opcodes.IRETURN));
        else if (rt.equals(longType))
            insns.add(new InsnNode(Opcodes.LRETURN));
        else if (rt.equals(floatType))
            insns.add(new InsnNode(Opcodes.FRETURN));
        else if (rt.equals(doubleType))
            insns.add(new InsnNode(Opcodes.DRETURN));
        else
            throw new AssertionError(i);
    }
}

From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java

License:Open Source License

private void emit(StoreInst i, InsnList insns) {
    Value location = i.getLocation();/* w  w w  . j  a  v a  2s .  c om*/
    if (location instanceof LocalVariable) {
        load(i.getData(), insns);
        store(location, insns);
    } else {
        Field f = (Field) location;
        if (!f.isStatic())
            load(i.getInstance(), insns);
        load(i.getData(), insns);
        insns.add(new FieldInsnNode(f.isStatic() ? Opcodes.PUTSTATIC : Opcodes.PUTFIELD,
                internalName(f.getParent()), f.getName(), f.getType().getFieldType().getDescriptor()));
    }
}

From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java

License:Open Source License

private void emit(SwitchInst i, InsnList insns) {
    load(i.getValue(), insns);/*from  w  ww  .j  a v  a2  s. co m*/
    LookupSwitchInsnNode insn = new LookupSwitchInsnNode(null, null, null);
    insn.dflt = labels.get(i.getDefault());
    Iterator<Constant<Integer>> cases = i.cases().iterator();
    Iterator<BasicBlock> targets = i.successors().iterator();
    while (cases.hasNext()) {
        insn.keys.add(cases.next().getConstant());
        insn.labels.add(labels.get(targets.next()));
    }
    insns.add(insn);
}

From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java

License:Open Source License

private void emit(ThrowInst i, InsnList insns) {
    load(i.getOperand(0), insns);
    insns.add(new InsnNode(Opcodes.ATHROW));
}

From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java

License:Open Source License

private void load(Value v, InsnList insns) {
    if (v instanceof Constant) {
        Object c = ((Constant<?>) v).getConstant();
        if (c == null)
            insns.add(new InsnNode(Opcodes.ACONST_NULL));
        else if (c instanceof Class)
            insns.add(new LdcInsnNode(org.objectweb.asm.Type.getType((Class) c)));
        else if (c instanceof Boolean)
            insns.add(loadIntegerConstant(((Boolean) c) ? 1 : 0));
        else if (c instanceof Character)
            insns.add(loadIntegerConstant((int) ((Character) c).charValue()));
        else if (c instanceof Byte || c instanceof Short || c instanceof Integer)
            insns.add(loadIntegerConstant(((Number) c).intValue()));
        else if (c instanceof Long)
            insns.add(loadLongConstant((Long) c));
        else if (c instanceof Float)
            insns.add(loadFloatConstant((Float) c));
        else if (c instanceof Double)
            insns.add(loadDoubleConstant((Double) c));
        else/*from  www . ja va2 s.c  om*/
            insns.add(new LdcInsnNode(c));
        return;
    }

    assert registers.containsKey(v) : v;
    int reg = registers.get(v);
    Type t = v instanceof LocalVariable ? ((LocalVariable) v).getType().getFieldType() : v.getType();
    if (t instanceof ReferenceType || t instanceof NullType)
        insns.add(new VarInsnNode(Opcodes.ALOAD, reg));
    else if (t.equals(longType))
        insns.add(new VarInsnNode(Opcodes.LLOAD, reg));
    else if (t.equals(floatType))
        insns.add(new VarInsnNode(Opcodes.FLOAD, reg));
    else if (t.equals(doubleType))
        insns.add(new VarInsnNode(Opcodes.DLOAD, reg));
    else if (t.isSubtypeOf(intType))
        insns.add(new VarInsnNode(Opcodes.ILOAD, reg));
    else
        throw new AssertionError("unloadable value: " + v);
}

From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java

License:Open Source License

private void store(Value v, InsnList insns) {
    assert registers.containsKey(v) : v;
    int reg = registers.get(v);
    Type t = v instanceof LocalVariable ? ((LocalVariable) v).getType().getFieldType() : v.getType();
    if (t instanceof ReferenceType || t instanceof NullType)
        insns.add(new VarInsnNode(Opcodes.ASTORE, reg));
    else if (t.equals(longType))
        insns.add(new VarInsnNode(Opcodes.LSTORE, reg));
    else if (t.equals(floatType))
        insns.add(new VarInsnNode(Opcodes.FSTORE, reg));
    else if (t.equals(doubleType))
        insns.add(new VarInsnNode(Opcodes.DSTORE, reg));
    else if (t.isSubtypeOf(intType))
        insns.add(new VarInsnNode(Opcodes.ISTORE, reg));
    else/*ww w .j ava  2 s .co m*/
        throw new AssertionError("unstorable value: " + v);
}

From source file:fr.insalyon.telecom.jooflux.InvokeMethodTransformer.java

License:Mozilla Public License

private InsnList generateInvokeDynamicConstructor(String name, String owner, String desc) {
    InsnList insnList = new InsnList();
    Handle methodHandle = new Handle(Opcodes.H_INVOKESTATIC, BOOTSTRAP_CLASS, "dynvokeConstructor",
            BOOTSTRAP_SIGNATURE);//w w  w  .j av a  2s.c o m
    String descReceiver = Type.getMethodDescriptor(Type.getObjectType(owner), Type.getArgumentTypes(desc));
    insnList.add(new InvokeDynamicInsnNode(owner + "." + name, descReceiver, methodHandle, ""));
    return insnList;
}

From source file:fr.insalyon.telecom.jooflux.InvokeMethodTransformer.java

License:Mozilla Public License

private InsnList generateInvokeDynamicStatic(String name, String owner, String desc) {
    InsnList insnList = new InsnList();
    Handle methodHandle = new Handle(Opcodes.H_INVOKESTATIC, BOOTSTRAP_CLASS, "dynvokeStatic",
            BOOTSTRAP_SIGNATURE);/*from   w  w w.  j a va2 s  .  com*/
    insnList.add(new InvokeDynamicInsnNode(owner + "." + name, desc, methodHandle, ""));
    return insnList;
}

From source file:fr.insalyon.telecom.jooflux.InvokeMethodTransformer.java

License:Mozilla Public License

private InsnList generateInvokeDynamicVirtualInterfaceSpecial(String name, String owner, String desc,
        String bootstrapMethod) {
    InsnList insnList = new InsnList();
    Handle methodHandle = new Handle(Opcodes.H_INVOKESTATIC, BOOTSTRAP_CLASS, bootstrapMethod,
            BOOTSTRAP_SIGNATURE);//from   w w  w.j  a v a2 s .  c o  m
    List<Type> argsList = new ArrayList<Type>(Arrays.asList(new Type[] { Type.getObjectType(owner) }));
    argsList.addAll(Arrays.asList(Type.getArgumentTypes(desc)));
    String descReceiver = Type.getMethodDescriptor(Type.getReturnType(desc),
            argsList.toArray(new Type[argsList.size()]));
    insnList.add(new InvokeDynamicInsnNode(owner + "." + name, descReceiver, methodHandle, ""));
    return insnList;
}

From source file:gemlite.core.internal.asm.AsmHelper.java

License:Apache License

public final static void addTypeConvert(InsnList insn, String typeDesc) {
    switch (typeDesc) {
    case "I":
        insn.add(newMethodInsnNode(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;",
                false));/*from   w ww. ja  v  a2 s  .co m*/
        break;
    case "J":
        insn.add(newMethodInsnNode(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false));
        break;
    case "D":
        insn.add(
                newMethodInsnNode(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false));
        break;
    case "F":
        insn.add(newMethodInsnNode(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;", false));
        break;
    case "S":
        insn.add(newMethodInsnNode(INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;", false));
        break;
    case "Z":
        insn.add(newMethodInsnNode(INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;",
                false));
        break;
    case "B":
        insn.add(newMethodInsnNode(INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false));
        break;
    }
}