Example usage for org.objectweb.asm Opcodes LLOAD

List of usage examples for org.objectweb.asm Opcodes LLOAD

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes LLOAD.

Prototype

int LLOAD

To view the source code for org.objectweb.asm Opcodes LLOAD.

Click Source Link

Usage

From source file:com.codename1.tools.translator.bytecodes.ArithmeticExpression.java

public static boolean isArg(Instruction instr) {
    if (instr instanceof ArithmeticExpression) {
        return true;
    }//from  w  w  w .  java2 s.c  o  m
    if (instr instanceof AssignableExpression) {
        StringBuilder dummy = new StringBuilder();

        if (((AssignableExpression) instr).assignTo(null, dummy)) {
            return true;
        }
    }
    int opcode = instr.getOpcode();
    switch (opcode) {

    case Opcodes.FLOAD:
    case Opcodes.DLOAD:
    case Opcodes.ILOAD:
    case Opcodes.LLOAD:
    case org.objectweb.asm.Opcodes.ICONST_0:
    case org.objectweb.asm.Opcodes.ICONST_1:
    case org.objectweb.asm.Opcodes.ICONST_2:
    case org.objectweb.asm.Opcodes.ICONST_3:
    case org.objectweb.asm.Opcodes.ICONST_4:
    case org.objectweb.asm.Opcodes.ICONST_5:
    case org.objectweb.asm.Opcodes.ICONST_M1:
    case org.objectweb.asm.Opcodes.LCONST_0:
    case org.objectweb.asm.Opcodes.LCONST_1:
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
    case Opcodes.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
    case org.objectweb.asm.Opcodes.BIPUSH:
    case org.objectweb.asm.Opcodes.SIPUSH:
    case Opcodes.LDC:
        return true;
    }
    return false;
}

From source file:com.codename1.tools.translator.bytecodes.ArithmeticExpression.java

