aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChick Markley2018-04-02 10:23:37 -0700
committerGitHub2018-04-02 10:23:37 -0700
commit6ec5df16a38a7b53494ed3f52da039b8fa62175e (patch)
tree47b81990e151b13a5435c7ee5bc713a58a2e9553 /src
parent396ee7ca63eb8a9e201dcdea965cbfc3e9d36783 (diff)
CyclicException identifies a problem node. (#778)
Needed for special handling in Treadle. Small refactor that allows users of DiGraph#linearize to return the first node found in a cycle. Fixed RemoveWiresTransfrom to handle this. Added test to show usage of this feature.
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/firrtl/graph/DiGraph.scala4
-rw-r--r--src/main/scala/firrtl/transforms/RemoveWires.scala5
-rw-r--r--src/test/scala/firrtlTests/graph/DiGraphTests.scala12
3 files changed, 17 insertions, 4 deletions
diff --git a/src/main/scala/firrtl/graph/DiGraph.scala b/src/main/scala/firrtl/graph/DiGraph.scala
index 450ec4ff..135603ff 100644
--- a/src/main/scala/firrtl/graph/DiGraph.scala
+++ b/src/main/scala/firrtl/graph/DiGraph.scala
@@ -7,7 +7,7 @@ import scala.collection.mutable
import scala.collection.mutable.{LinkedHashSet, LinkedHashMap}
/** An exception that is raised when an assumed DAG has a cycle */
-class CyclicException extends Exception("No valid linearization for cyclic graph")
+class CyclicException(val node: Any) extends Exception(s"No valid linearization for cyclic graph, found at $node")
/** An exception that is raised when attempting to find an unreachable node */
class PathNotFoundException extends Exception("Unreachable node")
@@ -79,7 +79,7 @@ class DiGraph[T] private[graph] (private[graph] val edges: LinkedHashMap[T, Link
def visit(n: T): Unit = {
if (tempMarked.contains(n)) {
- throw new CyclicException
+ throw new CyclicException(n)
}
if (unmarked.contains(n)) {
tempMarked += n
diff --git a/src/main/scala/firrtl/transforms/RemoveWires.scala b/src/main/scala/firrtl/transforms/RemoveWires.scala
index 931288d9..5ba953cd 100644
--- a/src/main/scala/firrtl/transforms/RemoveWires.scala
+++ b/src/main/scala/firrtl/transforms/RemoveWires.scala
@@ -111,9 +111,10 @@ class RemoveWires extends Transform {
case Success(logic) =>
Module(info, name, ports, Block(decls ++ logic ++ otherStmts))
// If we hit a CyclicException, just abort removing wires
- case Failure(_: CyclicException) =>
+ case Failure(c: CyclicException) =>
+ val problematicNode = c.node
logger.warn(s"Cycle found in module $name, " +
- "wires will not be removed which can prevent optimizations!")
+ s"wires will not be removed which can prevent optimizations! Problem node: $problematicNode")
mod
case Failure(other) => throw other
}
diff --git a/src/test/scala/firrtlTests/graph/DiGraphTests.scala b/src/test/scala/firrtlTests/graph/DiGraphTests.scala
index 147b22d7..a0f45c80 100644
--- a/src/test/scala/firrtlTests/graph/DiGraphTests.scala
+++ b/src/test/scala/firrtlTests/graph/DiGraphTests.scala
@@ -1,3 +1,5 @@
+// See LICENSE for license details.
+
package firrtlTests.graph
import java.io._
@@ -50,6 +52,16 @@ class DiGraphTests extends FirrtlFlatSpec {
a [CyclicException] should be thrownBy cyclicGraph.linearize
+ try {
+ cyclicGraph.linearize
+ }
+ catch {
+ case c: CyclicException =>
+ c.getMessage.contains("found at a") should be (true)
+ c.node.asInstanceOf[String] should be ("a")
+ case _: Throwable =>
+ }
+
acyclicGraph.reverse.getEdgeMap should equal (reversedAcyclicGraph.getEdgeMap)
degenerateGraph.getEdgeMap should equal (degenerateGraph.reverse.getEdgeMap)