Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

IR: turn some IR nodes into data classes #2071

Merged
merged 4 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 {
Expand Down
44 changes: 41 additions & 3 deletions src/main/scala/firrtl/ir/IR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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 {
Expand All @@ -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],
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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

Expand Down