diff --git a/asm/src/main/java/dev/openrs2/asm/InsnListUtils.kt b/asm/src/main/java/dev/openrs2/asm/InsnListUtils.kt index 2de6592912..01044332f7 100644 --- a/asm/src/main/java/dev/openrs2/asm/InsnListUtils.kt +++ b/asm/src/main/java/dev/openrs2/asm/InsnListUtils.kt @@ -14,7 +14,7 @@ fun getExpression( var height = 0 var insn: AbstractInsnNode? = last do { - val (pops, pushes) = insn!!.stackMetadata() + val (pops, pushes) = insn!!.stackMetadata if (insn !== last) { expr.add(insn) height -= pushes diff --git a/asm/src/main/java/dev/openrs2/asm/StackMetadata.kt b/asm/src/main/java/dev/openrs2/asm/StackMetadata.kt index 932204582d..c3ef4e6be6 100644 --- a/asm/src/main/java/dev/openrs2/asm/StackMetadata.kt +++ b/asm/src/main/java/dev/openrs2/asm/StackMetadata.kt @@ -181,36 +181,37 @@ private val SIMPLE_OPCODES = mapOf( Opcodes.IFNONNULL to POP1 ) -fun AbstractInsnNode.stackMetadata(): StackMetadata = when (this) { - is LdcInsnNode -> if (cst is Double || cst is Long) { - PUSH2 - } else { - PUSH1 - } - is FieldInsnNode -> { - val fieldSize = Type.getType(desc).size - var pushes = 0 - var pops = 0 - if (opcode == Opcodes.GETFIELD || opcode == Opcodes.PUTFIELD) { - pops++ - } - if (opcode == Opcodes.PUTFIELD || opcode == Opcodes.PUTSTATIC) { - pops += fieldSize +val AbstractInsnNode.stackMetadata + get() = when (this) { + is LdcInsnNode -> if (cst is Double || cst is Long) { + PUSH2 } else { - pushes += fieldSize + PUSH1 } - StackMetadata(pops, pushes) - } - is MethodInsnNode -> { - val argumentsAndReturnSizes = Type.getArgumentsAndReturnSizes(desc) - val pushes = argumentsAndReturnSizes and 0x3 - var pops = argumentsAndReturnSizes shr 2 - if (opcode == Opcodes.INVOKESTATIC) { - pops-- + is FieldInsnNode -> { + val fieldSize = Type.getType(desc).size + var pushes = 0 + var pops = 0 + if (opcode == Opcodes.GETFIELD || opcode == Opcodes.PUTFIELD) { + pops++ + } + if (opcode == Opcodes.PUTFIELD || opcode == Opcodes.PUTSTATIC) { + pops += fieldSize + } else { + pushes += fieldSize + } + StackMetadata(pops, pushes) + } + is MethodInsnNode -> { + val argumentsAndReturnSizes = Type.getArgumentsAndReturnSizes(desc) + val pushes = argumentsAndReturnSizes and 0x3 + var pops = argumentsAndReturnSizes shr 2 + if (opcode == Opcodes.INVOKESTATIC) { + pops-- + } + StackMetadata(pops, pushes) } - StackMetadata(pops, pushes) + is InvokeDynamicInsnNode -> throw UnsupportedOperationException() + is MultiANewArrayInsnNode -> StackMetadata(dims, 1) + else -> SIMPLE_OPCODES[opcode] ?: throw IllegalArgumentException() } - is InvokeDynamicInsnNode -> throw UnsupportedOperationException() - is MultiANewArrayInsnNode -> StackMetadata(dims, 1) - else -> SIMPLE_OPCODES[opcode] ?: throw IllegalArgumentException() -} diff --git a/deob/src/main/java/dev/openrs2/deob/transform/ConstantArgTransformer.kt b/deob/src/main/java/dev/openrs2/deob/transform/ConstantArgTransformer.kt index 60f4d0612f..0f20e12c0e 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/ConstantArgTransformer.kt +++ b/deob/src/main/java/dev/openrs2/deob/transform/ConstantArgTransformer.kt @@ -262,7 +262,7 @@ class ConstantArgTransformer : Transformer() { } else if (!insn.pure) { // can't replace instructions with a side effect continue - } else if (insn.stackMetadata().pushes != 1) { + } else if (insn.stackMetadata.pushes != 1) { // can't replace instructions pushing more than one result continue }