Search in sources :

Example 6 with LookupSwitchInsnNode

use of org.objectweb.asm.tree.LookupSwitchInsnNode in project maple-ir by LLVM-but-worse.

the class LookupSwitchInsnNodeSerializer method deserialize.

@Override
public LookupSwitchInsnNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObject = (JsonObject) json;
    LabelNode dflt = context.deserialize(jsonObject.get("dflt"), LabelNode.class);
    List<Integer> keysList = context.deserialize(jsonObject.get("keys"), List.class);
    List<LabelNode> labelsList = context.deserialize(jsonObject.get("labels"), List.class);
    int[] keys = new int[keysList.size()];
    for (int i = 0; i < keys.length; i++) {
        keys[i] = keysList.get(i);
    }
    LabelNode[] labels = new LabelNode[labelsList.size()];
    for (int i = 0; i < labels.length; i++) {
        labels[i] = labelsList.get(i);
    }
    return new LookupSwitchInsnNode(dflt, keys, labels);
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) JsonObject(com.google.gson.JsonObject) LookupSwitchInsnNode(org.objectweb.asm.tree.LookupSwitchInsnNode)

Example 7 with LookupSwitchInsnNode

use of org.objectweb.asm.tree.LookupSwitchInsnNode in project nuls by nuls-io.

the class VM method gasCost.

public int gasCost(Frame frame, OpCode opCode) {
    int gasCost = 1;
    switch(opCode) {
        case NOP:
            break;
        case ACONST_NULL:
        case ICONST_M1:
        case ICONST_0:
        case ICONST_1:
        case ICONST_2:
        case ICONST_3:
        case ICONST_4:
        case ICONST_5:
        case LCONST_0:
        case LCONST_1:
        case FCONST_0:
        case FCONST_1:
        case FCONST_2:
        case DCONST_0:
        case DCONST_1:
        case BIPUSH:
        case SIPUSH:
            gasCost = GasCost.CONSTANT;
            break;
        case LDC:
            Object value = frame.ldcInsnNode().cst;
            if (value instanceof Number) {
                gasCost = GasCost.LDC;
            } else {
                gasCost = Math.max(value.toString().length(), 1) * GasCost.LDC;
            }
            break;
        case ILOAD:
        case LLOAD:
        case FLOAD:
        case DLOAD:
        case ALOAD:
            gasCost = GasCost.LOAD;
            break;
        case IALOAD:
        case LALOAD:
        case FALOAD:
        case DALOAD:
        case AALOAD:
        case BALOAD:
        case CALOAD:
        case SALOAD:
            gasCost = GasCost.ARRAYLOAD;
            break;
        case ISTORE:
        case LSTORE:
        case FSTORE:
        case DSTORE:
        case ASTORE:
            gasCost = GasCost.STORE;
            break;
        case IASTORE:
        case LASTORE:
        case FASTORE:
        case DASTORE:
        case AASTORE:
        case BASTORE:
        case CASTORE:
        case SASTORE:
            gasCost = GasCost.ARRAYSTORE;
            break;
        case POP:
        case POP2:
        case DUP:
        case DUP_X1:
        case DUP_X2:
        case DUP2:
        case DUP2_X1:
        case DUP2_X2:
        case SWAP:
            gasCost = GasCost.STACK;
            break;
        case IADD:
        case LADD:
        case FADD:
        case DADD:
        case ISUB:
        case LSUB:
        case FSUB:
        case DSUB:
        case IMUL:
        case LMUL:
        case FMUL:
        case DMUL:
        case IDIV:
        case LDIV:
        case FDIV:
        case DDIV:
        case IREM:
        case LREM:
        case FREM:
        case DREM:
        case INEG:
        case LNEG:
        case FNEG:
        case DNEG:
        case ISHL:
        case LSHL:
        case ISHR:
        case LSHR:
        case IUSHR:
        case LUSHR:
        case IAND:
        case LAND:
        case IOR:
        case LOR:
        case IXOR:
        case LXOR:
        case IINC:
            gasCost = GasCost.MATH;
            break;
        case I2L:
        case I2F:
        case I2D:
        case L2I:
        case L2F:
        case L2D:
        case F2I:
        case F2L:
        case F2D:
        case D2I:
        case D2L:
        case D2F:
        case I2B:
        case I2C:
        case I2S:
            gasCost = GasCost.CONVERSION;
            break;
        case LCMP:
        case FCMPL:
        case FCMPG:
        case DCMPL:
        case DCMPG:
        case IFEQ:
        case IFNE:
        case IFLT:
        case IFGE:
        case IFGT:
        case IFLE:
        case IF_ICMPEQ:
        case IF_ICMPNE:
        case IF_ICMPLT:
        case IF_ICMPGE:
        case IF_ICMPGT:
        case IF_ICMPLE:
        case IF_ACMPEQ:
        case IF_ACMPNE:
            gasCost = GasCost.COMPARISON;
            break;
        case GOTO:
        case JSR:
        case RET:
            gasCost = GasCost.CONTROL;
            break;
        case TABLESWITCH:
            TableSwitchInsnNode table = frame.tableSwitchInsnNode();
            gasCost = Math.max(table.max - table.min, 1) * GasCost.TABLESWITCH;
            break;
        case LOOKUPSWITCH:
            LookupSwitchInsnNode lookup = frame.lookupSwitchInsnNode();
            gasCost = Math.max(lookup.keys.size(), 1) * GasCost.LOOKUPSWITCH;
            break;
        case IRETURN:
        case LRETURN:
        case FRETURN:
        case DRETURN:
        case ARETURN:
        case RETURN:
            gasCost = GasCost.CONTROL;
            break;
        case GETSTATIC:
        case PUTSTATIC:
        case GETFIELD:
        case PUTFIELD:
        case INVOKEVIRTUAL:
        case INVOKESPECIAL:
        case INVOKESTATIC:
        case INVOKEINTERFACE:
        case INVOKEDYNAMIC:
        case NEW:
            gasCost = GasCost.REFERENCE;
            break;
        case NEWARRAY:
        case ANEWARRAY:
            int count = frame.operandStack.popInt();
            gasCost = Math.max(count, 1) * GasCost.NEWARRAY;
            frame.operandStack.pushInt(count);
            break;
        case ARRAYLENGTH:
        case ATHROW:
        case CHECKCAST:
        case INSTANCEOF:
        case MONITORENTER:
        case MONITOREXIT:
            gasCost = GasCost.REFERENCE;
            break;
        case MULTIANEWARRAY:
            MultiANewArrayInsnNode multiANewArrayInsnNode = frame.multiANewArrayInsnNode();
            int size = 1;
            int[] dimensions = new int[multiANewArrayInsnNode.dims];
            for (int i = multiANewArrayInsnNode.dims - 1; i >= 0; i--) {
                int length = frame.operandStack.popInt();
                if (length > 0) {
                    size *= length;
                }
                dimensions[i] = length;
            }
            for (int dimension : dimensions) {
                frame.operandStack.pushInt(dimension);
            }
            gasCost = size * GasCost.MULTIANEWARRAY;
            break;
        case IFNULL:
        case IFNONNULL:
            gasCost = GasCost.EXTENDED;
            break;
        default:
            break;
    }
    return gasCost;
}
Also used : TableSwitchInsnNode(org.objectweb.asm.tree.TableSwitchInsnNode) MultiANewArrayInsnNode(org.objectweb.asm.tree.MultiANewArrayInsnNode) LookupSwitchInsnNode(org.objectweb.asm.tree.LookupSwitchInsnNode)

