aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorZachary Yedidia2022-08-26 07:52:04 -0700
committerGitHub2022-08-26 14:52:04 +0000
commit19fe90bb0fd37457c47f3873392db5cbb9b87d38 (patch)
tree8d81c6b3d0ddf3b050a021300033d40f377acab7 /src/test
parenta6851b8ec4044eef4af759a21887fdae6226e1cd (diff)
FIRRTL version support (#2543)
* Parse version and hardcode emitted version * Throw error if version is too high * Parse version even if rest is invalid * Change pattern match to if statement * Improve version grammar * Update tests * Remove outdated comment * Simplify grammar and use version class * Simplify and add no version test * Fix for conflicting lexer rule
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/firrtlTests/ParserSpec.scala61
-rw-r--r--src/test/scala/firrtlTests/SerializerSpec.scala2
2 files changed, 62 insertions, 1 deletions
diff --git a/src/test/scala/firrtlTests/ParserSpec.scala b/src/test/scala/firrtlTests/ParserSpec.scala
index 89e73cb7..610025ea 100644
--- a/src/test/scala/firrtlTests/ParserSpec.scala
+++ b/src/test/scala/firrtlTests/ParserSpec.scala
@@ -92,6 +92,67 @@ class ParserSpec extends FirrtlFlatSpec {
) ++ PrimOps.listing
}
+ // ********** FIRRTL version number **********
+ "Version 1.1.0" should "be accepted" in {
+ val input = """
+ |FIRRTL version 1.1.0
+ |circuit Test :
+ | module Test :
+ | input in : UInt<1>
+ | in <= UInt(0)
+ """.stripMargin
+ val c = firrtl.Parser.parse(input)
+ firrtl.Parser.parse(c.serialize)
+ }
+
+ "Version 1.1.1" should "be accepted" in {
+ val input = """
+ |FIRRTL version 1.1.1
+ |circuit Test :
+ | module Test :
+ | input in : UInt<1>
+ | in <= UInt(0)
+ """.stripMargin
+ val c = firrtl.Parser.parse(input)
+ firrtl.Parser.parse(c.serialize)
+ }
+
+ "No version" should "be accepted" in {
+ val input = """
+ |circuit Test :
+ | module Test :
+ | input in : { 0 : { 0 : { 0 : UInt<32>, flip 1 : UInt<32> } } }
+ | in.0.0.1 <= in.0.0.0
+ """.stripMargin
+ val c = firrtl.Parser.parse(input)
+ firrtl.Parser.parse(c.serialize)
+ }
+
+ an[UnsupportedVersionException] should be thrownBy {
+ val input = """
+ |FIRRTL version 1.2.0
+ |circuit Test :
+ | module Test :
+ | input in : UInt<1>
+ | in <= UInt(0)
+ """.stripMargin
+ firrtl.Parser.parse(input)
+ }
+
+ an[UnsupportedVersionException] should be thrownBy {
+ val input = """
+ |FIRRTL version 2.0.0
+ |crcuit Test :
+ | module Test @@#!# :
+ | input in1 : UInt<2>
+ | input in2 : UInt<3>
+ | output out : UInt<4>
+ | out[1:0] <= in1
+ | out[3:2] <= in2[1:0]
+ """.stripMargin
+ firrtl.Parser.parse(input)
+ }
+
// ********** Memories **********
"Memories" should "allow arbitrary ordering of fields" in {
val fields = MemTests.fieldsToSeq(MemTests.fields)
diff --git a/src/test/scala/firrtlTests/SerializerSpec.scala b/src/test/scala/firrtlTests/SerializerSpec.scala
index aae0ff1f..797a6045 100644
--- a/src/test/scala/firrtlTests/SerializerSpec.scala
+++ b/src/test/scala/firrtlTests/SerializerSpec.scala
@@ -63,7 +63,7 @@ object SerializerSpec {
val childModuleTabbed: String = tab(childModule)
val simpleCircuit: String =
- "circuit test :\n" + childModuleTabbed + "\n\n" + testModuleTabbed + "\n"
+ s"FIRRTL version ${Serializer.version.serialize}\ncircuit test :\n" + childModuleTabbed + "\n\n" + testModuleTabbed + "\n"
}
class SerializerSpec extends AnyFlatSpec with Matchers {