From 0f13cace653fa45e907f59a060b6acd93c7bce2a Mon Sep 17 00:00:00 2001 From: Jim Lawson Date: Wed, 14 Dec 2016 16:53:52 -0800 Subject: Add support for top-level use of MiddleFirrtlCompiler. --- src/test/scala/firrtlTests/CompilerTests.scala | 39 ++++++++++++++++++++++ src/test/scala/firrtlTests/DriverSpec.scala | 1 + .../scala/firrtlTests/MultiThreadingSpec.scala | 1 + 3 files changed, 41 insertions(+) (limited to 'src/test') diff --git a/src/test/scala/firrtlTests/CompilerTests.scala b/src/test/scala/firrtlTests/CompilerTests.scala index 2a5311f8..8ec7665c 100644 --- a/src/test/scala/firrtlTests/CompilerTests.scala +++ b/src/test/scala/firrtlTests/CompilerTests.scala @@ -14,6 +14,7 @@ import firrtl.{ CircuitState, Compiler, HighFirrtlCompiler, + MiddleFirrtlCompiler, LowFirrtlCompiler, Parser, VerilogCompiler @@ -60,6 +61,44 @@ class HighFirrtlCompilerSpec extends CompilerSpec with Matchers { } } +/** + * An example test for testing the MiddleFirrtlCompiler. + * + * Given an input Firrtl circuit (expressed as a string), + * the compiler is executed. The output of the compiler is + * a lowered (to MidForm) version of the input circuit. The output is + * string compared to the correct lowered circuit. + */ +class MiddleFirrtlCompilerSpec extends CompilerSpec with Matchers { + val compiler = new MiddleFirrtlCompiler() + val input = + """ +circuit Top : + module Top : + input reset : UInt<1> + input a : UInt<1>[2] + wire b : UInt + b <= a[0] + when reset : + b <= UInt(0) +""" + // Verify that Vecs are retained, but widths are inferred and whens are expanded. + val check = Seq( + "circuit Top :", + " module Top :", + " input reset : UInt<1>", + " input a : UInt<1>[2]", + " wire b : UInt<1>", + " node _GEN_0 = mux(reset, UInt<1>(\"h0\"), a[0])", + " b <= _GEN_0\n\n" + ).reduce(_ + "\n" + _) + "A circuit" should "match exactly to its MidForm state" in { + val parsedOutput = parse(getOutput) + val checkedOutput = parse(check) + (parse(getOutput)) should be (parse(check)) + } +} + /** * An example test for testing the LoweringCompiler. * diff --git a/src/test/scala/firrtlTests/DriverSpec.scala b/src/test/scala/firrtlTests/DriverSpec.scala index cdabc28c..3b0dee0a 100644 --- a/src/test/scala/firrtlTests/DriverSpec.scala +++ b/src/test/scala/firrtlTests/DriverSpec.scala @@ -155,6 +155,7 @@ class DriverSpec extends FreeSpec with Matchers with BackendCompilationUtilities Seq( "low" -> "./Dummy.lo.fir", "high" -> "./Dummy.hi.fir", + "middle" -> "./Dummy.mid.fir", "verilog" -> "./Dummy.v" ).foreach { case (compilerName, expectedOutputFileName) => val manager = new ExecutionOptionsManager("test") with HasFirrtlOptions { diff --git a/src/test/scala/firrtlTests/MultiThreadingSpec.scala b/src/test/scala/firrtlTests/MultiThreadingSpec.scala index 169aa6b2..1698c462 100644 --- a/src/test/scala/firrtlTests/MultiThreadingSpec.scala +++ b/src/test/scala/firrtlTests/MultiThreadingSpec.scala @@ -21,6 +21,7 @@ class MultiThreadingSpec extends FirrtlPropSpec { // The parameters we're testing with val compilers = Seq( new firrtl.HighFirrtlCompiler, + new firrtl.MiddleFirrtlCompiler, new firrtl.LowFirrtlCompiler, new firrtl.VerilogCompiler) val inputFilePath = s"/integration/GCDTester.fir" // arbitrary -- cgit v1.2.3