diff options
| author | Chick Markley | 2019-02-26 16:07:33 -0800 |
|---|---|---|
| committer | mergify[bot] | 2019-02-27 00:07:33 +0000 |
| commit | aec54ed72d02932f8fdb3aa857e82a23507aecd2 (patch) | |
| tree | 82c3ed54187dda79aeecf7614d494295c67ca8eb /src/main/scala/firrtl/graph/DiGraph.scala | |
| parent | dbe404460fd3062d940f86a02df044b8cc4be0fd (diff) | |
Create a simple generic GraphViz renderer for DiGraph (#1034)
* Create a simple generic graphviz renderer for DiGraph
There are three basic kinds
- A simple default renderer
- A ranked renderer that places nodes in columns based on depth from sources
- A sub-graph render for graphs that contain a loop
- Renders just nodes that are part of first loop found
- Plus the neighbors of the loop
- Loop edges are shown in red.
* Create a simple generic graphviz renderer for DiGraph
- Moved the graph loop finder into DiGraph
- Fixed scala doc per Edward's comments
Diffstat (limited to 'src/main/scala/firrtl/graph/DiGraph.scala')
| -rw-r--r-- | src/main/scala/firrtl/graph/DiGraph.scala | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/graph/DiGraph.scala b/src/main/scala/firrtl/graph/DiGraph.scala index 9cfcad52..1cac34b5 100644 --- a/src/main/scala/firrtl/graph/DiGraph.scala +++ b/src/main/scala/firrtl/graph/DiGraph.scala @@ -109,6 +109,30 @@ class DiGraph[T] private[graph] (private[graph] val edges: LinkedHashMap[T, Link order.reverse.toSeq } + /** + * Finds a Seq of Nodes that form a loop + * @param node Node to start loop path search from. + * @return The found Seq, the Seq is empty if there is no loop + */ + def findLoopAtNode(node: T): Seq[T] = { + var foundPath = Seq.empty[T] + getEdges(node).exists { vertex => + try { + foundPath = path(vertex, node, blacklist = Set.empty) + true + } + catch { + case _: PathNotFoundException => + foundPath = Seq.empty[T] + false + case t: Throwable => + throw t + + } + } + foundPath + } + /** Performs breadth-first search on the directed graph * * @param root the start node |