Example 8 with LookupSwitchInsnNode

use of org.objectweb.asm.tree.LookupSwitchInsnNode in project nuls by nuls-io.

the class Lookupswitch method lookupswitch.

public static void lookupswitch(final Frame frame) {
    LookupSwitchInsnNode lookup = frame.lookupSwitchInsnNode();
    LabelNode labelNode = lookup.dflt;
    int key = frame.operandStack.popInt();
    for (int i = 0; i < lookup.keys.size(); i++) {
        int k = lookup.keys.get(i);
        if (k == key) {
            labelNode = lookup.labels.get(i);
            break;
        }
    }
    frame.jump(labelNode);
// Log.opcode(frame.getCurrentOpCode());
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) LookupSwitchInsnNode(org.objectweb.asm.tree.LookupSwitchInsnNode)

Aggregations

LookupSwitchInsnNode (org.objectweb.asm.tree.LookupSwitchInsnNode)8 LabelNode (org.objectweb.asm.tree.LabelNode)6 TableSwitchInsnNode (org.objectweb.asm.tree.TableSwitchInsnNode)4 MultiANewArrayInsnNode (org.objectweb.asm.tree.MultiANewArrayInsnNode)3 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)2 IincInsnNode (org.objectweb.asm.tree.IincInsnNode)2 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)2 JsonObject (com.google.gson.JsonObject)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)1 FrameNode (org.objectweb.asm.tree.FrameNode)1 IntInsnNode (org.objectweb.asm.tree.IntInsnNode)1 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)1 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)1 LineNumberNode (org.objectweb.asm.tree.LineNumberNode)1 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)1