From ba2be50f42c1ec760decc22cfda73fbd39113b53 Mon Sep 17 00:00:00 2001 From: Kevin Laeufer Date: Thu, 30 Jul 2020 16:56:54 -0700 Subject: ir: use Serializer.serialize where possible (#1809) * ir: use Serializer.serialize where possible * ir.Serializer: serialize MultiInfo correctly * ir.Serializer: empty body needs to result in a skip statement The firrtl grammar requires at least one statement. * ir.Serializer: correctly serialize fixed point types and literals * Serializer: change Seq -> Iterable in order to be Scala 2.13 compatible--- .../firrtlTests/fixed/FixedSerializationSpec.scala | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/test/scala/firrtlTests/fixed/FixedSerializationSpec.scala (limited to 'src/test') diff --git a/src/test/scala/firrtlTests/fixed/FixedSerializationSpec.scala b/src/test/scala/firrtlTests/fixed/FixedSerializationSpec.scala new file mode 100644 index 00000000..db107cb3 --- /dev/null +++ b/src/test/scala/firrtlTests/fixed/FixedSerializationSpec.scala @@ -0,0 +1,27 @@ +// See LICENSE for license details. + +package firrtlTests +package fixed + +import firrtl.ir +import org.scalatest.flatspec.AnyFlatSpec + +class FixedSerializationSpec extends AnyFlatSpec { + behavior of "FixedType" + + it should "serialize correctly" in { + assert(ir.FixedType(ir.IntWidth(3), ir.IntWidth(2)).serialize == "Fixed<3><<2>>") + assert(ir.FixedType(ir.IntWidth(10), ir.UnknownWidth).serialize == "Fixed<10>") + assert(ir.FixedType(ir.UnknownWidth, ir.IntWidth(-4)).serialize == "Fixed<<-4>>") + assert(ir.FixedType(ir.UnknownWidth, ir.UnknownWidth).serialize == "Fixed") + } + + behavior of "FixedLiteral" + + it should "serialize correctly" in { + assert(ir.FixedLiteral(1, ir.IntWidth(3), ir.IntWidth(2)).serialize == "Fixed<3><<2>>(\"h1\")") + assert(ir.FixedLiteral(1, ir.IntWidth(10), ir.UnknownWidth).serialize == "Fixed<10>(\"h1\")") + assert(ir.FixedLiteral(1, ir.UnknownWidth, ir.IntWidth(-4)).serialize == "Fixed<<-4>>(\"h1\")") + assert(ir.FixedLiteral(1, ir.UnknownWidth, ir.UnknownWidth).serialize == "Fixed(\"h1\")") + } +} -- cgit v1.2.3