Search in sources :

Example 1 with Opcode

use of org.freud.analysed.classbytecode.method.instruction.Opcode in project freud by LMAX-Exchange.

the class AsmMethod method visitTypeInsn.

public void visitTypeInsn(final int opcodeUsed, final String type) {
    final Opcode opcode = OPCODES_ARRAY[opcodeUsed];
    final String operandType = "L" + type + ";";
    final Instruction instruction = new ReferenceOperandInstruction(instructionList.size(), opcode, currentLineNumber, operandType);
    updateCurrentState(instruction);
}
Also used : ReferenceOperandInstruction(org.freud.analysed.classbytecode.method.instruction.ReferenceOperandInstruction) Opcode(org.freud.analysed.classbytecode.method.instruction.Opcode) Instruction(org.freud.analysed.classbytecode.method.instruction.Instruction) ReferenceOperandInstruction(org.freud.analysed.classbytecode.method.instruction.ReferenceOperandInstruction) VarInstruction(org.freud.analysed.classbytecode.method.instruction.VarInstruction) JumpInstruction(org.freud.analysed.classbytecode.method.instruction.JumpInstruction) ConstInstruction(org.freud.analysed.classbytecode.method.instruction.ConstInstruction) FieldInstruction(org.freud.analysed.classbytecode.method.instruction.FieldInstruction) IntOperandInstruction(org.freud.analysed.classbytecode.method.instruction.IntOperandInstruction) MethodInvocationInstruction(org.freud.analysed.classbytecode.method.instruction.MethodInvocationInstruction)

Example 2 with Opcode

use of org.freud.analysed.classbytecode.method.instruction.Opcode in project freud by LMAX-Exchange.

the class AsmMethod method updateCurrentState.

private void updateCurrentState(final Instruction instruction) {
    instructionList.add(instruction);
    //        System.out.println(name + " " + instruction + " "  + labelByAsmLabelMap);
    final Opcode opcode = instruction.getOpcode();
    ensureCurrentLocalsSize(instruction.getVarIndex());
    currentLocals = opcode.updateLocals(currentLocals, instruction);
    currentOperandStack = opcode.updateOperandStack(this, instruction, currentOperandStack);
    instruction.setOperandStack(currentOperandStack);
}
Also used : Opcode(org.freud.analysed.classbytecode.method.instruction.Opcode)

Example 3 with Opcode

use of org.freud.analysed.classbytecode.method.instruction.Opcode in project freud by LMAX-Exchange.

the class ClassByteCodeMethodMatchers method containsInstructions.

public static FreudExtendedMatcher<ClassByteCodeMethod> containsInstructions(final Opcode... opcodes) {
    return new FreudExtendedMatcher<ClassByteCodeMethod>() {

        private Instruction found = null;

        @Override
        protected boolean matchesSafely(final ClassByteCodeMethod item) {
            item.findInstruction(new AbstractInstructionVisitor() {

                @Override
                public void noArgInstruction(final Instruction instruction) {
                    for (int i = 0; i < opcodes.length; i++) {
                        Opcode opcode = opcodes[i];
                        if (instruction.getOpcode() == opcode) {
                            found = instruction;
                            break;
                        }
                    }
                }
            });
            return found != null;
        }

        @Override
        public void describeTo(final Description description) {
            description.appendText("containsInstructions(");
            for (int i = 0; i < opcodes.length; i++) {
                Opcode opcode = opcodes[i];
                description.appendText(opcode.name());
                description.appendText(", ");
            }
            description.appendText(") found");
        }
    };
}
Also used : Description(org.hamcrest.Description) ClassByteCodeMethod(org.freud.analysed.classbytecode.method.ClassByteCodeMethod) Opcode(org.freud.analysed.classbytecode.method.instruction.Opcode) Instruction(org.freud.analysed.classbytecode.method.instruction.Instruction) FreudExtendedMatcher(org.freud.java.matcher.FreudExtendedMatcher) AbstractInstructionVisitor(org.freud.analysed.classbytecode.method.instruction.AbstractInstructionVisitor)

Example 4 with Opcode

