diff --git a/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/api/PandaGraph.kt b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/api/PandaGraph.kt index 904ee75c5..8b60d86df 100644 --- a/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/api/PandaGraph.kt +++ b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/api/PandaGraph.kt @@ -34,15 +34,25 @@ interface PandaBytecodeGraph : BytecodeGraph class PandaGraph( override val instructions: List, + val basicBlocks: List ) : PandaBytecodeGraph { private val predecessorMap: MutableMap> = hashMapOf() private val successorMap: MutableMap> = hashMapOf() + private fun bbFromInst(inst: PandaInst): PandaBasicBlock { + return basicBlocks.find { it.contains(inst) }!! + } + + private fun bbFromId(id: Int): PandaBasicBlock { + return basicBlocks.find { it.id == id }!! + } + init { for (inst in instructions) { val successors = when (inst) { is PandaTerminatingInst -> emptySet() + is PandaEmptyBBPlaceholderInst -> bbFromInst(inst).successors.map { inst(bbFromId(it).start) }.toSet() is PandaBranchingInst -> inst.successors.map { instructions[it.index] }.toSet() else -> setOfNotNull(next(inst)) } @@ -112,7 +122,7 @@ class PandaBlockGraph( instList: List, ) : PandaBytecodeGraph { - val graph: PandaGraph = PandaGraph(instList) + val graph: PandaGraph = PandaGraph(instList, instructions) override val entries: List get() = instructions.take(1) diff --git a/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/api/PandaInst.kt b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/api/PandaInst.kt index 0aac9a78e..5454b6ed5 100644 --- a/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/api/PandaInst.kt +++ b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/api/PandaInst.kt @@ -105,7 +105,7 @@ data class PandaNopInst( class PandaEmptyBBPlaceholderInst( override val location: PandaInstLocation, private val bbId: Int, -) : PandaTerminatingInst() { +) : PandaInst() { override val operands: List get() = emptyList() diff --git a/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/parser/IRTraversalManager.kt b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/parser/IRTraversalManager.kt index 3bc5a705a..c387869e3 100644 --- a/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/parser/IRTraversalManager.kt +++ b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/parser/IRTraversalManager.kt @@ -162,7 +162,7 @@ class IRTraversalManager( if (startId > endId || endId == -1) { currentBB.start = if (startId == -1) 0 else startId - addEmptyBlockPlaceholder(programMethod, currentBB.id) + if (currentBB.successors.isNotEmpty()) addEmptyBlockPlaceholder(programMethod, currentBB.id) addEmptyJump(programMethod) currentBB.end = programMethod.currentId } else if (endId >= 0) {