Cleanup code in PseudocodeTraverser
This commit is contained in:
@@ -49,10 +49,8 @@ fun <D> Pseudocode.traverse(
|
|||||||
if (instruction is LocalFunctionDeclarationInstruction) {
|
if (instruction is LocalFunctionDeclarationInstruction) {
|
||||||
instruction.body.traverse(traversalOrder, edgesMap, analyzeInstruction)
|
instruction.body.traverse(traversalOrder, edgesMap, analyzeInstruction)
|
||||||
}
|
}
|
||||||
val edges = edgesMap[instruction]
|
val edges = edgesMap[instruction] ?: continue
|
||||||
if (edges != null) {
|
analyzeInstruction(instruction, edges.incoming, edges.outgoing)
|
||||||
analyzeInstruction(instruction, edges.incoming, edges.outgoing)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +61,8 @@ fun <I : ControlFlowInfo<*, *, *>> Pseudocode.collectData(
|
|||||||
initialInfo: I
|
initialInfo: I
|
||||||
): Map<Instruction, Edges<I>> {
|
): Map<Instruction, Edges<I>> {
|
||||||
val edgesMap = LinkedHashMap<Instruction, Edges<I>>()
|
val edgesMap = LinkedHashMap<Instruction, Edges<I>>()
|
||||||
edgesMap.put(getStartInstruction(traversalOrder), Edges(initialInfo, initialInfo))
|
val startInstruction = getStartInstruction(traversalOrder)
|
||||||
|
edgesMap[startInstruction] = Edges(initialInfo, initialInfo)
|
||||||
|
|
||||||
val changed = mutableMapOf<Instruction, Boolean>()
|
val changed = mutableMapOf<Instruction, Boolean>()
|
||||||
do {
|
do {
|
||||||
@@ -125,15 +124,10 @@ private fun <I : ControlFlowInfo<*, *, *>> Pseudocode.collectDataFromSubgraph(
|
|||||||
val incomingEdgesData = HashSet<I>()
|
val incomingEdgesData = HashSet<I>()
|
||||||
|
|
||||||
for (previousInstruction in previousInstructions) {
|
for (previousInstruction in previousInstructions) {
|
||||||
val previousData = edgesMap[previousInstruction]
|
val previousData = edgesMap[previousInstruction] ?: continue
|
||||||
if (previousData != null) {
|
incomingEdgesData.add(updateEdge(previousInstruction, instruction, previousData.outgoing))
|
||||||
incomingEdgesData.add(
|
|
||||||
updateEdge(
|
|
||||||
previousInstruction, instruction, previousData.outgoing
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val mergedData = mergeEdges(instruction, incomingEdgesData)
|
val mergedData = mergeEdges(instruction, incomingEdgesData)
|
||||||
updateEdgeDataForInstruction(instruction, previousDataValue, mergedData, edgesMap, changed)
|
updateEdgeDataForInstruction(instruction, previousDataValue, mergedData, edgesMap, changed)
|
||||||
}
|
}
|
||||||
@@ -163,7 +157,7 @@ private fun <I : ControlFlowInfo<*, *, *>> updateEdgeDataForInstruction(
|
|||||||
) {
|
) {
|
||||||
if (previousValue != newValue && newValue != null) {
|
if (previousValue != newValue && newValue != null) {
|
||||||
changed[instruction] = true
|
changed[instruction] = true
|
||||||
edgesMap.put(instruction, newValue)
|
edgesMap[instruction] = newValue
|
||||||
} else {
|
} else {
|
||||||
changed[instruction] = false
|
changed[instruction] = false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user