aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Laeufer2021-02-03 17:56:02 -0800
committerGitHub2021-02-03 17:56:02 -0800
commit9c59c3d94ae3f922ee538d593304cdf2976685aa (patch)
tree0c24f609a8301777ea9a572831ff6d984a019470
parent81ff0fe30f7dd63cffd0c4cd93b72ebee9c8bec9 (diff)
IR: turn some IR nodes into data classes (#2071)
* build: add data-class dependency * ir: turn Print, Stop and Verification nodes into data classes This is in preparation to add a name field to them. Co-authored-by: Jack Koenig <jack.koenig3@gmail.com>
-rw-r--r--build.sbt17
-rw-r--r--src/main/scala/firrtl/ir/IR.scala44
2 files changed, 57 insertions, 4 deletions
diff --git a/build.sbt b/build.sbt
index 76908bb7..374bc273 100644
--- a/build.sbt
+++ b/build.sbt
@@ -22,6 +22,11 @@ lazy val commonSettings = Seq(
crossScalaVersions := Seq("2.13.4", "2.12.13", "2.11.12")
)
+lazy val isAtLeastScala213 = Def.setting {
+ import Ordering.Implicits._
+ CrossVersion.partialVersion(scalaVersion.value).exists(_ >= (2, 13))
+}
+
lazy val firrtlSettings = Seq(
name := "firrtl",
version := "1.5-SNAPSHOT",
@@ -42,8 +47,18 @@ lazy val firrtlSettings = Seq(
"com.github.scopt" %% "scopt" % "3.7.1",
"net.jcazevedo" %% "moultingyaml" % "0.4.2",
"org.json4s" %% "json4s-native" % "3.6.9",
- "org.apache.commons" % "commons-text" % "1.8"
+ "org.apache.commons" % "commons-text" % "1.8",
+ "io.github.alexarchambault" %% "data-class" % "0.2.5",
),
+ // macros for the data-class library
+ libraryDependencies ++= {
+ if (isAtLeastScala213.value) Nil
+ else Seq(compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full))
+ },
+ scalacOptions ++= {
+ if (isAtLeastScala213.value) Seq("-Ymacro-annotations")
+ else Nil
+ },
// starting with scala 2.13 the parallel collections are separate from the standard library
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
diff --git a/src/main/scala/firrtl/ir/IR.scala b/src/main/scala/firrtl/ir/IR.scala
index 7d091176..1b564d42 100644
--- a/src/main/scala/firrtl/ir/IR.scala
+++ b/src/main/scala/firrtl/ir/IR.scala
@@ -4,6 +4,7 @@ package firrtl
package ir
import Utils.{dec2string, trim}
+import dataclass.data
import firrtl.constraint.{Constraint, IsKnown, IsVar}
import org.apache.commons.text.translate.{AggregateTranslator, JavaUnicodeEscaper, LookupTranslator}
@@ -593,7 +594,7 @@ case class Attach(info: Info, exprs: Seq[Expression]) extends Statement with Has
def foreachString(f: String => Unit): Unit = ()
def foreachInfo(f: Info => Unit): Unit = f(info)
}
-case class Stop(info: Info, ret: Int, clk: Expression, en: Expression)
+@data class Stop(info: Info, ret: Int, clk: Expression, en: Expression)
extends Statement
with HasInfo
with UseSerializer {
@@ -607,8 +608,16 @@ case class Stop(info: Info, ret: Int, clk: Expression, en: Expression)
def foreachType(f: Type => Unit): Unit = ()
def foreachString(f: String => Unit): Unit = ()
def foreachInfo(f: Info => Unit): Unit = f(info)
+ def copy(info: Info = info, ret: Int = ret, clk: Expression = clk, en: Expression = en): Stop = {
+ Stop(info, ret, clk, en)
+ }
+}
+object Stop {
+ def unapply(s: Stop): Some[(Info, Int, Expression, Expression)] = {
+ Some((s.info, s.ret, s.clk, s.en))
+ }
}
-case class Print(
+@data class Print(
info: Info,
string: StringLit,
args: Seq[Expression],
@@ -627,6 +636,20 @@ case class Print(
def foreachType(f: Type => Unit): Unit = ()
def foreachString(f: String => Unit): Unit = ()
def foreachInfo(f: Info => Unit): Unit = f(info)
+ def copy(
+ info: Info = info,
+ string: StringLit = string,
+ args: Seq[Expression] = args,
+ clk: Expression = clk,
+ en: Expression = en
+ ): Print = {
+ Print(info, string, args, clk, en)
+ }
+}
+object Print {
+ def unapply(s: Print): Some[(Info, StringLit, Seq[Expression], Expression, Expression)] = {
+ Some((s.info, s.string, s.args, s.clk, s.en))
+ }
}
// formal
@@ -636,7 +659,7 @@ object Formal extends Enumeration {
val Cover = Value("cover")
}
-case class Verification(
+@data class Verification(
op: Formal.Value,
info: Info,
clk: Expression,
@@ -657,6 +680,21 @@ case class Verification(
def foreachType(f: Type => Unit): Unit = ()
def foreachString(f: String => Unit): Unit = ()
def foreachInfo(f: Info => Unit): Unit = f(info)
+ def copy(
+ op: Formal.Value = op,
+ info: Info = info,
+ clk: Expression = clk,
+ pred: Expression = pred,
+ en: Expression = en,
+ msg: StringLit = msg
+ ): Verification = {
+ Verification(op, info, clk, pred, en, msg)
+ }
+}
+object Verification {
+ def unapply(s: Verification): Some[(Formal.Value, Info, Expression, Expression, Expression, StringLit)] = {
+ Some((s.op, s.info, s.clk, s.pred, s.en, s.msg))
+ }
}
// end formal