From 19fe90bb0fd37457c47f3873392db5cbb9b87d38 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Fri, 26 Aug 2022 07:52:04 -0700 Subject: 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--- src/main/scala/firrtl/parser/Listener.scala | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/main/scala/firrtl/parser') diff --git a/src/main/scala/firrtl/parser/Listener.scala b/src/main/scala/firrtl/parser/Listener.scala index ffaa22b2..1f6692ca 100644 --- a/src/main/scala/firrtl/parser/Listener.scala +++ b/src/main/scala/firrtl/parser/Listener.scala @@ -6,6 +6,7 @@ import firrtl.antlr.{FIRRTLParser, _} import firrtl.Visitor import firrtl.Parser.InfoMode import firrtl.ir._ +import firrtl.UnsupportedVersionException import scala.collection.mutable import scala.concurrent.{Await, Future} @@ -25,6 +26,16 @@ private[firrtl] class Listener(infoMode: InfoMode) extends FIRRTLBaseListener { } override def exitCircuit(ctx: FIRRTLParser.CircuitContext): Unit = { + if (ctx.version != null) { + val version = ctx.version.semver.getText + val parts = version.split("\\.") + val (major, minor, patch) = (parts(0).toInt, parts(1).toInt, parts(2).toInt) + if (Version(major, minor, patch).incompatible(Serializer.version)) { + throw new UnsupportedVersionException( + s"FIRRTL version ${version} is not supported (greater than ${Serializer.version.serialize})" + ) + } + } info = Some(visitor.visitInfo(Option(ctx.info), ctx)) main = Some(ctx.id.getText) ctx.children = null // Null out to save memory -- cgit v1.2.3