Skip to content

Commit

Permalink
Fix panda application graph building
Browse files Browse the repository at this point in the history
  • Loading branch information
zishkaz committed Jun 4, 2024
1 parent ab7d189 commit c7f9d87
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,25 @@ interface PandaBytecodeGraph<out Statement> : BytecodeGraph<Statement>

class PandaGraph(
override val instructions: List<PandaInst>,
val basicBlocks: List<PandaBasicBlock>
) : PandaBytecodeGraph<PandaInst> {

private val predecessorMap: MutableMap<PandaInst, MutableSet<PandaInst>> = hashMapOf()
private val successorMap: MutableMap<PandaInst, Set<PandaInst>> = 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))
}
Expand Down Expand Up @@ -112,7 +122,7 @@ class PandaBlockGraph(
instList: List<PandaInst>,
) : PandaBytecodeGraph<PandaBasicBlock> {

val graph: PandaGraph = PandaGraph(instList)
val graph: PandaGraph = PandaGraph(instList, instructions)

override val entries: List<PandaBasicBlock>
get() = instructions.take(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ data class PandaNopInst(
class PandaEmptyBBPlaceholderInst(
override val location: PandaInstLocation,
private val bbId: Int,
) : PandaTerminatingInst() {
) : PandaInst() {

override val operands: List<PandaExpr>
get() = emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c7f9d87

Please sign in to comment.