Search in sources :

Example 1 with Instruction

use of net.runelite.cache.script.Instruction in project runelite by runelite.

the class ScriptWriter method enterName_string.

@Override
public void enterName_string(rs2asmParser.Name_stringContext ctx) {
    String text = ctx.getText();
    Instruction i = instructions.find(text);
    if (i == null) {
        logger.warn("Unknown instruction {}", text);
        throw new RuntimeException("Unknown instruction " + text);
    }
    int opcode = i.getOpcode();
    addOpcode(opcode);
}
Also used : Instruction(net.runelite.cache.script.Instruction)

Example 2 with Instruction

use of net.runelite.cache.script.Instruction in project runelite by runelite.

the class Disassembler method disassemble.

public String disassemble(ScriptDefinition script) throws IOException {
    int[] instructions = script.getInstructions();
    int[] iops = script.getIntOperands();
    String[] sops = script.getStringOperands();
    Map<Integer, Integer>[] switches = script.getSwitches();
    assert iops.length == instructions.length;
    assert sops.length == instructions.length;
    boolean[] jumps = needLabel(script);
    StringBuilder writer = new StringBuilder();
    writerHeader(writer, script);
    for (int i = 0; i < instructions.length; ++i) {
        int opcode = instructions[i];
        int iop = iops[i];
        String sop = sops[i];
        Instruction ins = this.instructions.find(opcode);
        if (ins == null) {
            logger.warn("Unknown instruction {} in script {}", opcode, script.getId());
        }
        if (jumps[i]) {
            // something jumps here
            writer.append("LABEL").append(i).append(":\n");
        }
        String name;
        if (ins != null && ins.getName() != null) {
            name = ins.getName();
        } else {
            name = String.format("%03d", opcode);
        }
        writer.append(String.format("   %-22s", name));
        if (shouldWriteIntOperand(opcode, iop)) {
            if (isJump(opcode)) {
                writer.append(" LABEL").append(i + iop + 1);
            } else {
                writer.append(" ").append(iop);
            }
        }
        if (sop != null) {
            writer.append(" \"").append(sop).append("\"");
        }
        if (opcode == Opcodes.SWITCH) {
            Map<Integer, Integer> switchMap = switches[iop];
            for (Entry<Integer, Integer> entry : switchMap.entrySet()) {
                int value = entry.getKey();
                int jump = entry.getValue();
                writer.append("\n");
                writer.append("      ").append(value).append(": LABEL").append(i + jump + 1);
            }
        }
        writer.append("\n");
    }
    return writer.toString();
}
Also used : Instruction(net.runelite.cache.script.Instruction) Map(java.util.Map)

Aggregations

Instruction (net.runelite.cache.script.Instruction)2 Map (java.util.Map)1