aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/ir
diff options
context:
space:
mode:
authorZachary Yedidia2022-08-26 07:52:04 -0700
committerGitHub2022-08-26 14:52:04 +0000
commit19fe90bb0fd37457c47f3873392db5cbb9b87d38 (patch)
tree8d81c6b3d0ddf3b050a021300033d40f377acab7 /src/main/scala/firrtl/ir
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/main/scala/firrtl/ir')
-rw-r--r--src/main/scala/firrtl/ir/Serializer.scala10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/ir/Serializer.scala b/src/main/scala/firrtl/ir/Serializer.scala
index f5457dea..0666a4b1 100644
--- a/src/main/scala/firrtl/ir/Serializer.scala
+++ b/src/main/scala/firrtl/ir/Serializer.scala
@@ -6,10 +6,19 @@ import firrtl.Utils
import firrtl.backends.experimental.smt.random.DefRandom
import firrtl.constraint.Constraint
+case class Version(major: Int, minor: Int, patch: Int) {
+ def serialize: String = s"$major.$minor.$patch"
+ def incompatible(that: Version): Boolean =
+ this.major > that.major || (this.major == that.major && this.minor > that.minor)
+}
+
object Serializer {
val NewLine = '\n'
val Indent = " "
+ // The version supported by the serializer.
+ val version = Version(1, 1, 0)
+
/** Converts a `FirrtlNode` into its string representation with
* default indentation.
*/
@@ -254,6 +263,7 @@ object Serializer {
private def s(node: Circuit)(implicit b: StringBuilder, indent: Int): Unit = node match {
case Circuit(info, modules, main) =>
+ b ++= s"FIRRTL version ${version.serialize}\n"
b ++= "circuit "; b ++= main; b ++= " :"; s(info)
if (modules.nonEmpty) {
newLineNoIndent(); s(modules.head)(b, indent + 1)