aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSchuyler Eldridge2020-02-12 15:28:50 -0500
committerSchuyler Eldridge2020-02-13 09:15:51 -0500
commite74529d2d13d2c361b028c2f0abb289566b25428 (patch)
tree034aed455f7995f5cf8028fb6714aa162ce9523c /src
parentdd6bbd4f6b21025913005658c562d2ad530aa3b1 (diff)
Add InstanceGraph helpers: reachable/unreachable
Adds new APIs for querying sets of modules in an InstanceGraph: - modules: the set of all modules - reachableModules: set of modules reachable from the main/top - unreachableModules: set of modules not reachable from the main/top Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/firrtl/analyses/InstanceGraph.scala10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/analyses/InstanceGraph.scala b/src/main/scala/firrtl/analyses/InstanceGraph.scala
index b8b40065..7b60b110 100644
--- a/src/main/scala/firrtl/analyses/InstanceGraph.scala
+++ b/src/main/scala/firrtl/analyses/InstanceGraph.scala
@@ -140,6 +140,16 @@ class InstanceGraph(c: Circuit) {
def getChildrenInstanceMap: collection.Map[OfModule, collection.Map[Instance, OfModule]] =
childInstances.map(kv => kv._1.OfModule -> asOrderedMap(kv._2, (i: WDefInstance) => i.toTokens))
+ /** The set of all modules in the circuit */
+ lazy val modules: collection.Set[OfModule] = graph.getVertices.map(_.OfModule)
+
+ /** The set of all modules in the circuit reachable from the top module */
+ lazy val reachableModules: collection.Set[OfModule] =
+ mutable.LinkedHashSet(trueTopInstance.OfModule) ++ graph.reachableFrom(trueTopInstance).map(_.OfModule)
+
+ /** The set of all modules *not* reachable in the circuit */
+ lazy val unreachableModules: collection.Set[OfModule] = modules diff reachableModules
+
}
object InstanceGraph {