From 1d1798cfd03f23896b7ea6203a1569da9532a939 Mon Sep 17 00:00:00 2001 From: Albert Magyar Date: Fri, 21 Dec 2018 11:57:23 -0800 Subject: Small convenience tweaks to IR/WIR APIs (#961) * Seal Direction trait * Add WRef factories for ports and instances --- src/main/scala/firrtl/WIR.scala | 5 +++++ src/main/scala/firrtl/ir/IR.scala | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/scala/firrtl/WIR.scala b/src/main/scala/firrtl/WIR.scala index b96cd253..a5d2571d 100644 --- a/src/main/scala/firrtl/WIR.scala +++ b/src/main/scala/firrtl/WIR.scala @@ -40,6 +40,11 @@ object WRef { def apply(reg: DefRegister): WRef = new WRef(reg.name, reg.tpe, RegKind, UNKNOWNGENDER) /** Creates a WRef from a Node */ def apply(node: DefNode): WRef = new WRef(node.name, node.value.tpe, NodeKind, MALE) + /** Creates a WRef from a Port */ + def apply(port: Port): WRef = new WRef(port.name, port.tpe, PortKind, UNKNOWNGENDER) + /** Creates a WRef from a WDefInstance */ + def apply(wi: WDefInstance): WRef = new WRef(wi.name, wi.tpe, InstanceKind, UNKNOWNGENDER) + /** Creates a WRef from an arbitrary string name */ def apply(n: String, t: Type = UnknownType, k: Kind = ExpKind): WRef = new WRef(n, t, k, UNKNOWNGENDER) } case class WSubField(expr: Expression, name: String, tpe: Type, gender: Gender) extends Expression { diff --git a/src/main/scala/firrtl/ir/IR.scala b/src/main/scala/firrtl/ir/IR.scala index cdf8e194..19ee56ca 100644 --- a/src/main/scala/firrtl/ir/IR.scala +++ b/src/main/scala/firrtl/ir/IR.scala @@ -607,7 +607,7 @@ case object UnknownType extends Type { } /** [[Port]] Direction */ -abstract class Direction extends FirrtlNode +sealed abstract class Direction extends FirrtlNode case object Input extends Direction { def serialize: String = "input" } -- cgit v1.2.3