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

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

Loading…
Cancel
Save