public String getExpressionAsString() {

    Instruction instr = lastInstruction;
    int opcode = lastInstruction.getOpcode();
    if (subExpression == null) {
        // This is the root of it... probably an FLOAD
        if (lastInstruction instanceof AssignableExpression
                && !(lastInstruction instanceof ArithmeticExpression)) {
            StringBuilder out = new StringBuilder();
            if (((AssignableExpression) lastInstruction).assignTo(null, out)) {
                String strOut = out.toString();
                if (strOut.trim().isEmpty()) {
                    throw new RuntimeException("Instruction produces blank string output: " + lastInstruction);
                }//  w w w. ja  va 2s  .  c o  m
                if (strOut == null || "null".equals(strOut)) {
                    throw new RuntimeException(
                            "ArithmeticExpression produced null value.  This shouldn't happen: "
                                    + lastInstruction);
                }
                return strOut;
            }
        }

        if (lastInstruction instanceof VarOp) {
            VarOp var = (VarOp) lastInstruction;
            switch (opcode) {
            case Opcodes.FLOAD: {
                return "flocals_" + var.getIndex() + "_";

            }
            case Opcodes.DLOAD: {
                return "dlocals_" + var.getIndex() + "_";
            }

            case Opcodes.ILOAD: {
                return "ilocals_" + var.getIndex() + "_";
            }

            case Opcodes.LLOAD: {
                return "llocals_" + var.getIndex() + "_";
            }

            case org.objectweb.asm.Opcodes.ICONST_0: {
                return "0";

            }
            case org.objectweb.asm.Opcodes.ICONST_1: {
                return "1";

            }
            case org.objectweb.asm.Opcodes.ICONST_2: {
                return "2";

            }
            case org.objectweb.asm.Opcodes.ICONST_3: {
                return "3";

            }
            case org.objectweb.asm.Opcodes.ICONST_4: {
                return "4";

            }
            case org.objectweb.asm.Opcodes.ICONST_5: {
                return "5";

            }
            case org.objectweb.asm.Opcodes.ICONST_M1: {
                return "(-1)";

            }
            case org.objectweb.asm.Opcodes.LCONST_0: {
                return "((JAVA_LONG)0)";

            }
            case Opcodes.DCONST_0: {
                return "((JAVA_DOUBLE)0)";
            }
            case Opcodes.DCONST_1: {
                return "((JAVA_DOUBLE)1)";
            }
            case Opcodes.FCONST_0: {
                return "((JAVA_FLOAT)0)";
            }
            case Opcodes.FCONST_1: {
                return "((JAVA_FLOAT)1)";
            }
            case Opcodes.FCONST_2: {
                return "((JAVA_FLOAT)2";
            }

            case org.objectweb.asm.Opcodes.LCONST_1: {
                return "((JAVA_LONG)1)";

            }
            case org.objectweb.asm.Opcodes.BIPUSH:
            case org.objectweb.asm.Opcodes.SIPUSH: {
                return String.valueOf(var.getIndex());
            }
            default: {
                throw new RuntimeException("Unsupported Opcode in ArithmeticExpression: " + opcode + " " + var);
            }
            }
        } else {
            switch (instr.getOpcode()) {

            case org.objectweb.asm.Opcodes.ICONST_0: {
                return "0";

            }
            case org.objectweb.asm.Opcodes.ICONST_1: {
                return "1";

            }
            case org.objectweb.asm.Opcodes.ICONST_2: {
                return "2";

            }
            case org.objectweb.asm.Opcodes.ICONST_3: {
                return "3";

            }
            case org.objectweb.asm.Opcodes.ICONST_4: {
                return "4";

            }
            case org.objectweb.asm.Opcodes.ICONST_5: {
                return "5";

            }
            case org.objectweb.asm.Opcodes.ICONST_M1: {
                return "(-1)";

            }
            case org.objectweb.asm.Opcodes.LCONST_0: {
                return "((JAVA_LONG)0)";

            }
            case org.objectweb.asm.Opcodes.LCONST_1: {
                return "(JAVA_LONG)1";

            }
            case org.objectweb.asm.Opcodes.BIPUSH: {
                if (instr instanceof BasicInstruction) {
                    return String.valueOf(((BasicInstruction) instr).getValue());
                }
                break;
            }
            case org.objectweb.asm.Opcodes.LDC: {
                if (instr instanceof Ldc) {
                    Ldc ldc = (Ldc) instr;
                    return ldc.getValueAsString();

                }
                break;
            }
            default: {
                throw new RuntimeException(
                        "Unsupported Opcode in ArithmeticExpression: " + opcode + " " + instr);
            }

            }
        }

    } else {

        switch (opcode) {

        case Opcodes.ISHL: {
            return "BC_ISHL_EXPR(" + subExpression.getExpressionAsString().trim() + ", "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }
        case Opcodes.ISHR: {
            return "BC_ISHR_EXPR(" + subExpression.getExpressionAsString().trim() + ", "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }
        case Opcodes.LSHL: {
            return "BC_LSHL_EXPR(" + subExpression.getExpressionAsString().trim() + ", "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }
        case Opcodes.LSHR: {
            return "BC_LSHR_EXPR(" + subExpression.getExpressionAsString().trim() + ", "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }
        case Opcodes.IUSHR: {
            return "BC_IUSHR_EXPR(" + subExpression.getExpressionAsString().trim() + ", "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }
        case Opcodes.LUSHR: {
            return "BC_LUSHR_EXPR(" + subExpression.getExpressionAsString().trim() + ", "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }

        case Opcodes.DCMPG:
        case Opcodes.DCMPL:
        case Opcodes.FCMPG:
        case Opcodes.FCMPL:
        case Opcodes.LCMP: {
            return "CN1_CMP_EXPR(" + subExpression.getExpressionAsString().trim() + ", "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }
        case Opcodes.D2F: {
            return "((JAVA_FLOAT)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.F2D: {
            return subExpression.getExpressionAsString().trim();
        }
        case Opcodes.F2I: {
            return "((JAVA_INT)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.F2L: {
            return "((JAVA_LONG)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.D2I: {
            return "((JAVA_INT)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.D2L: {
            return "((JAVA_LONG)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.I2B: {
            return "((" + subExpression.getExpressionAsString() + " << 24) >> 24)";
        }
        case Opcodes.I2C: {
            return "(" + subExpression.getExpressionAsString().trim() + " & 0xffff)";
        }
        case Opcodes.I2D: {
            return "((JAVA_DOUBLE)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.I2F: {
            return "((JAVA_FLOAT)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.I2L: {
            return "((JAVA_LONG)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.I2S: {
            return "((" + subExpression.getExpressionAsString().trim() + " << 16) >> 16)";
        }
        case Opcodes.L2D: {
            return "((JAVA_DOUBLE)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.L2F: {
            return "((JAVA_FLOAT)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.L2I: {
            return "((JAVA_INT)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.IAND:
        case Opcodes.LAND: {
            return "(" + subExpression.getExpressionAsString().trim() + " & "
                    + subExpression2.getExpressionAsString().trim() + ")";

        }
        case Opcodes.IOR:
        case Opcodes.LOR: {
            return "(" + subExpression.getExpressionAsString().trim() + " | "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }
        case Opcodes.IXOR:
        case Opcodes.LXOR: {
            return "(" + subExpression.getExpressionAsString().trim() + " ^ "
                    + subExpression2.getExpressionAsString().trim() + ")";

        }
        case Opcodes.DADD:
        case Opcodes.IADD:
        case Opcodes.LADD:
        case Opcodes.FADD: {
            return "(" + subExpression.getExpressionAsString().trim() + " + "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }

        case Opcodes.DSUB:
        case Opcodes.ISUB:
        case Opcodes.LSUB:
        case Opcodes.FSUB: {
            return "(" + subExpression.getExpressionAsString().trim() + " - "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }

        case Opcodes.DMUL:
        case Opcodes.IMUL:
        case Opcodes.LMUL:
        case Opcodes.FMUL: {
            return "(" + subExpression.getExpressionAsString().trim() + " * "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }

        case Opcodes.DDIV:
        case Opcodes.IDIV:
        case Opcodes.LDIV:
        case Opcodes.FDIV: {
            return "(" + subExpression.getExpressionAsString().trim() + " / "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }

        case Opcodes.FREM:
        case Opcodes.DREM: {
            return "fmod(" + subExpression.getExpressionAsString().trim() + ", "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }

        case Opcodes.LREM:
        case Opcodes.IREM: {
            if (subExpression2.getExpressionAsString() == null
                    || "null".equals(subExpression2.getExpressionAsString())) {
                throw new RuntimeException("2nd param of REM is null.  Should never happen.  Expression is "
                        + subExpression2 + " with last instruction " + subExpression2.lastInstruction);
            }
            return "(" + subExpression.getExpressionAsString().trim() + " % "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }

        case Opcodes.FNEG:
        case Opcodes.INEG:
        case Opcodes.LNEG:
        case Opcodes.DNEG:
            return "(-(" + subExpression.getExpressionAsString().trim() + "))";

        default: {
            throw new RuntimeException("Unsupported Opcode in ArithmeticExpression: " + opcode + " " + instr);
        }

        }
    }
    throw new RuntimeException("Did not return a value in getExpressionAsString() with lastInstruction "
            + lastInstruction + " subExpression " + subExpression + " and subExpression2 " + subExpression2);
}

From source file:com.codename1.tools.translator.bytecodes.VarOp.java

License:Open Source License

@Override
public boolean assignTo(String varName, StringBuilder sb) {
    StringBuilder b = new StringBuilder();

    /*//from  ww w .  j  a va 2  s. c o  m
    if (typeVarName != null) {
    switch (opcode) {
        case Opcodes.ALOAD:
            b.append("locals[");
            b.append(var);
            b.append("].type = CN1_TYPE_OBJECT; ");
            break;
    }
    }*/
    if (varName != null) {
        b.append("    ");
        b.append(varName).append(" = ");
    }
    switch (opcode) {
    case Opcodes.ILOAD:
        b.append("ilocals_");
        b.append(var);
        b.append("_");
        break;
    case Opcodes.LLOAD:
        b.append("llocals_");
        b.append(var);
        b.append("_");
        break;
    case Opcodes.FLOAD:
        b.append("flocals_");
        b.append(var);
        b.append("_");
        break;
    case Opcodes.DLOAD:
        b.append("dlocals_");
        b.append(var);
        b.append("_");
        break;
    case Opcodes.ALOAD:
        if (getMethod() != null && !getMethod().isStatic() && var == 0) {
            b.append("__cn1ThisObject");
        } else {
            b.append("locals[");
            b.append(var);
            b.append("].data.o");
        }
        break;
    default:
        return false;

    }
    if (varName != null) {
        b.append(";\n");
    }
    sb.append(b);
    return true;
}

From source file:com.codename1.tools.translator.bytecodes.VarOp.java

License:Open Source License

@Override
public void appendInstruction(StringBuilder b) {
    b.append("    ");
    switch (opcode) {
    case Opcodes.ILOAD:
        b.append("(*SP).type = CN1_TYPE_INT; /* ILOAD */ \n" + "    (*SP).data.i = ilocals_");
        b.append(var);
        b.append("_; \n    SP++;\n");
        return;/*from   www  .ja va 2  s . c  o m*/
    case Opcodes.LLOAD:
        b.append("BC_LLOAD(");
        break;
    case Opcodes.FLOAD:
        b.append("BC_FLOAD(");
        break;
    case Opcodes.DLOAD:
        b.append("BC_DLOAD(");
        break;
    case Opcodes.ALOAD:
        b.append("BC_ALOAD(");
        break;
    case Opcodes.ISTORE:
        b.append("BC_ISTORE(");
        break;
    case Opcodes.LSTORE:
        b.append("BC_LSTORE(");
        break;
    case Opcodes.FSTORE:
        b.append("BC_FSTORE(");
        break;
    case Opcodes.DSTORE:
        b.append("BC_DSTORE(");
        break;
    case Opcodes.ASTORE:
        b.append("BC_ASTORE(");
        break;
    case Opcodes.RET:
        b.append("/* RET TODO */");
        //b.append("goto label_");
        //b.append(var);
        //b.append("; /* RET */\n");
        return;
    case Opcodes.SIPUSH:
    case Opcodes.BIPUSH:
        b.append("PUSH_INT(");
        break;
    case Opcodes.NEWARRAY:
        switch (var) {
        case 4: // boolean
            b.append(
                    "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_BOOLEAN, sizeof(JAVA_ARRAY_BOOLEAN), 1));\n");
            break;
        case 5: // char
            b.append(
                    "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_CHAR, sizeof(JAVA_ARRAY_CHAR), 1));\n");
            break;
        case 6: // float
            b.append(
                    "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_FLOAT, sizeof(JAVA_ARRAY_FLOAT), 1));\n");
            break;
        case 7: // double
            b.append(
                    "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_DOUBLE, sizeof(JAVA_ARRAY_DOUBLE), 1));\n");
            break;
        case 8: // byte
            b.append(
                    "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_BYTE, sizeof(JAVA_ARRAY_BYTE), 1));\n");
            break;
        case 9: // short
            b.append(
                    "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_SHORT, sizeof(JAVA_ARRAY_SHORT), 1));\n");
            break;
        case 10: // int
            b.append(
                    "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_INT, sizeof(JAVA_ARRAY_INT), 1));\n");
            break;
        case 11: // long 
            b.append(
                    "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_LONG, sizeof(JAVA_ARRAY_LONG), 1));\n");
            break;
        }
        return;
    default:
        throw new RuntimeException("Missing opcode: " + opcode);
    }
    b.append(var);
    b.append(");\n");
}

From source file:com.geeksaga.light.profiler.util.ASMUtil.java

License:Apache License

public static VarInsnNode createLLOAD(int index) {
    return new VarInsnNode(Opcodes.LLOAD, index);
}

From source file:com.github.anba.es6draft.compiler.assembler.InstructionAssembler.java

License:Open Source License

private void load(int var, Type type) {
    assert var >= 0 && variables.isActive(var) : "variable is not initialized";
    switch (type.getOpcode(Opcodes.ILOAD)) {
    case Opcodes.ILOAD:
        iload(var);
        return;//from  www .jav  a2s .c  o  m
    case Opcodes.LLOAD:
        lload(var);
        return;
    case Opcodes.FLOAD:
        fload(var);
        return;
    case Opcodes.DLOAD:
        dload(var);
        return;
    case Opcodes.ALOAD:
        aload(var);
        return;
    default:
        throw new IllegalArgumentException();
    }
}

From source file:com.github.anba.es6draft.compiler.assembler.InstructionAssembler.java

License:Open Source License

private void lload(int var) {
    methodVisitor.visitVarInsn(Opcodes.LLOAD, var);
    stack.lload(var);
}

From source file:com.google.devtools.build.android.desugar.BytecodeTypeInference.java

License:Open Source License

@Override
public void visitVarInsn(int opcode, int var) {
    switch (opcode) {
    case Opcodes.ILOAD:
        push(InferredType.INT);/* w w  w.jav  a  2 s.c  o m*/
        break;
    case Opcodes.LLOAD:
        push(InferredType.LONG);
        push(InferredType.TOP);
        break;
    case Opcodes.FLOAD:
        push(InferredType.FLOAT);
        break;
    case Opcodes.DLOAD:
        push(InferredType.DOUBLE);
        push(InferredType.TOP);
        break;
    case Opcodes.ALOAD:
        push(getLocalVariableType(var));
        break;
    case Opcodes.ISTORE:
    case Opcodes.FSTORE:
    case Opcodes.ASTORE: {
        InferredType type = pop();
        setLocalVariableTypes(var, type);
        break;
    }
    case Opcodes.LSTORE:
    case Opcodes.DSTORE: {
        InferredType type = pop(2);
        setLocalVariableTypes(var, type);
        setLocalVariableTypes(var + 1, InferredType.TOP);
        break;
    }
    case Opcodes.RET:
        throw new RuntimeException("The instruction RET is not supported");
    default:
        throw new RuntimeException("Unhandled opcode " + opcode);
    }
    super.visitVarInsn(opcode, var);
}

From source file:com.google.devtools.build.wireless.testing.java.injector.TimeServant.java

License:Apache License

/**
 * Reloads from a previously saved stack a negative timestamp to which the new
 * time is added. The result is left on top of the stack.
 * //  w  w  w .jav a 2 s.  com
 * @param indexInStack The index in stack from where to load the 
 *    previously saved time;
 * @throws IllegalArgumentException If the index is negative.
 */
public void stopCountingTime(int indexInStack) {
    if (indexInStack < 0) {
        throw new IllegalArgumentException("Index in stack must be >= 0");
    }
    mv.visitVarInsn(Opcodes.LLOAD, indexInStack);
    loadCurrentTimeMillis();
    mv.visitInsn(Opcodes.LADD);
}

From source file:com.google.devtools.build.wireless.testing.java.injector.TypeDescriptorTest.java

License:Apache License

/**
 * Test method for {@link TypeDescriptor#getLoadOpcode()}.
 *//*from  w  w  w .ja v  a 2  s  . c  om*/
public void testGetLoadOpcode() {
    try {
        TypeDescriptor.VOID.getLoadOpcode();
        fail("Void should have thrown an exception!");
    } catch (IllegalStateException e) {
        // OK!
    }
    assertEquals("Wrong LOAD instruction", Opcodes.ILOAD, TypeDescriptor.BOOLEAN.getLoadOpcode());
    assertEquals("Wrong STORE instruction", Opcodes.ILOAD, TypeDescriptor.BYTE.getLoadOpcode());
    assertEquals("Wrong STORE instruction", Opcodes.ILOAD, TypeDescriptor.CHAR.getLoadOpcode());
    assertEquals("Wrong STORE instruction", Opcodes.ILOAD, TypeDescriptor.SHORT.getLoadOpcode());
    assertEquals("Wrong STORE instruction", Opcodes.ILOAD, TypeDescriptor.INTEGER.getLoadOpcode());
    assertEquals("Wrong STORE instruction", Opcodes.LLOAD, TypeDescriptor.LONG.getLoadOpcode());
    assertEquals("Wrong STORE instruction", Opcodes.FLOAD, TypeDescriptor.FLOAT.getLoadOpcode());
    assertEquals("Wrong STORE instruction", Opcodes.DLOAD, TypeDescriptor.DOUBLE.getLoadOpcode());
    assertEquals("Wrong STORE instruction", Opcodes.ALOAD, TypeDescriptor.CLASS.getLoadOpcode());
    assertEquals("Wrong STORE instruction", Opcodes.ALOAD, TypeDescriptor.ARRAY.getLoadOpcode());
}