Search in sources :

Example 1 with LDC

use of net.runelite.asm.attributes.code.InstructionType.LDC in project runelite by runelite.

the class ExprArgOrderTest method test2.

@Test
public void test2() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(2);
    // vars[0] = 3
    Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    Instruction[] body = { // 2
    new ILoad(ins, 0), new LDC(ins, 3), new IAdd(ins), new Pop(ins), // 6
    new LDC(ins, 3), new ILoad(ins, 0), new IAdd(ins), new SiPush(ins, (short) 512), new IAdd(ins), new Pop(ins), new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    ExprArgOrder exprArgOrder = new ExprArgOrder();
    exprArgOrder.run(group);
    List<Instruction> instructions = ins.getInstructions();
    // ensure this stays the same
    assertEquals(ILOAD, instructions.get(2).getType());
    assertEquals(LDC, instructions.get(3).getType());
    assertEquals(IADD, instructions.get(4).getType());
    // 
    assertEquals(ILOAD, instructions.get(6).getType());
    assertEquals(SIPUSH, instructions.get(7).getType());
    assertEquals(IADD, instructions.get(8).getType());
    assertEquals(LDC, instructions.get(9).getType());
    assertEquals(IADD, instructions.get(10).getType());
}
Also used : SiPush(net.runelite.asm.attributes.code.instructions.SiPush) IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.InstructionType.LDC) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Pop(net.runelite.asm.attributes.code.instructions.Pop) ClassGroup(net.runelite.asm.ClassGroup) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Example 2 with LDC

use of net.runelite.asm.attributes.code.InstructionType.LDC in project runelite by runelite.

the class ExprArgOrderTest method test4.

@Test
public void test4() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(2);
    // vars[0] = 3
    Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    Instruction[] body = { new SiPush(ins, (short) 600), new ILoad(ins, 0), new LDC(ins, 3), new IMul(ins), new IAdd(ins), new Pop(ins), new ILoad(ins, 0), new LDC(ins, 3), new IMul(ins), new SiPush(ins, (short) 600), new IAdd(ins), new Pop(ins), new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    ExprArgOrder exprArgOrder = new ExprArgOrder();
    exprArgOrder.run(group);
    List<Instruction> instructions = ins.getInstructions();
    for (int i = 2; i <= 7; ++i) {
        assertEquals(instructions.get(i).getType(), instructions.get(i + 6).getType());
    }
}
Also used : SiPush(net.runelite.asm.attributes.code.instructions.SiPush) IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.InstructionType.LDC) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Pop(net.runelite.asm.attributes.code.instructions.Pop) ClassGroup(net.runelite.asm.ClassGroup) IMul(net.runelite.asm.attributes.code.instructions.IMul) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Example 3 with LDC

use of net.runelite.asm.attributes.code.InstructionType.LDC in project runelite by runelite.

the class ExprArgOrderTest method test3.

@Test
public void test3() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(2);
    // vars[0] = 3
    Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    Instruction[] body = { // 512 + (3 + var1) -> var1 + 3 + 512
    new LDC(ins, 512), new LDC(ins, 3), new ILoad(ins, 0), new IAdd(ins), new IAdd(ins), new Pop(ins), new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    ExprArgOrder exprArgOrder = new ExprArgOrder();
    exprArgOrder.run(group);
    List<Instruction> instructions = ins.getInstructions();
    // 2: iload
    // 3: iconst 3
    // 4: iadd
    // 5: ldc
    // 6: add
    assertEquals(IADD, instructions.get(4).getType());
    assertEquals(IADD, instructions.get(6).getType());
}
Also used : IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.InstructionType.LDC) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Pop(net.runelite.asm.attributes.code.instructions.Pop) ClassGroup(net.runelite.asm.ClassGroup) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Example 4 with LDC

use of net.runelite.asm.attributes.code.InstructionType.LDC in project runelite by runelite.

the class ExprArgOrderTest method test5.

@Test
public void test5() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(2);
    // vars[0] = 3
    Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    Label label = new Label(ins);
    Instruction[] body = { // if (0 == 3 + var0) -> if (var0 + 3 == 0)
    new LDC(ins, 0), new LDC(ins, 3), new ILoad(ins, 0), new IAdd(ins), new IfICmpEq(ins, label), label, new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    ExprArgOrder exprArgOrder = new ExprArgOrder();
    exprArgOrder.run(group);
    List<Instruction> instructions = ins.getInstructions();
    // ldc iload add -> iload ldc iadd
    assertEquals(ILOAD, instructions.get(2).getType());
    assertEquals(LDC, instructions.get(3).getType());
    assertEquals(IADD, instructions.get(4).getType());
    // idc moves from 2 to 5
    assertEquals(LDC, instructions.get(5).getType());
    assertEquals(IF_ICMPEQ, instructions.get(6).getType());
}
Also used : IfICmpEq(net.runelite.asm.attributes.code.instructions.IfICmpEq) IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.InstructionType.LDC) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) ClassGroup(net.runelite.asm.ClassGroup) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Example 5 with LDC

use of net.runelite.asm.attributes.code.InstructionType.LDC in project runelite by runelite.

the class ExprArgOrderTest method test6.

@Test
public void test6() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(2);
    // vars[0] = 3
    Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    Label label = new Label(ins);
    /*
		iconst_0
		ldc                   8388608
		iload_3
		iadd
		ldc                   -16777216
		iand
		if_icmpeq             LABEL0x49
		 */
    Instruction[] body = { new LDC(ins, 0), new LDC(ins, 8388608), new ILoad(ins, 0), new IAdd(ins), new LDC(ins, -16777216), new IAnd(ins), // 8
    new IfICmpEq(ins, label), label, new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    ExprArgOrder exprArgOrder = new ExprArgOrder();
    exprArgOrder.run(group);
    List<Instruction> instructions = ins.getInstructions();
    assertEquals(ILOAD, instructions.get(2).getType());
    assertEquals(LDC, instructions.get(3).getType());
    assertEquals(IADD, instructions.get(4).getType());
    assertEquals(LDC, instructions.get(5).getType());
    assertEquals(IAND, instructions.get(6).getType());
    assertEquals(LDC, instructions.get(7).getType());
    assertEquals(IF_ICMPEQ, instructions.get(8).getType());
}
Also used : IfICmpEq(net.runelite.asm.attributes.code.instructions.IfICmpEq) IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.InstructionType.LDC) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instruction(net.runelite.asm.attributes.code.Instruction) IAnd(net.runelite.asm.attributes.code.instructions.IAnd) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) ClassGroup(net.runelite.asm.ClassGroup) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Aggregations

ClassGroup (net.runelite.asm.ClassGroup)6 Code (net.runelite.asm.attributes.Code)6 Instruction (net.runelite.asm.attributes.code.Instruction)6 LDC (net.runelite.asm.attributes.code.InstructionType.LDC)6 Instructions (net.runelite.asm.attributes.code.Instructions)6 IAdd (net.runelite.asm.attributes.code.instructions.IAdd)6 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)6 IStore (net.runelite.asm.attributes.code.instructions.IStore)6 LDC (net.runelite.asm.attributes.code.instructions.LDC)6 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)6 Test (org.junit.Test)6 Pop (net.runelite.asm.attributes.code.instructions.Pop)4 Label (net.runelite.asm.attributes.code.Label)2 IfICmpEq (net.runelite.asm.attributes.code.instructions.IfICmpEq)2 SiPush (net.runelite.asm.attributes.code.instructions.SiPush)2 IAnd (net.runelite.asm.attributes.code.instructions.IAnd)1 IMul (net.runelite.asm.attributes.code.instructions.IMul)1