Example usage for org.objectweb.asm Opcodes ISTORE

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

Introduction

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

Prototype

int ISTORE

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

Click Source Link

Usage

From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java

License:Open Source License

private static int getStoreOpCode(JavaTypeName varType) {

    //ASM automatically handles replacing ISTORE 0, ISTORE 1, ISTORE 2 and ISTORE 3 by the special
    //0 argument op codes ISTORE_0, ISTORE_1, ISTORE_2, and ISTORE_3 and similarly for the other
    //types.//from   ww w  . j  a v  a  2  s. c  o  m

    switch (varType.getTag()) {

    case JavaTypeName.VOID_TAG:
        throw new IllegalArgumentException("Cannot load a local variable of void type.");

    case JavaTypeName.BOOLEAN_TAG:
    case JavaTypeName.BYTE_TAG:
    case JavaTypeName.SHORT_TAG:
    case JavaTypeName.CHAR_TAG:
    case JavaTypeName.INT_TAG:
        return Opcodes.ISTORE;

    case JavaTypeName.LONG_TAG:
        return Opcodes.LSTORE;

    case JavaTypeName.DOUBLE_TAG:
        return Opcodes.DSTORE;

    case JavaTypeName.FLOAT_TAG:
        return Opcodes.FSTORE;

    case JavaTypeName.ARRAY_TAG:
    case JavaTypeName.OBJECT_TAG:
        return Opcodes.ASTORE;

    default: {
        throw new IllegalArgumentException("Cannot load a local variable of type " + varType);
    }
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.AODMutator2.java

License:Apache License

@Override
public void visitInsn(int opcode) {
    switch (opcode) {
    case Opcodes.IADD:
    case Opcodes.ISUB:
    case Opcodes.IMUL:
    case Opcodes.IDIV:
    case Opcodes.IREM:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            int storage = this.newLocal(Type.INT_TYPE);
            mv.visitVarInsn(Opcodes.ISTORE, storage);
            mv.visitInsn(Opcodes.POP);/*from ww  w.j a v  a  2s .  co m*/
            mv.visitVarInsn(Opcodes.ILOAD, storage);
            /*
             * Alternative : mv.visitInsn(Opcodes.SWAP);
             * mv.visitInsn(Opcodes.POP);
             * mv.visitVarInsn(Opcodes.ILOAD,storage);
             */
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.FADD:
    case Opcodes.FSUB:
    case Opcodes.FMUL:
    case Opcodes.FDIV:
    case Opcodes.FREM:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            int storage = this.newLocal(Type.FLOAT_TYPE);
            mv.visitVarInsn(Opcodes.FSTORE, storage);
            mv.visitInsn(Opcodes.POP);
            mv.visitVarInsn(Opcodes.FLOAD, storage);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.LADD:
    case Opcodes.LSUB:
    case Opcodes.LMUL:
    case Opcodes.LDIV:
    case Opcodes.LREM:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            int storage = this.newLocal(Type.LONG_TYPE);
            mv.visitVarInsn(Opcodes.LSTORE, storage);
            mv.visitInsn(Opcodes.POP2);
            mv.visitVarInsn(Opcodes.LLOAD, storage);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.DADD:
    case Opcodes.DSUB:
    case Opcodes.DMUL:
    case Opcodes.DDIV:
    case Opcodes.DREM:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            int storage = this.newLocal(Type.DOUBLE_TYPE);
            mv.visitVarInsn(Opcodes.DSTORE, storage);
            mv.visitInsn(Opcodes.POP2);
            mv.visitVarInsn(Opcodes.DLOAD, storage);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    default:
        mv.visitInsn(opcode);
        break;
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.OBBNMutator3.java

License:Apache License

@Override
public void visitInsn(int opcode) {
    switch (opcode) {
    case Opcodes.IAND:
    case Opcodes.IOR:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            int storage = this.newLocal(Type.INT_TYPE);
            mv.visitVarInsn(Opcodes.ISTORE, storage);
            mv.visitInsn(Opcodes.POP);//from   w w w  .  jav a  2  s  .  com
            mv.visitVarInsn(Opcodes.ILOAD, storage);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.LAND:
    case Opcodes.LOR:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            int storage = this.newLocal(Type.LONG_TYPE);
            mv.visitVarInsn(Opcodes.LSTORE, storage);
            mv.visitInsn(Opcodes.POP2);
            mv.visitVarInsn(Opcodes.LLOAD, storage);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    default:
        mv.visitInsn(opcode);
        break;
    }
}

From source file:org.sonar.java.bytecode.se.BytecodeEGWalkerExecuteTest.java

License:Open Source License

@Test
public void test_store() throws Exception {
    int[] storeOpcodes = new int[] { Opcodes.ISTORE, Opcodes.LSTORE, Opcodes.FSTORE, Opcodes.DSTORE,
            Opcodes.ASTORE };// www  .j a  va  2s .c  o  m
    SymbolicValue sv = new SymbolicValue();
    ProgramState startState = ProgramState.EMPTY_STATE.stackValue(sv);
    for (int opcode : storeOpcodes) {
        ProgramState programState = execute(new Instruction(opcode, 67), startState);
        assertThat(programState.getValue(67)).isEqualTo(sv);
    }
}

From source file:org.spongepowered.asm.mixin.injection.callback.CallbackInjector.java

License:MIT License

/**
 * If this is a ReturnEventInfo AND we are right before a RETURN opcode (so
 * we can expect the *original* return value to be on the stack, then we dup
 * the return value into a local var so we can push it later when we invoke
 * the ReturnEventInfo ctor//  ww  w.  jav  a 2 s . c om
 * 
 * @param callback callback handle
 */
private void dupReturnValue(final Callback callback) {
    if (!callback.isAtReturn) {
        return;
    }

    callback.add(new InsnNode(Opcodes.DUP));
    callback.add(new VarInsnNode(callback.target.returnType.getOpcode(Opcodes.ISTORE), callback.marshallVar));
}

From source file:org.spongepowered.asm.mixin.injection.invoke.InvokeInjector.java

License:MIT License

/**
 * Store args on the stack to their positions allocated based on argMap
 * /*from   w w  w .ja v  a2  s. com*/
 * @param args argument types
 * @param insns instruction list to generate insns into
 * @param argMap generated argmap containing local indices for all args
 * @param start Starting index
 * @param end Ending index
 */
protected void storeArgs(Type[] args, InsnList insns, int[] argMap, int start, int end) {
    for (int arg = end - 1; arg >= start; arg--) {
        insns.add(new VarInsnNode(args[arg].getOpcode(Opcodes.ISTORE), argMap[arg]));
    }
}

From source file:org.spongepowered.despector.emitter.bytecode.statement.BytecodeLocalAssignmentEmitter.java

License:Open Source License

@Override
public void emit(BytecodeEmitterContext ctx, LocalAssignment stmt, boolean semicolon) {
    MethodVisitor mv = ctx.getMethodVisitor();
    TypeSignature type = stmt.getLocal().getType();
    ctx.emitInstruction(stmt.getValue(), type);
    if (type == ClassTypeSignature.INT || type == ClassTypeSignature.BOOLEAN || type == ClassTypeSignature.BYTE
            || type == ClassTypeSignature.SHORT || type == ClassTypeSignature.CHAR) {
        mv.visitVarInsn(Opcodes.ISTORE, stmt.getLocal().getIndex());
    } else if (type == ClassTypeSignature.LONG) {
        mv.visitVarInsn(Opcodes.LSTORE, stmt.getLocal().getIndex());
    } else if (type == ClassTypeSignature.FLOAT) {
        mv.visitVarInsn(Opcodes.FSTORE, stmt.getLocal().getIndex());
    } else if (type == ClassTypeSignature.DOUBLE) {
        mv.visitVarInsn(Opcodes.DSTORE, stmt.getLocal().getIndex());
    } else {/*from   w  ww  .  ja v a 2  s  .c o  m*/
        mv.visitVarInsn(Opcodes.ISTORE, stmt.getLocal().getIndex());
    }
    ctx.updateStack(-1);
}

From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java

License:Apache License

private void buildEndMethod(ClassVisitor cv, String className, Dfa dfa) {
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "end", "()" + Type.getDescriptor(Matcher.class), null,
            null);//from ww  w.  j av a2 s. com

    stateLabels = new Label[dfa.getStates().size()];
    Arrays.setAll(stateLabels, i -> new Label());
    int[] keys = new int[dfa.getStates().size()];
    Arrays.setAll(keys, IntUnaryOperator.identity());

    saveLabel = new Label();
    errorLabel = new Label();

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, "state", "I");
    mv.visitLookupSwitchInsn(errorLabel, keys, stateLabels);

    for (int i = 0; i < dfa.getStates().size(); ++i) {
        mv.visitLabel(stateLabels[i]);
        DfaTransition transition = dfa.getStates().get(i).getTransition(-1);
        if (transition == null) {
            mv.visitJumpInsn(Opcodes.GOTO, errorLabel);
        } else {
            DfaState target = transition.getTarget();
            mv.visitIntInsn(Opcodes.SIPUSH, transition.getTarget().getIndex());
            mv.visitVarInsn(Opcodes.ISTORE, 1);
            mv.visitIntInsn(Opcodes.SIPUSH, !target.isTerminal() ? -1 : target.getDomains()[0]);
            mv.visitVarInsn(Opcodes.ISTORE, 2);
            debug(mv, "DFA: " + i + " .-> " + target.getIndex() + " " + Arrays.toString(target.getDomains()));
            mv.visitJumpInsn(Opcodes.GOTO, saveLabel);
        }
    }

    mv.visitLabel(errorLabel);
    debug(mv, "DFA: error");
    mv.visitInsn(Opcodes.ICONST_M1);
    mv.visitVarInsn(Opcodes.ISTORE, 1);
    mv.visitInsn(Opcodes.ICONST_M1);
    mv.visitVarInsn(Opcodes.ISTORE, 2);
    mv.visitLabel(saveLabel);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ILOAD, 1);
    mv.visitFieldInsn(Opcodes.PUTFIELD, className, "state", "I");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitFieldInsn(Opcodes.PUTFIELD, className, "domain", "I");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitInsn(Opcodes.ARETURN);

    mv.visitMaxs(3, 3);
    mv.visitEnd();
}

From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java

License:Apache License

private void buildWorkerMethod(ClassVisitor cv, String className, Dfa dfa) {
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "feed",
            "(Ljava/lang/String;IIZ)" + Type.getDescriptor(Matcher.class), null, null);
    mv.visitCode();//from   ww w.  ja v  a  2  s .com

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, "state", "I");
    mv.visitVarInsn(Opcodes.ISTORE, 5);

    errorLabel = new Label();
    saveLabel = new Label();
    loopLabel = new Label();
    continueLabel = new Label();

    mv.visitLabel(loopLabel);
    generateLengthGuard(mv);

    stateLabels = new Label[dfa.getStates().size()];
    Arrays.setAll(stateLabels, i -> new Label());
    int[] keys = new int[dfa.getStates().size()];
    Arrays.setAll(keys, IntUnaryOperator.identity());

    mv.visitVarInsn(Opcodes.ILOAD, 5);
    mv.visitLookupSwitchInsn(errorLabel, keys, stateLabels);

    mv.visitLabel(continueLabel);
    mv.visitIincInsn(2, 1);
    mv.visitJumpInsn(Opcodes.GOTO, loopLabel);

    mv.visitLabel(errorLabel);
    debug(mv, "DFA: error");
    mv.visitInsn(Opcodes.ICONST_M1);
    mv.visitVarInsn(Opcodes.ISTORE, 5);

    mv.visitLabel(saveLabel);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ILOAD, 5);
    mv.visitFieldInsn(Opcodes.PUTFIELD, className, "state", "I");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitFieldInsn(Opcodes.PUTFIELD, className, "index", "I");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitInsn(Opcodes.ARETURN);

    for (int i = 0; i < dfa.getStates().size(); ++i) {
        mv.visitLabel(stateLabels[i]);
        DfaState state = dfa.getStates().get(i);
        generateTransitions(state, mv);
    }

    mv.visitMaxs(3, 6);
    mv.visitEnd();
}

From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java

License:Apache License

private void generateLengthGuard(MethodVisitor mv) {
    mv.visitVarInsn(Opcodes.ILOAD, 3);/*from w  w w . j ava  2  s .  co  m*/
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitInsn(Opcodes.ISUB);
    mv.visitJumpInsn(Opcodes.IFLE, saveLabel);

    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "charAt", "(I)C", false);
    mv.visitVarInsn(Opcodes.ISTORE, 6);

    if (debugMode) {
        mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", Type.getDescriptor(PrintStream.class));
        mv.visitInsn(Opcodes.DUP);
        mv.visitLdcInsn("DFA <- ");
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "print", "(Ljava/lang/String;)V",
                false);
        mv.visitInsn(Opcodes.DUP);
        mv.visitVarInsn(Opcodes.ILOAD, 6);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "print", "(C)V", false);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "()V", false);
    }
}