-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --debug=call-graph option for displaying custom dependency graph
- Loading branch information
Showing
4 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
core/src/main/scala/stainless/frontend/CallGraphPrinter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* Copyright 2009-2021 EPFL, Lausanne */ | ||
|
||
package stainless | ||
package frontend | ||
|
||
import stainless.extraction.xlang.{trees => xt} | ||
|
||
import inox.utils.Graphs._ | ||
import inox.utils.GraphPrinters.DotPrinter | ||
|
||
object CallGraphPrinter { | ||
|
||
import xt._ | ||
|
||
def apply(symbols: Symbols): Unit = { | ||
val displayedFds = symbols.functions.values.filter { fd => | ||
!fd.flags.exists(_.name.contains("inline")) && | ||
!fd.flags.contains(Ghost) && | ||
!fd.isAccessor && | ||
!fd.isInvariant && | ||
!fd.isSynthetic && | ||
!fd.getPos.file.toString.contains("stainless_") | ||
}.toSet | ||
val map = displayedFds.groupBy(fd => fd.getPos.file) | ||
|
||
val fw = new java.io.FileWriter("CallGraph.dot") | ||
|
||
fw.write("digraph G {\n") | ||
|
||
val nodes = scala.collection.mutable.Set[String]() | ||
var edges = scala.collection.mutable.Set[(String, String)]() | ||
|
||
// print dependencies within each file | ||
for ((fullName, fds) <- map) { | ||
val fdSet = fds.map(_.id).toSet | ||
val name0 = fullName.getName.takeWhile(c => c != '.') | ||
val name = if (name0.isEmpty) "Unknown" else name0 | ||
|
||
fw.write(s" subgraph cluster_$name {\n") | ||
fw.write(s" label = $name;\n") | ||
for (fd1 <- fds) { | ||
val c = if (fd1.flags.contains(DropVCs)) "crimson" | ||
else if (fd1.flags.exists(_.name == "cCode.export")) "cornflowerblue" | ||
else if (fd1.flags.exists(_.name == "cCode.drop")) "gray" | ||
else if (fd1.flags.exists(_.name == "cCode.function")) "gray" | ||
else if (fd1.flags.exists(_.name == "extern")) "gray" | ||
else "darkolivegreen2" | ||
|
||
val name1 = fd1.id.toString | ||
if (!nodes.contains(name1)) { | ||
nodes += name1 | ||
fw.write(s" $name1 [style=filled,color=$c];\n") | ||
} | ||
} | ||
|
||
for (fd1 <- fds) | ||
for (id2 <- symbols.dependencies(fd1.id) & fdSet) { | ||
val name1 = fd1.id.toString | ||
val name2 = id2.toString | ||
if (!edges.contains((name1, name2))) { | ||
edges += ((name1, name2)) | ||
fw.write(s" $name1 -> $name2;\n") | ||
} | ||
} | ||
|
||
fw.write(" }\n") | ||
} | ||
|
||
fw.write("\n\n") | ||
// print dependencies across files | ||
for ((fullName, fds) <- map) { | ||
val fdSet = fds.map(_.id).toSet | ||
for (fd1 <- fds) | ||
for (id2 <- (symbols.dependencies(fd1.id) & displayedFds.map(_.id)) -- fdSet) { | ||
val name1 = fd1.id.toString | ||
val name2 = id2.toString | ||
if (!edges.contains((name1, name2))) { | ||
edges += ((name1, name2)) | ||
fw.write(s" $name1 -> $name2;\n") | ||
} | ||
} | ||
} | ||
|
||
fw.write("}\n") | ||
fw.close() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters