@Override public void execute(ExecutionNode node, MethodState mState) { HeapItem item = mState.readRegister(register); // Mark register as assigned because next op will be payload, and it uses assigned register in this op to // determine target register for payload. mState.assignRegister(register, item); // It needs to know return address when finished since payload ops do not continue to next address. mState.setPseudoInstructionReturnLocation(returnLocation); }
@Override public void execute(ExecutionNode node, ExecutionContext context) { // TODO: https://github.com/CalebFenton/simplify/issues/22 MethodState mState = context.getMethodState(); HeapItem instanceItem = mState.readRegister(instanceRegister); String type = fieldDescriptor.split(":")[1]; mState.assignRegister(destRegister, HeapItem.newUnknown(type)); }
public void assignParameter(int parameterRegister, HeapItem item) { assignRegister(parameterRegister, item, METHOD_HEAP); boolean mutable = !item.isImmutable(); if (mutable) { pokeRegister(parameterRegister, item, MUTABLE_PARAMETER_HEAP); mutableParameters.add(parameterRegister); } }
@Override public void execute(ExecutionNode node, ExecutionContext context) { MethodState mState = context.getMethodState(); HeapItem valueItem = mState.readRegister(valueRegister); HeapItem instanceItem = mState.readRegister(instanceRegister); mState.assignRegister(instanceRegister, instanceItem); }
@Override public void execute(ExecutionNode node, ExecutionContext context) { StaticFieldAccessor accessor = vm.getStaticFieldAccessor(); HeapItem item = accessor.getField(context, actualField); MethodState mState = context.getMethodState(); mState.assignRegister(destRegister, item); }
public static void verifyExceptionHandling(Set<Throwable> expectedExceptions, ExecutionNode node, MethodState mState) { verify(node).setExceptions(eq(expectedExceptions)); verify(node).clearChildren(); verify(node, times(0)).setChildLocations(any(MethodLocation[].class)); verify(mState, times(0)).assignRegister(any(Integer.class), any(HeapItem.class)); }
public static void verifyExceptionHandling(Class<? extends Throwable> exceptionClass, String message, ExecutionNode node, MethodState mState) { ArgumentCaptor<Throwable> argument = ArgumentCaptor.forClass(Throwable.class); verify(node).setException(argument.capture()); assertEquals(exceptionClass, argument.getValue().getClass()); assertEquals(message, argument.getValue().getMessage()); verify(node).clearChildren(); verify(node, times(0)).setChildLocations(any(MethodLocation[].class)); verify(mState, times(0)).assignRegister(any(Integer.class), any(HeapItem.class)); }
@Test public void canFloatToDouble() { Float value = 11204.0345F; when(item.getValue()).thenReturn(value); when(item.getType()).thenReturn("F"); when(instruction.getOpcode()).thenReturn(Opcode.FLOAT_TO_DOUBLE); op = (UnaryMathOp) opFactory.create(location, addressToLocation, vm); op.execute(node, mState); verify(mState, times(1)).assignRegister(eq(REGISTER_A), eq(new HeapItem(value.doubleValue(), "D"))); }
@Test public void canFloatToInt() { Float value = 11204.0345F; when(item.getValue()).thenReturn(value); when(item.getType()).thenReturn("F"); when(instruction.getOpcode()).thenReturn(Opcode.FLOAT_TO_INT); op = (UnaryMathOp) opFactory.create(location, addressToLocation, vm); op.execute(node, mState); verify(mState, times(1)).assignRegister(eq(REGISTER_A), eq(new HeapItem(value.intValue(), "I"))); }
@Test public void canLongToDouble() { Long value = 112040345L; when(item.getValue()).thenReturn(value); when(item.getType()).thenReturn("J"); when(instruction.getOpcode()).thenReturn(Opcode.LONG_TO_DOUBLE); op = (UnaryMathOp) opFactory.create(location, addressToLocation, vm); op.execute(node, mState); verify(mState, times(1)).assignRegister(eq(REGISTER_A), eq(new HeapItem(value.doubleValue(), "D"))); }
@Test public void canLongToInt() { Long value = 112040345L; when(item.getValue()).thenReturn(value); when(item.getType()).thenReturn("J"); when(instruction.getOpcode()).thenReturn(Opcode.LONG_TO_INT); op = (UnaryMathOp) opFactory.create(location, addressToLocation, vm); op.execute(node, mState); verify(mState, times(1)).assignRegister(eq(REGISTER_A), eq(new HeapItem(value.intValue(), "I"))); }
@Test public void canDoubleToLong() { Double value = 11204.0345612345D; when(item.getValue()).thenReturn(value); when(item.getType()).thenReturn("D"); when(instruction.getOpcode()).thenReturn(Opcode.DOUBLE_TO_LONG); op = (UnaryMathOp) opFactory.create(location, addressToLocation, vm); op.execute(node, mState); verify(mState, times(1)).assignRegister(eq(REGISTER_A), eq(new HeapItem(value.longValue(), "J"))); }
@Test public void canIntToByte() { Integer value = 10; when(item.getValue()).thenReturn(value); when(item.getType()).thenReturn("I"); when(instruction.getOpcode()).thenReturn(Opcode.INT_TO_BYTE); op = (UnaryMathOp) opFactory.create(location, addressToLocation, vm); op.execute(node, mState); verify(mState, times(1)).assignRegister(eq(REGISTER_A), eq(new HeapItem(value.byteValue(), "B"))); }
@Override public void execute(ExecutionNode node, MethodState mState) { Object constant = buildConstant(); if (constant instanceof Throwable) { node.setException((Throwable) constant); node.clearChildren(); return; } else { node.clearExceptions(); } mState.assignRegister(destRegister, constant, getConstantTypeString()); }
@Override public void execute(ExecutionNode node, MethodState mState) { HeapItem lengthItem = mState.readRegister(lengthRegister); Object instance = buildInstance(lengthItem); if (instance instanceof Throwable) { node.setException((Throwable) instance); node.clearChildren(); return; } else { node.clearExceptions(); } mState.assignRegister(destRegister, instance, arrayType); }
@Test public void intDivisionWithLiteralEqualsExpected() { int value1 = 10; int value2 = 4; int expected = value1 / value2; VMTester.setRegisterMock(mState, ARG1_REGISTER, value1, "I"); buildInstruction22s(Opcode.DIV_INT, value2); op = opFactory.create(location, addressToLocation, vm); op.execute(node, mState); verify(mState, times(1)).assignRegister(eq(DEST_REGISTER), eq(expected), eq("I")); }
@Test public void canFloatToLong() { Float value = 11204.0345F; when(item.getValue()).thenReturn(value); when(item.getType()).thenReturn("F"); when(instruction.getOpcode()).thenReturn(Opcode.FLOAT_TO_LONG); op = (UnaryMathOp) opFactory.create(location, addressToLocation, vm); op.execute(node, mState); verify(mState, times(1)).assignRegister(eq(REGISTER_A), eq(new HeapItem(value.longValue(), "J"))); }
@Test public void canLongToFloat() { Long value = 112040345L; when(item.getValue()).thenReturn(value); when(item.getType()).thenReturn("J"); when(instruction.getOpcode()).thenReturn(Opcode.LONG_TO_FLOAT); op = (UnaryMathOp) opFactory.create(location, addressToLocation, vm); op.execute(node, mState); verify(mState, times(1)).assignRegister(eq(REGISTER_A), eq(new HeapItem(value.floatValue(), "F"))); }
@Test public void doubleDivisionWithTwoRegistersEqualsExpected() { double value1 = 1586.2D; double value2 = 2536.9D; double expected = value1 / value2; VMTester.setRegisterMock(mState, ARG1_REGISTER, value1, "D"); VMTester.setRegisterMock(mState, ARG2_REGISTER, value2, "D"); buildInstruction12x(Opcode.DIV_DOUBLE); op = opFactory.create(location, addressToLocation, vm); op.execute(node, mState); verify(mState, times(1)).assignRegister(eq(ARG1_REGISTER), eq(expected), eq("D")); }
@Test public void floatDivisionWithTwoRegistersEqualsExpected() { float value1 = 1120403456.43F; float value2 = 1149239296.32F; float expected = value1 / value2; VMTester.setRegisterMock(mState, ARG1_REGISTER, value1, "F"); VMTester.setRegisterMock(mState, ARG2_REGISTER, value2, "F"); buildInstruction12x(Opcode.DIV_FLOAT); op = opFactory.create(location, addressToLocation, vm); op.execute(node, mState); verify(mState, times(1)).assignRegister(eq(ARG1_REGISTER), eq(expected), eq("F")); }