use of org.freud.analysed.classbytecode.method.instruction.Opcode in project freud by LMAX-Exchange.

the class AsmMethod method visitIntInsn.

public void visitIntInsn(final int opcodeUsed, final int operand) {
    final Opcode opcode = OPCODES_ARRAY[opcodeUsed];
    final Instruction instruction;
    if (opcode == Opcode.NEWARRAY) {
        instruction = new ReferenceOperandInstruction(instructionList.size(), opcode, currentLineNumber, NEWARRAY_TYPES[operand]);
    } else {
        instruction = new IntOperandInstruction(instructionList.size(), opcode, currentLineNumber, operand);
    }
    updateCurrentState(instruction);
}
Also used : IntOperandInstruction(org.freud.analysed.classbytecode.method.instruction.IntOperandInstruction) ReferenceOperandInstruction(org.freud.analysed.classbytecode.method.instruction.ReferenceOperandInstruction) Opcode(org.freud.analysed.classbytecode.method.instruction.Opcode) Instruction(org.freud.analysed.classbytecode.method.instruction.Instruction) ReferenceOperandInstruction(org.freud.analysed.classbytecode.method.instruction.ReferenceOperandInstruction) VarInstruction(org.freud.analysed.classbytecode.method.instruction.VarInstruction) JumpInstruction(org.freud.analysed.classbytecode.method.instruction.JumpInstruction) ConstInstruction(org.freud.analysed.classbytecode.method.instruction.ConstInstruction) FieldInstruction(org.freud.analysed.classbytecode.method.instruction.FieldInstruction) IntOperandInstruction(org.freud.analysed.classbytecode.method.instruction.IntOperandInstruction) MethodInvocationInstruction(org.freud.analysed.classbytecode.method.instruction.MethodInvocationInstruction)

Example 5 with Opcode

use of org.freud.analysed.classbytecode.method.instruction.Opcode in project freud by LMAX-Exchange.

the class ClassByteCodeDsl method containsInstructions.

public static boolean containsInstructions(final ClassByteCodeMethod analysed, final Opcode... opcodes) {
    final Instruction[] found = new Instruction[1];
    analysed.findInstruction(new AbstractInstructionVisitor() {

        @Override
        public void noArgInstruction(final Instruction instruction) {
            for (int i = 0; i < opcodes.length; i++) {
                Opcode opcode = opcodes[i];
                if (instruction.getOpcode() == opcode) {
                    found[0] = instruction;
                    break;
                }
            }
        }
    });
    return found[0] != null;
}
Also used : Opcode(org.freud.analysed.classbytecode.method.instruction.Opcode) Instruction(org.freud.analysed.classbytecode.method.instruction.Instruction) AbstractInstructionVisitor(org.freud.analysed.classbytecode.method.instruction.AbstractInstructionVisitor)

Aggregations

Opcode (org.freud.analysed.classbytecode.method.instruction.Opcode)5 Instruction (org.freud.analysed.classbytecode.method.instruction.Instruction)4 AbstractInstructionVisitor (org.freud.analysed.classbytecode.method.instruction.AbstractInstructionVisitor)2 ConstInstruction (org.freud.analysed.classbytecode.method.instruction.ConstInstruction)2 FieldInstruction (org.freud.analysed.classbytecode.method.instruction.FieldInstruction)2 IntOperandInstruction (org.freud.analysed.classbytecode.method.instruction.IntOperandInstruction)2 JumpInstruction (org.freud.analysed.classbytecode.method.instruction.JumpInstruction)2 MethodInvocationInstruction (org.freud.analysed.classbytecode.method.instruction.MethodInvocationInstruction)2 ReferenceOperandInstruction (org.freud.analysed.classbytecode.method.instruction.ReferenceOperandInstruction)2 VarInstruction (org.freud.analysed.classbytecode.method.instruction.VarInstruction)2 ClassByteCodeMethod (org.freud.analysed.classbytecode.method.ClassByteCodeMethod)1 FreudExtendedMatcher (org.freud.java.matcher.FreudExtendedMatcher)1 Description (org.hamcrest.Description)1