aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/firrtl
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/scala/firrtl')
-rw-r--r--src/test/scala/firrtl/testutils/FirrtlSpec.scala11
-rw-r--r--src/test/scala/firrtl/transforms/EnsureNamedStatementsSpec.scala39
2 files changed, 44 insertions, 6 deletions
diff --git a/src/test/scala/firrtl/testutils/FirrtlSpec.scala b/src/test/scala/firrtl/testutils/FirrtlSpec.scala
index 6de2af1e..24793437 100644
--- a/src/test/scala/firrtl/testutils/FirrtlSpec.scala
+++ b/src/test/scala/firrtl/testutils/FirrtlSpec.scala
@@ -123,21 +123,21 @@ trait FirrtlRunners extends BackendCompilationUtilities {
}
/** Check equivalence of Firrtl with reference Verilog
- *
+ *
* @note the name of the reference Verilog module is grabbed via regex
* @param inputFirrtl string containing Firrtl source
* @param referenceVerilog Verilog that will be used as reference for LEC
* @param timesteps the maximum number of timesteps to consider
*/
def firrtlEquivalenceWithVerilog(
- inputFirrtl: String,
- referenceVerilog: String,
- timesteps: Int = 1
+ inputFirrtl: String,
+ referenceVerilog: String,
+ timesteps: Int = 1
): Unit = {
val VerilogModule = """(?s).*module\s(\w+).*""".r
val refName = referenceVerilog match {
case VerilogModule(name) => name
- case _ => throw new Exception(s"Reference Verilog must match simple regex! $VerilogModule")
+ case _ => throw new Exception(s"Reference Verilog must match simple regex! $VerilogModule")
}
val circuit = Parser.parse(inputFirrtl.split("\n").toIterator)
val inputName = circuit.main
@@ -163,7 +163,6 @@ trait FirrtlRunners extends BackendCompilationUtilities {
assert(BackendCompilationUtilities.yosysExpectSuccess(inputName, refName, testDir, timesteps))
}
-
/** Compiles input Firrtl to Verilog */
def compileToVerilog(input: String, annotations: AnnotationSeq = Seq.empty): String = {
val circuit = Parser.parse(input.split("\n").toIterator)
diff --git a/src/test/scala/firrtl/transforms/EnsureNamedStatementsSpec.scala b/src/test/scala/firrtl/transforms/EnsureNamedStatementsSpec.scala
new file mode 100644
index 00000000..4c993994
--- /dev/null
+++ b/src/test/scala/firrtl/transforms/EnsureNamedStatementsSpec.scala
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package firrtl.transforms
+
+import firrtl.options.Dependency
+import firrtl.testutils.LeanTransformSpec
+
+class EnsureNamedStatementsSpec extends LeanTransformSpec(Seq(Dependency(EnsureNamedStatements))) {
+ behavior.of("EnsureNamedStatements")
+
+ it should "automatically name statements that do not have a name yet" in {
+ val src = """circuit test :
+ | module test :
+ | input clock : Clock
+ | input stop_ : UInt<1>
+ | assert(clock, UInt(1), not(UInt(0)), "")
+ | stop(clock, UInt(1), 1) : stop_123
+ | stop(clock, UInt(1), 1)
+ | assert(clock, UInt(0), UInt(0), "")
+ | assume(clock, UInt(0), UInt(0), "")
+ | cover(clock, UInt(0), UInt(0), "")
+ | cover(clock, UInt(0), UInt(0), "")
+ |
+ |""".stripMargin
+
+ val result = compile(src, List()).circuit.serialize.split('\n').map(_.trim)
+
+ val expected = List(
+ """assert(clock, UInt<1>("h1"), not(UInt<1>("h0")), "") : assert_0""",
+ """stop(clock, UInt<1>("h1"), 1) : stop_123""",
+ """stop(clock, UInt<1>("h1"), 1) : stop_0""",
+ """assert(clock, UInt<1>("h0"), UInt<1>("h0"), "") : assert_1""",
+ """assume(clock, UInt<1>("h0"), UInt<1>("h0"), "") : assume_0""",
+ """cover(clock, UInt<1>("h0"), UInt<1>("h0"), "") : cover_0""",
+ """cover(clock, UInt<1>("h0"), UInt<1>("h0"), "") : cover_1"""
+ )
+ expected.foreach(e => assert(result.contains(e)))
+ }
+}