aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAlbert Magyar2020-05-27 16:07:35 -0700
committerAlbert Magyar2020-06-02 16:50:31 -0700
commit35183faa23a8f54cbf83a6d124f3e6ef7df91251 (patch)
treed250e882febdcee03bb5546303472ba6b0700ee2 /src/main
parentb7b9af739b7f1b96c030619f8910cfd6f571d6d6 (diff)
Add extra convenience factories for regular IR nodes
* This will help encourage use of these rather than WIR
Diffstat (limited to 'src/main')
-rw-r--r--src/main/scala/firrtl/ir/IR.scala23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/main/scala/firrtl/ir/IR.scala b/src/main/scala/firrtl/ir/IR.scala
index fd119d39..64181642 100644
--- a/src/main/scala/firrtl/ir/IR.scala
+++ b/src/main/scala/firrtl/ir/IR.scala
@@ -141,7 +141,22 @@ abstract class Expression extends FirrtlNode {
def foreachWidth(f: Width => Unit): Unit
}
-case class Reference(name: String, tpe: Type, kind: Kind = UnknownKind, flow: Flow = UnknownFlow)
+object Reference {
+ /** Creates a Reference from a Wire */
+ def apply(wire: DefWire): Reference = Reference(wire.name, wire.tpe, WireKind, UnknownFlow)
+ /** Creates a Reference from a Register */
+ def apply(reg: DefRegister): Reference = Reference(reg.name, reg.tpe, RegKind, UnknownFlow)
+ /** Creates a Reference from a Node */
+ def apply(node: DefNode): Reference = Reference(node.name, node.value.tpe, NodeKind, SourceFlow)
+ /** Creates a Reference from a Port */
+ def apply(port: Port): Reference = Reference(port.name, port.tpe, PortKind, UnknownFlow)
+ /** Creates a Reference from a DefInstance */
+ def apply(i: DefInstance): Reference = Reference(i.name, i.tpe, InstanceKind, UnknownFlow)
+ /** Creates a Reference from a DefMemory */
+ def apply(mem: DefMemory): Reference = Reference(mem.name, passes.MemPortUtils.memType(mem), MemKind, UnknownFlow)
+}
+
+case class Reference(name: String, tpe: Type = UnknownType, kind: Kind = UnknownKind, flow: Flow = UnknownFlow)
extends Expression with HasName {
def serialize: String = name
def mapExpr(f: Expression => Expression): Expression = this
@@ -152,7 +167,7 @@ case class Reference(name: String, tpe: Type, kind: Kind = UnknownKind, flow: Fl
def foreachWidth(f: Width => Unit): Unit = Unit
}
-case class SubField(expr: Expression, name: String, tpe: Type, flow: Flow = UnknownFlow)
+case class SubField(expr: Expression, name: String, tpe: Type = UnknownType, 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))
@@ -307,6 +322,10 @@ case class DefRegister(
def foreachInfo(f: Info => Unit): Unit = f(info)
}
+object DefInstance {
+ def apply(name: String, module: String): DefInstance = DefInstance(NoInfo, name, module)
+}
+
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