aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/firrtl/testutils
diff options
context:
space:
mode:
authorJack Koenig2021-01-28 18:39:57 -0800
committerGitHub2021-01-28 18:39:57 -0800
commit651fbe9339aca5fcb562715d00b1f87cf66296ee (patch)
treefc9289f3dc223db85d3fe2d67c593e87b97e19d0 /src/test/scala/firrtl/testutils
parentaec9e9e61f9b6775bf313601ec5a44a34f608609 (diff)
Stop padding multiply and divide ops (#2058)
Fixes bug with mul or div followed by cat. Also fixes some Verilog lint issues.
Diffstat (limited to 'src/test/scala/firrtl/testutils')
-rw-r--r--src/test/scala/firrtl/testutils/FirrtlSpec.scala42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/test/scala/firrtl/testutils/FirrtlSpec.scala b/src/test/scala/firrtl/testutils/FirrtlSpec.scala
index 3a6f9372..6de2af1e 100644
--- a/src/test/scala/firrtl/testutils/FirrtlSpec.scala
+++ b/src/test/scala/firrtl/testutils/FirrtlSpec.scala
@@ -122,6 +122,48 @@ trait FirrtlRunners extends BackendCompilationUtilities {
assert(BackendCompilationUtilities.yosysExpectSuccess(customName, refName, testDir, timesteps))
}
+ /** 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
+ ): 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")
+ }
+ val circuit = Parser.parse(inputFirrtl.split("\n").toIterator)
+ val inputName = circuit.main
+ require(refName != inputName, s"Name of reference Verilog must not match name of input FIRRTL: $refName")
+
+ val testDir = createTestDirectory(inputName + "_equivalence_test")
+
+ val annos = List(
+ TargetDirAnnotation(testDir.toString),
+ InfoModeAnnotation("ignore"),
+ stage.FirrtlCircuitAnnotation(circuit),
+ stage.RunFirrtlTransformAnnotation.stringToEmitter("verilog"),
+ stage.OutputFileAnnotation(inputName)
+ )
+
+ (new firrtl.stage.FirrtlStage).execute(Array(), annos)
+
+ // Write reference
+ val w = new FileWriter(new File(testDir, s"$refName.v"))
+ w.write(referenceVerilog)
+ w.close()
+
+ 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)