aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/firrtlTests/transforms/RemoveResetSpec.scala
diff options
context:
space:
mode:
authorJack Koenig2022-04-21 20:20:47 -0700
committerGitHub2022-04-21 20:20:47 -0700
commit5093da03083a37a0a7bdaf44f9867d7f7a0a5980 (patch)
tree25e3d723a95cac8a6cb109e14a28e3df039d467e /src/test/scala/firrtlTests/transforms/RemoveResetSpec.scala
parent410f030dc98177ffe54632c1e25fca873b7b1faf (diff)
Fix optimization of register with reset but invalid connection (#2520)
Fixes #2516 Previously, reg r : UInt<8>, clock with : reset => (p, UInt<8>(3)) r is invalid would compile to: reg r : UInt<8>, clock r <= UInt<8>(0) now it compiles to: reg r : UInt<8>, clock wire r_1 : UInt<8> r_1 is invalid r <= mux(reset, UInt<8>(3), r_1) This is consistent with the behavior for a reset with an asynchronous reset.
Diffstat (limited to 'src/test/scala/firrtlTests/transforms/RemoveResetSpec.scala')
-rw-r--r--src/test/scala/firrtlTests/transforms/RemoveResetSpec.scala28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/test/scala/firrtlTests/transforms/RemoveResetSpec.scala b/src/test/scala/firrtlTests/transforms/RemoveResetSpec.scala
index 1adeeed8..666320b7 100644
--- a/src/test/scala/firrtlTests/transforms/RemoveResetSpec.scala
+++ b/src/test/scala/firrtlTests/transforms/RemoveResetSpec.scala
@@ -8,7 +8,7 @@ import firrtl.testutils.FirrtlFlatSpec
import firrtl.testutils.FirrtlCheckers._
import firrtl.{CircuitState, WRef}
-import firrtl.ir.{Connect, DefRegister, Mux}
+import firrtl.ir.{Connect, DefRegister, IsInvalid, Mux, UIntLiteral}
import firrtl.stage.{FirrtlCircuitAnnotation, FirrtlSourceAnnotation, FirrtlStage}
class RemoveResetSpec extends FirrtlFlatSpec with GivenWhenThen {
@@ -47,6 +47,32 @@ class RemoveResetSpec extends FirrtlFlatSpec with GivenWhenThen {
outputState shouldNot containTree { case Connect(_, WRef("foo", _, _, _), Mux(_, _, _, _)) => true }
}
+ it should "generate a reset mux for a sync reset register with an invalid connection" in {
+ Given("an 8-bit register 'foo' initialized to UInt(3) with an invalid connection")
+ val input =
+ """|circuit Example :
+ | module Example :
+ | input clock : Clock
+ | input rst : UInt<1>
+ | input in : UInt<8>
+ | output out : UInt<8>
+ |
+ | reg foo : UInt<8>, clock with : (reset => (rst, UInt(3)))
+ | foo is invalid
+ | out <= foo""".stripMargin
+
+ val outputState = toLowFirrtl(input)
+
+ Then("'foo' should not have a reset")
+ outputState should containTree {
+ case DefRegister(_, "foo", _, _, UIntLiteral(value, _), WRef("foo", _, _, _)) if value == 0 => true
+ }
+ And("'foo' is connected to a mux with its old reset value")
+ outputState should containTree {
+ case Connect(_, WRef("foo", _, _, _), Mux(_, UIntLiteral(value, _), _, _)) if value == 3 => true
+ }
+ }
+
it should "generate a reset mux for only the portion of an invalid aggregate that is reset" in {
Given("aggregate register 'foo' with 2-bit field 'a' and 1-bit field 'b'")
And("aggregate, invalid wire 'bar' with the same fields")