Rename ArgRef to ArgPartition

The next commit will introduce an ArgRef class which uses a MemberRef
directly, rather than a MemberRef partition.

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 4 years ago
parent f4d8b29747
commit 33955a57ad
  1. 2
      deob/src/main/java/dev/openrs2/deob/ArgPartition.kt
  2. 14
      deob/src/main/java/dev/openrs2/deob/transform/ConstantArgTransformer.kt
  3. 12
      deob/src/main/java/dev/openrs2/deob/transform/UnusedArgTransformer.kt

@ -3,4 +3,4 @@ package dev.openrs2.deob
import dev.openrs2.asm.MemberRef
import dev.openrs2.util.collect.DisjointSet
data class ArgRef(val method: DisjointSet.Partition<MemberRef>, val index: Int)
data class ArgPartition(val method: DisjointSet.Partition<MemberRef>, val index: Int)

@ -16,7 +16,7 @@ import dev.openrs2.asm.replaceExpression
import dev.openrs2.asm.stackMetadata
import dev.openrs2.asm.toAbstractInsnNode
import dev.openrs2.asm.transform.Transformer
import dev.openrs2.deob.ArgRef
import dev.openrs2.deob.ArgPartition
import dev.openrs2.deob.Profile
import dev.openrs2.deob.analysis.IntBranch
import dev.openrs2.deob.analysis.IntBranchResult.ALWAYS_TAKEN
@ -54,7 +54,7 @@ import javax.inject.Singleton
class ConstantArgTransformer @Inject constructor(private val profile: Profile) : Transformer() {
private val pendingMethods = LinkedHashSet<MemberRef>()
private val arglessMethods = mutableSetOf<DisjointSet.Partition<MemberRef>>()
private val argValues = mutableMapOf<ArgRef, IntValueSet>()
private val argValues = mutableMapOf<ArgPartition, IntValueSet>()
private lateinit var inheritedMethodSets: DisjointSet<MemberRef>
private lateinit var entryPoints: MemberFilter
private var branchesSimplified = 0
@ -131,7 +131,7 @@ class ConstantArgTransformer @Inject constructor(private val profile: Profile) :
private fun getArgs(ref: MemberRef): Array<IntValueSet> {
val partition = inheritedMethodSets[ref]!!
val size = Type.getArgumentTypes(ref.desc).sumBy { it.size }
return Array(size) { i -> argValues[ArgRef(partition, i)] ?: IntValueSet.Unknown }
return Array(size) { i -> argValues[ArgPartition(partition, i)] ?: IntValueSet.Unknown }
}
private fun addArgValues(owner: ClassNode, method: MethodNode, args: Array<IntValueSet>) {
@ -153,7 +153,7 @@ class ConstantArgTransformer @Inject constructor(private val profile: Profile) :
var index = 0
for (j in 0 until size) {
val value = frame.getStack(frame.stackSize - size + j)
if (addArgValues(ArgRef(invokedMethod, index), value.set)) {
if (addArgValues(ArgPartition(invokedMethod, index), value.set)) {
pendingMethods.addAll(invokedMethod)
}
index += value.size
@ -165,8 +165,8 @@ class ConstantArgTransformer @Inject constructor(private val profile: Profile) :
}
}
private fun addArgValues(ref: ArgRef, value: IntValueSet): Boolean {
val old = argValues[ref]
private fun addArgValues(partition: ArgPartition, value: IntValueSet): Boolean {
val old = argValues[partition]
val new = if (value.singleton != null) {
if (old != null) {
@ -177,7 +177,7 @@ class ConstantArgTransformer @Inject constructor(private val profile: Profile) :
} else {
IntValueSet.Unknown
}
argValues[ref] = new
argValues[partition] = new
return old != new
}

@ -7,7 +7,7 @@ import dev.openrs2.asm.classpath.Library
import dev.openrs2.asm.hasCode
import dev.openrs2.asm.removeArgument
import dev.openrs2.asm.transform.Transformer
import dev.openrs2.deob.ArgRef
import dev.openrs2.deob.ArgPartition
import dev.openrs2.deob.Profile
import dev.openrs2.deob.analysis.ConstSourceInterpreter
import dev.openrs2.deob.analysis.ConstSourceValue
@ -26,7 +26,7 @@ import javax.inject.Singleton
@Singleton
class UnusedArgTransformer @Inject constructor(private val profile: Profile) : Transformer() {
private val retainedArgs = mutableSetOf<ArgRef>()
private val retainedArgs = mutableSetOf<ArgPartition>()
private lateinit var inheritedMethodSets: DisjointSet<MemberRef>
private var deletedArgs = 0
@ -68,7 +68,7 @@ class UnusedArgTransformer @Inject constructor(private val profile: Profile) : T
val arg = localToArgMap[insn.`var`]
if (arg != null) {
retainedArgs.add(ArgRef(partition, arg))
retainedArgs.add(ArgPartition(partition, arg))
}
}
is MethodInsnNode -> {
@ -85,7 +85,7 @@ class UnusedArgTransformer @Inject constructor(private val profile: Profile) : T
for (j in 0 until args) {
val source = frame.getStack(stackSize - args + j)
if (source !is ConstSourceValue.Single) {
retainedArgs.add(ArgRef(invokePartition, j))
retainedArgs.add(ArgPartition(invokePartition, j))
}
}
}
@ -132,7 +132,7 @@ class UnusedArgTransformer @Inject constructor(private val profile: Profile) : T
val newArgTypes = mutableListOf<Type>()
for ((j, argType) in argTypes.withIndex()) {
if (argType.sort in INT_SORTS && ArgRef(partition, j) !in retainedArgs) {
if (argType.sort in INT_SORTS && ArgPartition(partition, j) !in retainedArgs) {
val value = frame.getStack(stackSize - argTypes.size + j) as ConstSourceValue.Single
deadInsns.add(value.source)
} else {
@ -162,7 +162,7 @@ class UnusedArgTransformer @Inject constructor(private val profile: Profile) : T
val argTypes = Type.getType(method.desc).argumentTypes
for ((i, argType) in argTypes.withIndex().reversed()) {
if (argType.sort in INT_SORTS && ArgRef(partition, i) !in retainedArgs) {
if (argType.sort in INT_SORTS && ArgPartition(partition, i) !in retainedArgs) {
method.removeArgument(i)
deletedArgs++
}

Loading…
Cancel
Save