From 05ba1c9d52c056e33b4121ea55812ae596016ea3 Mon Sep 17 00:00:00 2001 From: Kevin Laeufer Date: Wed, 8 Jul 2020 11:46:51 -0700 Subject: ir: add faster serializer (#1694) This Serializer which is implemented external to the IR node definition uses a StringBuilder to achieve about a 1.7x performance improvement when serializing. Eventually, all implementations of the `serialize` methd should be replaced with a call to `Serializer.serialize`. However, for this PR we keep the old code in place in order to allow for easy regression testing with the benchmark JAR like this: > java -cp utils/bin/firrtl-benchmark.jar \ firrtl.benchmark.hot.SerializationBenchmark \ ~/benchmarks/medium.pb 2 5 test Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>--- .../scala/firrtlTests/formal/VerificationSpec.scala | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/test') diff --git a/src/test/scala/firrtlTests/formal/VerificationSpec.scala b/src/test/scala/firrtlTests/formal/VerificationSpec.scala index 22dbc1f1..31c54e76 100644 --- a/src/test/scala/firrtlTests/formal/VerificationSpec.scala +++ b/src/test/scala/firrtlTests/formal/VerificationSpec.scala @@ -5,6 +5,7 @@ package firrtlTests.formal import firrtl.{SystemVerilogCompiler} import firrtl.testutils.FirrtlFlatSpec import logger.{LogLevel, Logger} +import firrtl.ir class VerificationSpec extends FirrtlFlatSpec { behavior of "Formal" @@ -57,4 +58,23 @@ class VerificationSpec extends FirrtlFlatSpec { |""".stripMargin.split("\n") map normalized executeTest(input, expected, compiler) } + + "VerificationStatement" should "serialize correctly" in { + val clk = ir.Reference("clk") + val en = ir.Reference("en") + val pred = ir.Reference("pred") + val a = ir.Verification(ir.Formal.Assert, ir.NoInfo, clk, pred, en, ir.StringLit("test")) + + assert(a.serialize == "assert(clk, pred, en, \"test\")") + assert(ir.Serializer.serialize(a) == "assert(clk, pred, en, \"test\")") + + val b = ir.Verification(ir.Formal.Assume, ir.NoInfo, clk, en, pred, ir.StringLit("test \n test")) + assert(b.serialize == "assume(clk, en, pred, \"test \\n test\")") + assert(ir.Serializer.serialize(b) == "assume(clk, en, pred, \"test \\n test\")") + + val c = ir.Verification(ir.Formal.Assume, ir.NoInfo, clk, pred, en, ir.StringLit("test \t test")) + assert(c.serialize == "assume(clk, pred, en, \"test \\t test\")") + assert(ir.Serializer.serialize(c) == "assume(clk, pred, en, \"test \\t test\")") + + } } -- cgit v1.2.3