Skip to content

Commit

Permalink
Fix raw inst equality (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saloed authored Nov 12, 2024
1 parent 2fcc42b commit 9733174
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
24 changes: 12 additions & 12 deletions jacodb-api-jvm/src/main/kotlin/org/jacodb/api/jvm/cfg/JcRawInst.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sealed interface JcRawInst {
fun <T> accept(visitor: JcRawInstVisitor<T>): T
}

data class JcRawAssignInst(
class JcRawAssignInst(
override val owner: JcMethod,
val lhv: JcRawValue,
val rhv: JcRawExpr
Expand All @@ -43,7 +43,7 @@ data class JcRawAssignInst(
}
}

data class JcRawEnterMonitorInst(
class JcRawEnterMonitorInst(
override val owner: JcMethod,
val monitor: JcRawSimpleValue
) : JcRawInst {
Expand All @@ -57,7 +57,7 @@ data class JcRawEnterMonitorInst(
}
}

data class JcRawExitMonitorInst(
class JcRawExitMonitorInst(
override val owner: JcMethod,
val monitor: JcRawSimpleValue
) : JcRawInst {
Expand All @@ -71,7 +71,7 @@ data class JcRawExitMonitorInst(
}
}

data class JcRawCallInst(
class JcRawCallInst(
override val owner: JcMethod,
val callExpr: JcRawCallExpr
) : JcRawInst {
Expand All @@ -89,7 +89,7 @@ data class JcRawLabelRef(val name: String) {
override fun toString() = name
}

data class JcRawLineNumberInst(override val owner: JcMethod, val lineNumber: Int, val start: JcRawLabelRef) : JcRawInst {
class JcRawLineNumberInst(override val owner: JcMethod, val lineNumber: Int, val start: JcRawLabelRef) : JcRawInst {

override val operands: List<JcRawExpr>
get() = emptyList()
Expand All @@ -102,7 +102,7 @@ data class JcRawLineNumberInst(override val owner: JcMethod, val lineNumber: Int
}


data class JcRawLabelInst(
class JcRawLabelInst(
override val owner: JcMethod,
val name: String
) : JcRawInst {
Expand All @@ -118,7 +118,7 @@ data class JcRawLabelInst(
}
}

data class JcRawReturnInst(
class JcRawReturnInst(
override val owner: JcMethod,
val returnValue: JcRawValue?
) : JcRawInst {
Expand All @@ -132,7 +132,7 @@ data class JcRawReturnInst(
}
}

data class JcRawThrowInst(
class JcRawThrowInst(
override val owner: JcMethod,
val throwable: JcRawValue
) : JcRawInst {
Expand All @@ -152,7 +152,7 @@ data class JcRawCatchEntry(
val endExclusive: JcRawLabelRef
)

data class JcRawCatchInst(
class JcRawCatchInst(
override val owner: JcMethod,
val throwable: JcRawValue,
val handler: JcRawLabelRef,
Expand All @@ -172,7 +172,7 @@ sealed interface JcRawBranchingInst : JcRawInst {
val successors: List<JcRawLabelRef>
}

data class JcRawGotoInst(
class JcRawGotoInst(
override val owner: JcMethod,
val target: JcRawLabelRef
) : JcRawBranchingInst {
Expand All @@ -189,7 +189,7 @@ data class JcRawGotoInst(
}
}

data class JcRawIfInst(
class JcRawIfInst(
override val owner: JcMethod,
val condition: JcRawConditionExpr,
val trueBranch: JcRawLabelRef,
Expand All @@ -208,7 +208,7 @@ data class JcRawIfInst(
}
}

data class JcRawSwitchInst(
class JcRawSwitchInst(
override val owner: JcMethod,
val key: JcRawValue,
val branches: Map<JcRawValue, JcRawLabelRef>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,12 @@ class RawInstListBuilder(
if (branchInst.key.dependsOn(value)) {
val freshVar = generateFreshLocalVar(branchInst.key.typeName)
insnList.addInst(JcRawAssignInst(method, freshVar, branchInst.key), index = 0)
insnList[branchInstIdx + 2] = branchInst.copy(key = freshVar)
insnList[branchInstIdx + 2] = JcRawSwitchInst(
owner = branchInst.owner,
key = freshVar,
branches = branchInst.branches,
default = branchInst.default
)
}
}

Expand All @@ -555,7 +560,12 @@ class RawInstListBuilder(
insnList.addInst(JcRawAssignInst(method, freshVar, value), index = 0)

val updatedCondition = branchInst.condition.replace(fromValue = value, toValue = freshVar)
insnList[branchInstIdx + 2] = branchInst.copy(condition = updatedCondition)
insnList[branchInstIdx + 2] = JcRawIfInst(
owner = branchInst.owner,
condition = updatedCondition,
trueBranch = branchInst.trueBranch,
falseBranch = branchInst.falseBranch
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ internal class Simplifier {
val reservedValues = hashSetOf<JcRawValue>()
val replacedInsts = hashSetOf<JcRawInst>()

val instructionIndex = hashMapOf<JcRawInst, Int>()
val instructionIndex = identityMap<JcRawInst, Int>()
val assignInstructions = mutableListOf<JcRawAssignInst>()
val firstValueAssignment = hashMapOf<JcRawValue, JcRawAssignInst>()

Expand Down

0 comments on commit 9733174

Please sign in to comment.