use of net.runelite.asm.execution.Variables in project runelite by runelite.
the class IfEqTest method testIsSame.
@Test
public void testIsSame() {
Instructions ins = mock(Instructions.class);
Frame originalIfEqFrame = mock(Frame.class);
Stack stack = new Stack(42);
Variables variables = new Variables(42);
when(originalIfEqFrame.getStack()).thenReturn(stack);
when(originalIfEqFrame.getVariables()).thenReturn(variables);
variables.set(9, new VariableContext(INT));
Instruction i = new LDC(ins, 0);
InstructionContext ctx = new InstructionContext(i, originalIfEqFrame);
// ifeq 0
IfEq ifeq = new IfEq(ins, InstructionType.IFEQ);
InstructionContext ifeqCtx = new InstructionContext(ifeq, originalIfEqFrame);
ifeqCtx.pop(new StackContext(ctx, INT, new Value(1)));
//
ins = mock(Instructions.class);
Frame originalIfIcmpNeFrame = mock(Frame.class);
stack = new Stack(42);
variables = new Variables(42);
when(originalIfIcmpNeFrame.getStack()).thenReturn(stack);
when(originalIfIcmpNeFrame.getVariables()).thenReturn(variables);
variables.set(5, new VariableContext(INT));
i = new LDC(ins, 1);
InstructionContext ctx1 = new InstructionContext(i, originalIfIcmpNeFrame);
i = new ILoad(ins, 5);
InstructionContext ctx2 = new InstructionContext(i, originalIfIcmpNeFrame);
// ificmpne 1
IfICmpNe ificmpne = new IfICmpNe(ins, InstructionType.IF_ICMPNE);
InstructionContext ificmpneCtx = new InstructionContext(ificmpne, originalIfIcmpNeFrame);
ificmpneCtx.pop(new StackContext(ctx1, INT, new Value(1)), new StackContext(ctx2, INT, Value.UNKNOWN));
assertEquals(ifeq.isSame(ifeqCtx, ificmpneCtx), ificmpne.isSame(ificmpneCtx, ifeqCtx));
// check that both frames jump the same direction
Frame ifeqBranchFrame = mock(Frame.class);
ifeqCtx.branch(ifeqBranchFrame);
Frame ificmpneBranchFrame = mock(Frame.class);
ificmpneCtx.branch(ificmpneBranchFrame);
// initially originalIfEqFrame.other == originalIfIcmpNeFrame.other
when(originalIfEqFrame.getOther()).thenReturn(originalIfIcmpNeFrame);
when(originalIfIcmpNeFrame.getOther()).thenReturn(originalIfEqFrame);
ParallelExecutorMapping mapping = mock(ParallelExecutorMapping.class);
ifeq.map(mapping, ifeqCtx, ificmpneCtx);
// verify that ifeqBranchFrame.other = ificmpneBranchFrame
ArgumentCaptor<Frame> frameCapture = ArgumentCaptor.forClass(Frame.class);
verify(ifeqBranchFrame).setOther(frameCapture.capture());
assertEquals(ificmpneBranchFrame, frameCapture.getValue());
}
use of net.runelite.asm.execution.Variables in project runelite by runelite.
the class LCmpTest method testIsSame.
@Test
public void testIsSame() {
LCmp cmp = new LCmp(mock(Instructions.class), InstructionType.LCMP);
LCmp cmp2 = new LCmp(mock(Instructions.class), InstructionType.LCMP);
Frame f1 = mock(Frame.class);
when(f1.getStack()).thenReturn(new Stack(42));
when(f1.getVariables()).thenReturn(new Variables(42));
Frame f2 = mock(Frame.class);
when(f2.getStack()).thenReturn(new Stack(42));
when(f2.getVariables()).thenReturn(new Variables(42));
InstructionContext ctx1 = new InstructionContext(cmp, f1);
InstructionContext ctx2 = new InstructionContext(cmp2, f2);
boolean result = cmp.isSame(ctx1, ctx2);
Assert.assertTrue(result);
}
use of net.runelite.asm.execution.Variables in project runelite by runelite.
the class ILoad method execute.
@Override
public InstructionContext execute(Frame frame) {
InstructionContext ins = new InstructionContext(this, frame);
Stack stack = frame.getStack();
Variables variables = frame.getVariables();
VariableContext vctx = variables.get(index);
assert vctx.getType().isStackInt();
ins.read(vctx);
StackContext ctx = new StackContext(ins, vctx);
stack.push(ctx);
ins.push(ctx);
return ins;
}
use of net.runelite.asm.execution.Variables in project runelite by runelite.
the class IStore method execute.
@Override
public InstructionContext execute(Frame frame) {
InstructionContext ins = new InstructionContext(this, frame);
Stack stack = frame.getStack();
Variables variables = frame.getVariables();
StackContext value = stack.pop();
assert value.getType().isStackInt();
ins.pop(value);
variables.set(index, new VariableContext(ins, value));
return ins;
}
use of net.runelite.asm.execution.Variables in project runelite by runelite.
the class FLoad method execute.
@Override
public InstructionContext execute(Frame frame) {
InstructionContext ins = new InstructionContext(this, frame);
Stack stack = frame.getStack();
Variables variables = frame.getVariables();
VariableContext vctx = variables.get(index);
assert vctx.getType().equals(Type.FLOAT);
ins.read(vctx);
StackContext ctx = new StackContext(ins, vctx);
stack.push(ctx);
ins.push(ctx);
return ins;
}
Aggregations