diff options
| author | Albert Magyar | 2020-01-31 19:51:43 -0800 |
|---|---|---|
| committer | Albert Magyar | 2020-05-26 09:57:56 -0700 |
| commit | dddb53fa575e62aac04d737c398c5bdd65e918f7 (patch) | |
| tree | 7a06f938c02164c38c4b03bb28280d3bc8f42002 /src | |
| parent | 46f98931874c19432810dfe55afb89afc4e14c81 (diff) | |
[API change] Absorb repetitive WIR nodes into IR
* Absorb WRef into Reference
* Absorb WSubField into SubField
* Absorb WSubIndex into SubIndex
* Absorb WSubAccess into SubAccess
* Absorb WDefInstance into DefInstance
------------------------- API CHANGE SEVERITY --------------------------
This is projected to not break source-level compatibility with any known
user code. However, it will break *binary* compatibility with all
existing user FIRRTL passes, as is generally allowed with major
releases of FIRRTL.
--------------------------- DESCRIPTION --------------------------------
Previously, there were several nodes in WIR.scala that had a one-to-one
correspondance with existing nodes in the standard firrtl.ir hierarchy.
These nodes would have a case class resembling the corresponding
standard IR node, but with the addition of one or more "analysis"
fields.
Since these fields (such as kind) represent helpful info that can be
invalidated or set to Unknown (e.g. UnknownKind for Kind), it does not
cause any issues to simply include these fields on any in-memory
representation of FIRRTL IR. Although other systems for tracking FIRRTL
analyses have evolved over time, the ubiquity of pattern-matching on
these fields has lead most core and custom transforms to be written
against WIR, rather than IR.
This PR unifies the IRs by adding the fields that would be in an
"augmented" WIR node directly into the corresponding IR node; i.e., the
"type" and "kind" fields from WRef are added directly to the definition
of the Reference case class, while these "repetitive" WIR case classes
are removed entirely.
-------------------- SOURCE-COMPATIBILITY ADAPTERS ---------------------
Several object methods are added to WIR.scala to maintain
source-compatiblity for passes that used WIR. These objects define
factory methods and unapply methods, so passes that relied on implicit
case class factories or pattern matching for the removed WIR types will
remain perfectly source-compatible. However, these do not guarantee
compatibility at the binary level.
The types of the removed WIR case classes are also added as type aliases
to the top-level firrtl package, which allows code that relies on
explicit constructor calls or reflection to retain source-compatibility.
Finally, additional explicit factory methods are added to the companion
objects of the newly-augmented IR case classes, which allows user code
to avoid having to specify any of the new analysis fields. Existing code
that created non-WIR IR nodes will be able to continue using the
previous factory signatures, which will cause all omitted analysis
fields to be set to Unknown.
---------------------- UNMITIGATED API CHANGES -------------------------
While passes that used WIR will be source-compatible with this change,
there is one significant change that affects any pass currently using
non-WIR IR: the signatures of pattern-matching cases for Reference,
SubField, SubIndex, SubAccess, and DefInstance must change to
accommodate the extra fields.
This cannot be worked at the API level due to restrictions on unapply
overloading, but it could theoretically be solved with macros or other
static rewriting. However, only four core transforms (RemoveProto,
ToWorkingIR, Dedup, and RemoveChirrtl) use non-WIR IR, and it is
expected that no user code currently relies on it, so the expected
migration strategy is simply to change the small fraction of code
relying on these nodes.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/firrtl/Emitter.scala | 2 | ||||
| -rw-r--r-- | src/main/scala/firrtl/Utils.scala | 14 | ||||
| -rw-r--r-- | src/main/scala/firrtl/WIR.scala | 70 | ||||
| -rw-r--r-- | src/main/scala/firrtl/annotations/AnnotationUtils.scala | 8 | ||||
| -rw-r--r-- | src/main/scala/firrtl/annotations/TargetToken.scala | 6 | ||||
| -rw-r--r-- | src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala | 2 | ||||
| -rw-r--r-- | src/main/scala/firrtl/ir/IR.scala | 34 | ||||
| -rw-r--r-- | src/main/scala/firrtl/package.scala | 6 | ||||
| -rw-r--r-- | src/main/scala/firrtl/passes/RemoveCHIRRTL.scala | 4 | ||||
| -rw-r--r-- | src/main/scala/firrtl/passes/ToWorkingIR.scala | 19 | ||||
| -rw-r--r-- | src/main/scala/firrtl/proto/ToProto.scala | 10 | ||||
| -rw-r--r-- | src/main/scala/firrtl/transforms/Dedup.scala | 4 | ||||
| -rw-r--r-- | src/main/scala/tutorial/lesson2-working-ir/AnalyzeCircuit.scala | 4 | ||||
| -rw-r--r-- | src/test/scala/firrtl/testutils/FirrtlSpec.scala | 4 | ||||
| -rw-r--r-- | src/test/scala/firrtlTests/ChirrtlMemSpec.scala | 2 |
15 files changed, 77 insertions, 112 deletions
diff --git a/src/main/scala/firrtl/Emitter.scala b/src/main/scala/firrtl/Emitter.scala index aa2cdc18..6c83974b 100644 --- a/src/main/scala/firrtl/Emitter.scala +++ b/src/main/scala/firrtl/Emitter.scala @@ -121,7 +121,7 @@ sealed abstract class FirrtlEmitter(form: CircuitForm) extends Transform with Em // Use list instead of set to maintain order val modules = mutable.ArrayBuffer.empty[DefModule] def onStmt(stmt: Statement): Unit = stmt match { - case DefInstance(_, _, name) => modules += map(name) + case DefInstance(_, _, name, _) => modules += map(name) case WDefInstance(_, _, name, _) => modules += map(name) case _: WDefInstanceConnector => throwInternalError(s"unrecognized statement: $stmt") case other => other.foreach(onStmt) diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index db3c8d3e..75266731 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -220,12 +220,12 @@ object Utils extends LazyLogging { case WSubAccess(expr, index, _, _) => niceName(depth)(expr) + niceName(depth - 1)(index) case WSubField(expr, field, _, _) => niceName(depth)(expr) + "_" + field case WSubIndex(expr, index, _, _) => niceName(depth)(expr) + "_" + index - case Reference(name, _) if name(0) == '_' => name - case Reference(name, _) => "_" + name - case SubAccess(expr, index, _) if depth <= 0 => niceName(depth)(expr) - case SubAccess(expr, index, _) => niceName(depth)(expr) + niceName(depth - 1)(index) - case SubField(expr, field, _) => niceName(depth)(expr) + "_" + field - case SubIndex(expr, index, _) => niceName(depth)(expr) + "_" + index + case Reference(name, _, _, _) if name(0) == '_' => name + case Reference(name, _, _, _) => "_" + name + case SubAccess(expr, index, _, _) if depth <= 0 => niceName(depth)(expr) + case SubAccess(expr, index, _, _) => niceName(depth)(expr) + niceName(depth - 1)(index) + case SubField(expr, field, _, _) => niceName(depth)(expr) + "_" + field + case SubIndex(expr, index, _, _) => niceName(depth)(expr) + "_" + index case DoPrim(op, args, consts, _) if depth <= 0 => "_" + op case DoPrim(op, args, consts, _) => "_" + op + (args.map(niceName(depth - 1)) ++ consts.map("_" + _)).mkString("") case Mux(cond, tval, fval, _) if depth <= 0 => "_mux" @@ -388,7 +388,7 @@ object Utils extends LazyLogging { */ def inline(nodeMap: NodeMap, stop: String => Boolean = {x: String => false})(e: Expression): Expression = { def onExp(e: Expression): Expression = e map onExp match { - case Reference(name, _) if nodeMap.contains(name) && !stop(name) => onExp(nodeMap(name)) + case Reference(name, _, _, _) if nodeMap.contains(name) && !stop(name) => onExp(nodeMap(name)) case WRef(name, _, _, _) if nodeMap.contains(name) && !stop(name) => onExp(nodeMap(name)) case other => other } diff --git a/src/main/scala/firrtl/WIR.scala b/src/main/scala/firrtl/WIR.scala index 3ed02fd0..2f1daadd 100644 --- a/src/main/scala/firrtl/WIR.scala +++ b/src/main/scala/firrtl/WIR.scala @@ -26,15 +26,6 @@ case object SinkFlow extends Flow case object DuplexFlow extends Flow case object UnknownFlow extends Flow -case class WRef(name: String, tpe: Type, kind: Kind, flow: Flow) extends Expression { - def serialize: String = name - def mapExpr(f: Expression => Expression): Expression = this - def mapType(f: Type => Type): Expression = this.copy(tpe = f(tpe)) - def mapWidth(f: Width => Width): Expression = this - def foreachExpr(f: Expression => Unit): Unit = Unit - def foreachType(f: Type => Unit): Unit = f(tpe) - def foreachWidth(f: Width => Unit): Unit = Unit -} object WRef { /** Creates a WRef from a Wire */ def apply(wire: DefWire): WRef = new WRef(wire.name, wire.tpe, WireKind, UnknownFlow) @@ -49,39 +40,29 @@ object WRef { /** Creates a WRef from a DefMemory */ def apply(mem: DefMemory): WRef = new WRef(mem.name, passes.MemPortUtils.memType(mem), MemKind, UnknownFlow) /** Creates a WRef from an arbitrary string name */ - def apply(n: String, t: Type = UnknownType, k: Kind = ExpKind): WRef = new WRef(n, t, k, UnknownFlow) -} -case class WSubField(expr: Expression, name: String, tpe: Type, flow: Flow) extends Expression { - def serialize: String = s"${expr.serialize}.$name" - def mapExpr(f: Expression => Expression): Expression = this.copy(expr = f(expr)) - def mapType(f: Type => Type): Expression = this.copy(tpe = f(tpe)) - def mapWidth(f: Width => Width): Expression = this - def foreachExpr(f: Expression => Unit): Unit = f(expr) - def foreachType(f: Type => Unit): Unit = f(tpe) - def foreachWidth(f: Width => Unit): Unit = Unit + def apply(n: String, t: Type = UnknownType, k: Kind = ExpKind): WRef = Reference(n, t, k, UnknownFlow) + + def apply(name: String, tpe: Type , kind: Kind, flow: Flow): WRef = Reference(name, tpe, kind, flow) + def unapply(ref: Reference): Option[(String, Type, Kind, Flow)] = Some((ref.name, ref.tpe, ref.kind, ref.flow)) } + object WSubField { def apply(expr: Expression, n: String): WSubField = new WSubField(expr, n, field_type(expr.tpe, n), UnknownFlow) def apply(expr: Expression, name: String, tpe: Type): WSubField = new WSubField(expr, name, tpe, UnknownFlow) + def apply(expr: Expression, name: String, tpe: Type, flow: Flow): WSubField = new WSubField(expr, name, tpe, flow) + def unapply(wsf: WSubField): Option[(Expression, String, Type, Flow)] = Some((wsf.expr, wsf.name, wsf.tpe, wsf.flow)) } -case class WSubIndex(expr: Expression, value: Int, tpe: Type, flow: Flow) extends Expression { - def serialize: String = s"${expr.serialize}[$value]" - def mapExpr(f: Expression => Expression): Expression = this.copy(expr = f(expr)) - def mapType(f: Type => Type): Expression = this.copy(tpe = f(tpe)) - def mapWidth(f: Width => Width): Expression = this - def foreachExpr(f: Expression => Unit): Unit = f(expr) - def foreachType(f: Type => Unit): Unit = f(tpe) - def foreachWidth(f: Width => Unit): Unit = Unit + +object WSubIndex { + def apply(expr: Expression, value: Int, tpe: Type, flow: Flow): WSubIndex = new WSubIndex(expr, value, tpe, flow) + def unapply(wsi: WSubIndex): Option[(Expression, Int, Type, Flow)] = Some((wsi.expr, wsi.value, wsi.tpe, wsi.flow)) } -case class WSubAccess(expr: Expression, index: Expression, tpe: Type, flow: Flow) extends Expression { - def serialize: String = s"${expr.serialize}[${index.serialize}]" - def mapExpr(f: Expression => Expression): Expression = this.copy(expr = f(expr), index = f(index)) - def mapType(f: Type => Type): Expression = this.copy(tpe = f(tpe)) - def mapWidth(f: Width => Width): Expression = this - def foreachExpr(f: Expression => Unit): Unit = { f(expr); f(index) } - def foreachType(f: Type => Unit): Unit = f(tpe) - def foreachWidth(f: Width => Unit): Unit = Unit + +object WSubAccess { + def apply(expr: Expression, index: Expression, tpe: Type, flow: Flow): WSubAccess = new WSubAccess(expr, index, tpe, flow) + def unapply(wsa: WSubAccess): Option[(Expression, Expression, Type, Flow)] = Some((wsa.expr, wsa.index, wsa.tpe, wsa.flow)) } + case object WVoid extends Expression { def tpe = UnknownType def serialize: String = "VOID" @@ -113,22 +94,15 @@ case object EmptyExpression extends Expression { def foreachType(f: Type => Unit): Unit = Unit def foreachWidth(f: Width => Unit): Unit = Unit } -case class WDefInstance(info: Info, name: String, module: String, tpe: Type) extends Statement with IsDeclaration { - def serialize: String = s"inst $name of $module" + info.serialize - def mapExpr(f: Expression => Expression): Statement = this - def mapStmt(f: Statement => Statement): Statement = this - def mapType(f: Type => Type): Statement = this.copy(tpe = f(tpe)) - def mapString(f: String => String): Statement = this.copy(name = f(name)) - def mapInfo(f: Info => Info): Statement = this.copy(f(info)) - def foreachStmt(f: Statement => Unit): Unit = Unit - def foreachExpr(f: Expression => Unit): Unit = Unit - def foreachType(f: Type => Unit): Unit = f(tpe) - def foreachString(f: String => Unit): Unit = f(name) - def foreachInfo(f: Info => Unit): Unit = f(info) -} + object WDefInstance { def apply(name: String, module: String): WDefInstance = new WDefInstance(NoInfo, name, module, UnknownType) + def apply(info: Info, name: String, module: String, tpe: Type): WDefInstance = new WDefInstance(info, name, module, tpe) + def unapply(wi: WDefInstance): Option[(Info, String, String, Type)] = { + Some((wi.info, wi.name, wi.module, wi.tpe)) + } } + case class WDefInstanceConnector( info: Info, name: String, diff --git a/src/main/scala/firrtl/annotations/AnnotationUtils.scala b/src/main/scala/firrtl/annotations/AnnotationUtils.scala index 9a7a8fd2..52b18400 100644 --- a/src/main/scala/firrtl/annotations/AnnotationUtils.scala +++ b/src/main/scala/firrtl/annotations/AnnotationUtils.scala @@ -66,10 +66,10 @@ object AnnotationUtils { def toSubComponents(s: String): Seq[TargetToken] = { import TargetToken._ def exp2subcomp(e: ir.Expression): Seq[TargetToken] = e match { - case ir.Reference(name, _) => Seq(Ref(name)) - case ir.SubField(expr, name, _) => exp2subcomp(expr) :+ Field(name) - case ir.SubIndex(expr, idx, _) => exp2subcomp(expr) :+ Index(idx) - case ir.SubAccess(expr, idx, _) => Utils.throwInternalError(s"For string $s, cannot convert a subaccess $e into a Target") + case ir.Reference(name, _, _, _) => Seq(Ref(name)) + case ir.SubField(expr, name, _, _) => exp2subcomp(expr) :+ Field(name) + case ir.SubIndex(expr, idx, _, _) => exp2subcomp(expr) :+ Index(idx) + case ir.SubAccess(expr, idx, _, _) => Utils.throwInternalError(s"For string $s, cannot convert a subaccess $e into a Target") } exp2subcomp(toExp(s)) } diff --git a/src/main/scala/firrtl/annotations/TargetToken.scala b/src/main/scala/firrtl/annotations/TargetToken.scala index 70b64271..765102a6 100644 --- a/src/main/scala/firrtl/annotations/TargetToken.scala +++ b/src/main/scala/firrtl/annotations/TargetToken.scala @@ -56,12 +56,6 @@ case object TargetToken { def toTokens: (Instance, OfModule) = (new TargetToken.Instance(i.name), new TargetToken.OfModule(i.module)) } - implicit class fromWDefInstanceToTargetToken(wi: WDefInstance) { - def Instance: Instance = new TargetToken.Instance(wi.name) - def OfModule: OfModule = new TargetToken.OfModule(wi.module) - def toTokens: (Instance, OfModule) = (new TargetToken.Instance(wi.name), new TargetToken.OfModule(wi.module)) - } - val keyword2targettoken = Map( "inst" -> ((value: String) => Instance(value)), "of" -> ((value: String) => OfModule(value)), diff --git a/src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala b/src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala index 5ba6e4fa..a4cd2f3d 100644 --- a/src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala +++ b/src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala @@ -59,7 +59,7 @@ class EliminateTargetPaths extends Transform with DependencyAPIMigration with Pr private def onStmt(dupMap: DuplicationHelper) (originalModule: String, newModule: String) (s: Statement): Statement = s match { - case d@DefInstance(_, name, module) => + case d@DefInstance(_, name, module, _) => val ofModule = dupMap.getNewOfModule(originalModule, newModule, Instance(name), OfModule(module)).value d.copy(module = ofModule) case d@WDefInstance(_, name, module, _) => diff --git a/src/main/scala/firrtl/ir/IR.scala b/src/main/scala/firrtl/ir/IR.scala index 07cbb7e2..fd119d39 100644 --- a/src/main/scala/firrtl/ir/IR.scala +++ b/src/main/scala/firrtl/ir/IR.scala @@ -140,7 +140,9 @@ abstract class Expression extends FirrtlNode { def foreachType(f: Type => Unit): Unit def foreachWidth(f: Width => Unit): Unit } -case class Reference(name: String, tpe: Type) extends Expression with HasName { + +case class Reference(name: String, tpe: Type, kind: Kind = UnknownKind, flow: Flow = UnknownFlow) + extends Expression with HasName { def serialize: String = name def mapExpr(f: Expression => Expression): Expression = this def mapType(f: Type => Type): Expression = this.copy(tpe = f(tpe)) @@ -149,7 +151,9 @@ case class Reference(name: String, tpe: Type) extends Expression with HasName { def foreachType(f: Type => Unit): Unit = f(tpe) def foreachWidth(f: Width => Unit): Unit = Unit } -case class SubField(expr: Expression, name: String, tpe: Type) extends Expression with HasName { + +case class SubField(expr: Expression, name: String, tpe: Type, flow: Flow = UnknownFlow) + extends Expression with HasName { def serialize: String = s"${expr.serialize}.$name" def mapExpr(f: Expression => Expression): Expression = this.copy(expr = f(expr)) def mapType(f: Type => Type): Expression = this.copy(tpe = f(tpe)) @@ -158,7 +162,9 @@ case class SubField(expr: Expression, name: String, tpe: Type) extends Expressio def foreachType(f: Type => Unit): Unit = f(tpe) def foreachWidth(f: Width => Unit): Unit = Unit } -case class SubIndex(expr: Expression, value: Int, tpe: Type) extends Expression { + +case class SubIndex(expr: Expression, value: Int, tpe: Type, flow: Flow = UnknownFlow) + extends Expression { def serialize: String = s"${expr.serialize}[$value]" def mapExpr(f: Expression => Expression): Expression = this.copy(expr = f(expr)) def mapType(f: Type => Type): Expression = this.copy(tpe = f(tpe)) @@ -167,16 +173,18 @@ case class SubIndex(expr: Expression, value: Int, tpe: Type) extends Expression def foreachType(f: Type => Unit): Unit = f(tpe) def foreachWidth(f: Width => Unit): Unit = Unit } -case class SubAccess(expr: Expression, index: Expression, tpe: Type) extends Expression { + +case class SubAccess(expr: Expression, index: Expression, tpe: Type, flow: Flow = UnknownFlow) + extends Expression { def serialize: String = s"${expr.serialize}[${index.serialize}]" - def mapExpr(f: Expression => Expression): Expression = - this.copy(expr = f(expr), index = f(index)) + def mapExpr(f: Expression => Expression): Expression = this.copy(expr = f(expr), index = f(index)) def mapType(f: Type => Type): Expression = this.copy(tpe = f(tpe)) def mapWidth(f: Width => Width): Expression = this def foreachExpr(f: Expression => Unit): Unit = { f(expr); f(index) } def foreachType(f: Type => Unit): Unit = f(tpe) def foreachWidth(f: Width => Unit): Unit = Unit } + case class Mux(cond: Expression, tval: Expression, fval: Expression, tpe: Type = UnknownType) extends Expression { def serialize: String = s"mux(${cond.serialize}, ${tval.serialize}, ${fval.serialize})" def mapExpr(f: Expression => Expression): Expression = Mux(f(cond), f(tval), f(fval), tpe) @@ -298,16 +306,18 @@ case class DefRegister( def foreachString(f: String => Unit): Unit = f(name) def foreachInfo(f: Info => Unit): Unit = f(info) } -case class DefInstance(info: Info, name: String, module: String) extends Statement with IsDeclaration { + +case class DefInstance(info: Info, name: String, module: String, tpe: Type = UnknownType) + extends Statement with IsDeclaration { def serialize: String = s"inst $name of $module" + info.serialize - def mapStmt(f: Statement => Statement): Statement = this def mapExpr(f: Expression => Expression): Statement = this - def mapType(f: Type => Type): Statement = this - def mapString(f: String => String): Statement = DefInstance(info, f(name), module) - def mapInfo(f: Info => Info): Statement = this.copy(info = f(info)) + def mapStmt(f: Statement => Statement): Statement = this + def mapType(f: Type => Type): Statement = this.copy(tpe = f(tpe)) + def mapString(f: String => String): Statement = this.copy(name = f(name)) + def mapInfo(f: Info => Info): Statement = this.copy(f(info)) def foreachStmt(f: Statement => Unit): Unit = Unit def foreachExpr(f: Expression => Unit): Unit = Unit - def foreachType(f: Type => Unit): Unit = Unit + def foreachType(f: Type => Unit): Unit = f(tpe) def foreachString(f: String => Unit): Unit = f(name) def foreachInfo(f: Info => Unit): Unit = f(info) } diff --git a/src/main/scala/firrtl/package.scala b/src/main/scala/firrtl/package.scala index ec715979..11b2ab44 100644 --- a/src/main/scala/firrtl/package.scala +++ b/src/main/scala/firrtl/package.scala @@ -15,4 +15,10 @@ package object firrtl { @deprecated("Use firrtl.stage.TargetDirAnnotation", "1.2") val TargetDirAnnotation = firrtl.options.TargetDirAnnotation + + type WRef = ir.Reference + type WSubField = ir.SubField + type WSubIndex = ir.SubIndex + type WSubAccess = ir.SubAccess + type WDefInstance = ir.DefInstance } diff --git a/src/main/scala/firrtl/passes/RemoveCHIRRTL.scala b/src/main/scala/firrtl/passes/RemoveCHIRRTL.scala index af9518e9..67181f2b 100644 --- a/src/main/scala/firrtl/passes/RemoveCHIRRTL.scala +++ b/src/main/scala/firrtl/passes/RemoveCHIRRTL.scala @@ -183,7 +183,7 @@ object RemoveCHIRRTL extends Transform with DependencyAPIMigration with Preserve var has_readwrite_mport: Option[Expression] = None var has_read_mport: Option[Expression] = None def remove_chirrtl_e(g: Flow)(e: Expression): Expression = e match { - case Reference(name, tpe) => refs get name match { + case Reference(name, tpe, _, _) => refs get name match { case Some(p) => g match { case SinkFlow => has_write_mport = true @@ -200,7 +200,7 @@ object RemoveCHIRRTL extends Transform with DependencyAPIMigration with Preserve case SourceFlow => e } } - case SubAccess(expr, index, tpe) => SubAccess( + case SubAccess(expr, index, tpe, _) => SubAccess( remove_chirrtl_e(g)(expr), remove_chirrtl_e(SourceFlow)(index), tpe) case ex => ex map remove_chirrtl_e(g) } diff --git a/src/main/scala/firrtl/passes/ToWorkingIR.scala b/src/main/scala/firrtl/passes/ToWorkingIR.scala index 53936c18..3f044e03 100644 --- a/src/main/scala/firrtl/passes/ToWorkingIR.scala +++ b/src/main/scala/firrtl/passes/ToWorkingIR.scala @@ -5,24 +5,7 @@ import firrtl.Mappers._ import firrtl.options.{PreservesAll} import firrtl.{Transform, UnknownFlow, UnknownKind, WDefInstance, WRef, WSubAccess, WSubField, WSubIndex} -// These should be distributed into separate files object ToWorkingIR extends Pass with PreservesAll[Transform] { - override def prerequisites = firrtl.stage.Forms.MinimalHighForm - - def toExp(e: Expression): Expression = e map toExp match { - case ex: Reference => WRef(ex.name, ex.tpe, UnknownKind, UnknownFlow) - case ex: SubField => WSubField(ex.expr, ex.name, ex.tpe, UnknownFlow) - case ex: SubIndex => WSubIndex(ex.expr, ex.value, ex.tpe, UnknownFlow) - case ex: SubAccess => WSubAccess(ex.expr, ex.index, ex.tpe, UnknownFlow) - case ex => ex // This might look like a case to use case _ => e, DO NOT! - } - - def toStmt(s: Statement): Statement = s map toExp match { - case sx: DefInstance => WDefInstance(sx.info, sx.name, sx.module, UnknownType) - case sx => sx map toStmt - } - - def run (c:Circuit): Circuit = - c copy (modules = c.modules map (_ map toStmt)) + def run(c:Circuit): Circuit = c } diff --git a/src/main/scala/firrtl/proto/ToProto.scala b/src/main/scala/firrtl/proto/ToProto.scala index 9fe01a07..c246656f 100644 --- a/src/main/scala/firrtl/proto/ToProto.scala +++ b/src/main/scala/firrtl/proto/ToProto.scala @@ -141,21 +141,21 @@ object ToProto { def convert(expr: ir.Expression): Firrtl.Expression.Builder = { val eb = Firrtl.Expression.newBuilder() expr match { - case ir.Reference(name, _) => + case ir.Reference(name, _, _, _) => val rb = Firrtl.Expression.Reference.newBuilder() .setId(name) eb.setReference(rb) - case ir.SubField(e, name, _) => + case ir.SubField(e, name, _, _) => val sb = Firrtl.Expression.SubField.newBuilder() .setExpression(convert(e)) .setField(name) eb.setSubField(sb) - case ir.SubIndex(e, value, _) => + case ir.SubIndex(e, value, _, _) => val sb = Firrtl.Expression.SubIndex.newBuilder() .setExpression(convert(e)) .setIndex(convertToIntegerLiteral(value)) eb.setSubIndex(sb) - case ir.SubAccess(e, index, _) => + case ir.SubAccess(e, index, _, _) => val sb = Firrtl.Expression.SubAccess.newBuilder() .setExpression(convert(e)) .setIndex(convert(index)) @@ -231,7 +231,7 @@ object ToProto { .setReset(convert(reset)) .setInit(convert(init)) sb.setRegister(rb) - case ir.DefInstance(_, name, module) => + case ir.DefInstance(_, name, module, _) => val ib = Firrtl.Statement.Instance.newBuilder() .setId(name) .setModuleId(module) diff --git a/src/main/scala/firrtl/transforms/Dedup.scala b/src/main/scala/firrtl/transforms/Dedup.scala index 3ef7a403..09fd3af8 100644 --- a/src/main/scala/firrtl/transforms/Dedup.scala +++ b/src/main/scala/firrtl/transforms/Dedup.scala @@ -133,7 +133,9 @@ object DedupModules { case WDefInstance(i, n, m, t) => val newmod = renameOfModule(n, m) WDefInstance(reinfo(i), rename(n), newmod, retype(n)(t)) - case DefInstance(i, n, m) => DefInstance(reinfo(i), rename(n), renameOfModule(n, m)) + case DefInstance(i, n, m, t) => + val newmod = renameOfModule(n, m) + WDefInstance(reinfo(i), rename(n), newmod, retype(n)(t)) case d: DefMemory => val oldType = MemPortUtils.memType(d) val newType = retype(d.name)(oldType) diff --git a/src/main/scala/tutorial/lesson2-working-ir/AnalyzeCircuit.scala b/src/main/scala/tutorial/lesson2-working-ir/AnalyzeCircuit.scala index 87cc3c59..f7344fd2 100644 --- a/src/main/scala/tutorial/lesson2-working-ir/AnalyzeCircuit.scala +++ b/src/main/scala/tutorial/lesson2-working-ir/AnalyzeCircuit.scala @@ -127,10 +127,6 @@ class AnalyzeCircuit extends Transform { // Map the functions walkStatement(ledger) and walkExpression(ledger) val visited = s map walkStatement(ledger) map walkExpression(ledger) visited match { - // IR node [[DefInstance]] is previously replaced by WDefInstance, a - // "working" IR node - case DefInstance(info, name, module) => - Utils.error("All DefInstances should have been replaced by WDefInstances") // Working IR Node [[WDefInstance]] is what the compiler uses // See src/main/scala/firrtl/WIR.scala for all working IR nodes case WDefInstance(info, name, module, tpe) => diff --git a/src/test/scala/firrtl/testutils/FirrtlSpec.scala b/src/test/scala/firrtl/testutils/FirrtlSpec.scala index c9cd1ecd..cab66332 100644 --- a/src/test/scala/firrtl/testutils/FirrtlSpec.scala +++ b/src/test/scala/firrtl/testutils/FirrtlSpec.scala @@ -306,12 +306,12 @@ class TestFirrtlFlatSpec extends FirrtlFlatSpec { it should "be supported on Circuit" in { assert(c search { - case Connect(_, Reference("out",_), Reference("in",_)) => true + case Connect(_, Reference("out",_, _, _), Reference("in", _, _, _)) => true }) } it should "be supported on CircuitStates" in { assert(state search { - case Connect(_, Reference("out",_), Reference("in",_)) => true + case Connect(_, Reference("out", _, _, _), Reference("in",_, _, _)) => true }) } it should "be supported on the results of compilers" in { diff --git a/src/test/scala/firrtlTests/ChirrtlMemSpec.scala b/src/test/scala/firrtlTests/ChirrtlMemSpec.scala index 3868c237..b22283a7 100644 --- a/src/test/scala/firrtlTests/ChirrtlMemSpec.scala +++ b/src/test/scala/firrtlTests/ChirrtlMemSpec.scala @@ -258,7 +258,7 @@ circuit foo : |""".stripMargin val res = (new HighFirrtlCompiler).compile(CircuitState(parse(input), ChirrtlForm), Seq()).circuit assert(res search { - case Connect(_, SubField(SubField(Reference("mem", _), "bar", _), "clk", _), DoPrim(AsClock, Seq(Reference("clock", _)), _, _)) => true + case Connect(_, SubField(SubField(Reference("mem", _, _, _), "bar", _, _), "clk", _, _), DoPrim(AsClock, Seq(Reference("clock", _, _, _)), _, _)) => true }) } } |
