diff options
| author | Zachary Yedidia | 2022-08-26 07:52:04 -0700 |
|---|---|---|
| committer | GitHub | 2022-08-26 14:52:04 +0000 |
| commit | 19fe90bb0fd37457c47f3873392db5cbb9b87d38 (patch) | |
| tree | 8d81c6b3d0ddf3b050a021300033d40f377acab7 /src/main/scala/firrtl/parser | |
| parent | a6851b8ec4044eef4af759a21887fdae6226e1cd (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/main/scala/firrtl/parser')
| -rw-r--r-- | src/main/scala/firrtl/parser/Listener.scala | 11 |
1 files changed, 11 insertions, 0 deletions
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 |
