aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/firrtl/ir/IR.scala25
-rw-r--r--src/test/scala/firrtlTests/annotationTests/EliminateTargetPathsSpec.scala4
-rw-r--r--src/test/scala/firrtlTests/annotationTests/MorphismSpec.scala16
-rw-r--r--src/test/scala/firrtlTests/transforms/TopWiringTest.scala3
4 files changed, 25 insertions, 23 deletions
diff --git a/src/main/scala/firrtl/ir/IR.scala b/src/main/scala/firrtl/ir/IR.scala
index af3709cd..a47a4cea 100644
--- a/src/main/scala/firrtl/ir/IR.scala
+++ b/src/main/scala/firrtl/ir/IR.scala
@@ -421,8 +421,29 @@ object Block {
}
case class Block(stmts: Seq[Statement]) extends Statement {
- def serialize: String = stmts map (_.serialize) mkString "\n"
- def mapStmt(f: Statement => Statement): Statement = Block(stmts map f)
+ def serialize: String = {
+ val res = stmts.view.map(_.serialize).mkString("\n")
+ if (res.nonEmpty) res else EmptyStmt.serialize
+ }
+ def mapStmt(f: Statement => Statement): Statement = {
+ val res = new scala.collection.mutable.ArrayBuffer[Statement]()
+ var its = stmts.iterator :: Nil
+ while (its.nonEmpty) {
+ val it = its.head
+ if (it.hasNext) {
+ it.next() match {
+ case EmptyStmt => // flatten out
+ case b: Block =>
+ its = b.stmts.iterator :: its
+ case other =>
+ res.append(f(other))
+ }
+ } else {
+ its = its.tail
+ }
+ }
+ Block(res)
+ }
def mapExpr(f: Expression => Expression): Statement = this
def mapType(f: Type => Type): Statement = this
def mapString(f: String => String): Statement = this
diff --git a/src/test/scala/firrtlTests/annotationTests/EliminateTargetPathsSpec.scala b/src/test/scala/firrtlTests/annotationTests/EliminateTargetPathsSpec.scala
index e1cadf32..73f36cf0 100644
--- a/src/test/scala/firrtlTests/annotationTests/EliminateTargetPathsSpec.scala
+++ b/src/test/scala/firrtlTests/annotationTests/EliminateTargetPathsSpec.scala
@@ -386,7 +386,6 @@ class EliminateTargetPathsSpec extends FirrtlPropSpec with FirrtlMatchers {
"""|circuit Foo:
| module Bar:
| node x = UInt<1>(0)
- | skip
| module Foo:
| inst bar of Bar
| inst baz of Bar""".stripMargin
@@ -394,10 +393,8 @@ class EliminateTargetPathsSpec extends FirrtlPropSpec with FirrtlMatchers {
"""|circuit Foo:
| module Bar___Foo_bar:
| node x = UInt<1>(0)
- | skip
| module Bar:
| node x = UInt<1>(0)
- | skip
| module Foo:
| inst bar of Bar___Foo_bar
| inst baz of Bar""".stripMargin
@@ -427,7 +424,6 @@ class EliminateTargetPathsSpec extends FirrtlPropSpec with FirrtlMatchers {
| module Bar:
| node foo = UInt<1>(0)
| inst baz of Baz
- | skip
| module Foo:
| node foo = UInt<1>(0)
| inst bar of Bar
diff --git a/src/test/scala/firrtlTests/annotationTests/MorphismSpec.scala b/src/test/scala/firrtlTests/annotationTests/MorphismSpec.scala
index 985779ab..cc486c99 100644
--- a/src/test/scala/firrtlTests/annotationTests/MorphismSpec.scala
+++ b/src/test/scala/firrtlTests/annotationTests/MorphismSpec.scala
@@ -220,16 +220,12 @@ class MorphismSpec extends FlatSpec with Matchers {
"""|circuit Top:
| module Foo:
| node a = UInt<1>(0)
- | skip
| module Bop:
| node a = UInt<1>(0)
- | skip
| module Fub:
| node a = UInt<1>(0)
- | skip
| module Bar:
| node a = UInt<1>(0)
- | skip
| module Baz:
| input x: UInt<1>
| inst foo of Foo
@@ -246,7 +242,6 @@ class MorphismSpec extends FlatSpec with Matchers {
"""|circuit Top:
| module Foo:
| node a = UInt<1>(0)
- | skip
| module Baz:
| input x: UInt<1>
| inst foo of Foo
@@ -358,10 +353,8 @@ class MorphismSpec extends FlatSpec with Matchers {
"""|circuit Top:
| module Foo:
| node a = UInt<1>(0)
- | skip
| module Bar:
| node a = UInt<1>(0)
- | skip
| module Baz:
| input x: UInt<1>
| inst foo of Foo
@@ -374,22 +367,16 @@ class MorphismSpec extends FlatSpec with Matchers {
"""|circuit Top :
| module Foo___Top_baz_bar :
| node a = UInt<1>("h0")
- | skip
| module Foo___Top_qux_foox :
| node a = UInt<1>("h0")
- | skip
| module Foo___Top_qux_bar :
| node a = UInt<1>("h0")
- | skip
| module Foo___Top_baz_foox :
| node a = UInt<1>("h0")
- | skip
| module Foo___Top_baz_foo :
| node a = UInt<1>("h0")
- | skip
| module Foo___Top_qux_foo :
| node a = UInt<1>("h0")
- | skip
| module Baz___Top_baz :
| input x : UInt<1>
| inst foo of Foo___Top_baz_foo
@@ -486,10 +473,8 @@ class MorphismSpec extends FlatSpec with Matchers {
"""|circuit Top:
| module Foo:
| node a = UInt<1>(0)
- | skip
| module Bar:
| node a = UInt<1>(0)
- | skip
| module Baz:
| input x: UInt<1>
| inst foo of Foo
@@ -502,7 +487,6 @@ class MorphismSpec extends FlatSpec with Matchers {
"""|circuit Top :
| module Foo :
| node a = UInt<1>("h0")
- | skip
| module Baz :
| input x : UInt<1>
| inst foo of Foo
diff --git a/src/test/scala/firrtlTests/transforms/TopWiringTest.scala b/src/test/scala/firrtlTests/transforms/TopWiringTest.scala
index e26b0445..0ac12ef8 100644
--- a/src/test/scala/firrtlTests/transforms/TopWiringTest.scala
+++ b/src/test/scala/firrtlTests/transforms/TopWiringTest.scala
@@ -618,7 +618,8 @@ class TopWiringTests extends MiddleTransformSpec with TopWiringTestsCommon {
"--info-mode", "ignore"
)
firrtl.Driver.execute(args) match {
- case FirrtlExecutionSuccess(_, emitted) => parse(emitted) should be (parse(input))
+ case FirrtlExecutionSuccess(_, emitted) =>
+ parse(emitted).serialize should be (parse(input).serialize)
case _ => fail
}
}