aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/Utils.scala
diff options
context:
space:
mode:
authorSchuyler Eldridge2019-07-17 14:08:33 -0400
committerSchuyler Eldridge2019-09-16 17:12:51 -0400
commita594ccef986c4567730fee729bdea9ed9aefed38 (patch)
tree2512913e054ea7d56867f2c73912ff4be17f1e82 /src/main/scala/firrtl/Utils.scala
parent7e39ea8ec948ff1db7ccd0d850923a86d2d8a4e7 (diff)
Rename gender to flow
The following names are changed: - gender -> flow - Gender -> Flow - MALE -> SourceFlow - FEMALE -> SinkFlow - BIGENDER -> DuplexFlow - UNKNOWNGENDER -> UnknownFlow Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Diffstat (limited to 'src/main/scala/firrtl/Utils.scala')
-rw-r--r--src/main/scala/firrtl/Utils.scala148
1 files changed, 74 insertions, 74 deletions
diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala
index 91da600a..45e611b2 100644
--- a/src/main/scala/firrtl/Utils.scala
+++ b/src/main/scala/firrtl/Utils.scala
@@ -34,9 +34,9 @@ object toBits {
}
private def hiercat(e: Expression): Expression = e.tpe match {
case t: VectorType => seqCat((0 until t.size).reverse map (i =>
- hiercat(WSubIndex(e, i, t.tpe, UNKNOWNGENDER))))
+ hiercat(WSubIndex(e, i, t.tpe, UnknownFlow))))
case t: BundleType => seqCat(t.fields map (f =>
- hiercat(WSubField(e, f.name, f.tpe, UNKNOWNGENDER))))
+ hiercat(WSubField(e, f.name, f.tpe, UnknownFlow))))
case t: GroundType => DoPrim(AsUInt, Seq(e), Seq.empty, UnknownType)
case t => Utils.error(s"Unknown type encountered in toBits: $e")
}
@@ -63,18 +63,18 @@ object bitWidth {
object castRhs {
def apply(lhst: Type, rhs: Expression) = {
(lhst, rhs.tpe) match {
- case (x: GroundType, y: GroundType) if WrappedType(x) == WrappedType(y) =>
+ case (x: GroundType, y: GroundType) if WrappedType(x) == WrappedType(y) =>
rhs
- case (_: SIntType, _) =>
+ case (_: SIntType, _) =>
DoPrim(AsSInt, Seq(rhs), Seq.empty, lhst)
- case (FixedType(_, IntWidth(p)), _) =>
+ case (FixedType(_, IntWidth(p)), _) =>
DoPrim(AsFixedPoint, Seq(rhs), Seq(p), lhst)
- case (ClockType, _) =>
+ case (ClockType, _) =>
DoPrim(AsClock, Seq(rhs), Seq.empty, lhst)
- case (_: UIntType, _) =>
+ case (_: UIntType, _) =>
DoPrim(AsUInt, Seq(rhs), Seq.empty, lhst)
case (_, _) => Utils.error("castRhs lhst, rhs type combination is invalid")
- }
+ }
}
}
@@ -102,13 +102,13 @@ object fromBits {
lhst match {
case t: VectorType => (0 until t.size foldLeft( (offset, Seq[Statement]()) )) {
case ((curOffset, stmts), i) =>
- val subidx = WSubIndex(lhs, i, t.tpe, UNKNOWNGENDER)
+ val subidx = WSubIndex(lhs, i, t.tpe, UnknownFlow)
val (tmpOffset, substmts) = getPart(subidx, t.tpe, rhs, curOffset)
(tmpOffset, stmts ++ substmts)
}
case t: BundleType => (t.fields foldRight( (offset, Seq[Statement]()) )) {
case (f, (curOffset, stmts)) =>
- val subfield = WSubField(lhs, f.name, f.tpe, UNKNOWNGENDER)
+ val subfield = WSubField(lhs, f.name, f.tpe, UnknownFlow)
val (tmpOffset, substmts) = getPart(subfield, f.tpe, rhs, curOffset)
(tmpOffset, stmts ++ substmts)
}
@@ -228,7 +228,7 @@ object Utils extends LazyLogging {
val zero = UIntLiteral(0)
def create_exps(n: String, t: Type): Seq[Expression] =
- create_exps(WRef(n, t, ExpKind, UNKNOWNGENDER))
+ create_exps(WRef(n, t, ExpKind, UnknownFlow))
def create_exps(e: Expression): Seq[Expression] = e match {
case ex: Mux =>
val e1s = create_exps(ex.tval)
@@ -240,8 +240,8 @@ object Utils extends LazyLogging {
case ex => ex.tpe match {
case (_: GroundType) => Seq(ex)
case t: BundleType =>
- t.fields.flatMap(f => create_exps(WSubField(ex, f.name, f.tpe,times(gender(ex), f.flip))))
- case t: VectorType => (0 until t.size).flatMap(i => create_exps(WSubIndex(ex, i, t.tpe,gender(ex))))
+ t.fields.flatMap(f => create_exps(WSubField(ex, f.name, f.tpe,times(flow(ex), f.flip))))
+ case t: VectorType => (0 until t.size).flatMap(i => create_exps(WSubIndex(ex, i, t.tpe,flow(ex))))
}
}
@@ -260,9 +260,9 @@ object Utils extends LazyLogging {
case ex => ex.tpe match {
case (_: GroundType) => Seq(ex)
case (t: BundleType) => (t.fields foldLeft Seq[Expression](ex))((exps, f) =>
- exps ++ create_exps(WSubField(ex, f.name, f.tpe,times(gender(ex), f.flip))))
+ exps ++ create_exps(WSubField(ex, f.name, f.tpe,times(flow(ex), f.flip))))
case (t: VectorType) => (0 until t.size foldLeft Seq[Expression](ex))((exps, i) =>
- exps ++ create_exps(WSubIndex(ex, i, t.tpe,gender(ex))))
+ exps ++ create_exps(WSubIndex(ex, i, t.tpe,flow(ex))))
}
}
def toTarget(main: String, module: String)(expression: Expression): ReferenceTarget = {
@@ -283,7 +283,7 @@ object Utils extends LazyLogging {
onExp(expression)
ReferenceTarget(main, module, Nil, ref, tokens)
}
- @deprecated("get_flip is fundamentally slow, use to_flip(gender(expr))", "1.2")
+ @deprecated("get_flip is fundamentally slow, use to_flip(flow(expr))", "1.2")
def get_flip(t: Type, i: Int, f: Orientation): Orientation = {
if (i >= get_size(t)) throwInternalError(s"get_flip: shouldn't be here - $i >= get_size($t)")
t match {
@@ -308,7 +308,7 @@ object Utils extends LazyLogging {
flip.get
}
}
-
+
def get_point (e:Expression) : Int = e match {
case (e: WRef) => 0
case (e: WSubField) => e.expr.tpe match {case b: BundleType =>
@@ -418,7 +418,7 @@ object Utils extends LazyLogging {
}
case vx => UnknownType
}
-
+
// =================================
def error(str: String, cause: Throwable = null) = throw new FirrtlInternalException(str, cause)
@@ -473,12 +473,12 @@ object Utils extends LazyLogging {
}
}
-// =========== GENDER/FLIP UTILS ============
- def swap(g: Gender) : Gender = g match {
- case UNKNOWNGENDER => UNKNOWNGENDER
- case MALE => FEMALE
- case FEMALE => MALE
- case BIGENDER => BIGENDER
+// =========== FLOW/FLIP UTILS ============
+ def swap(g: Flow) : Flow = g match {
+ case UnknownFlow => UnknownFlow
+ case SourceFlow => SinkFlow
+ case SinkFlow => SourceFlow
+ case DuplexFlow => DuplexFlow
}
def swap(d: Direction) : Direction = d match {
case Output => Input
@@ -488,21 +488,21 @@ object Utils extends LazyLogging {
case Default => Flip
case Flip => Default
}
- def to_dir(g: Gender): Direction = g match {
- case MALE => Input
- case FEMALE => Output
+ def to_dir(g: Flow): Direction = g match {
+ case SourceFlow => Input
+ case SinkFlow => Output
}
- def to_gender(d: Direction): Gender = d match {
- case Input => MALE
- case Output => FEMALE
+ def to_flow(d: Direction): Flow = d match {
+ case Input => SourceFlow
+ case Output => SinkFlow
}
def to_flip(d: Direction): Orientation = d match {
case Input => Flip
case Output => Default
}
- def to_flip(g: Gender): Orientation = g match {
- case MALE => Flip
- case FEMALE => Default
+ def to_flip(g: Flow): Orientation = g match {
+ case SourceFlow => Flip
+ case SinkFlow => Default
}
def field_flip(v: Type, s: String): Orientation = v match {
@@ -524,14 +524,14 @@ object Utils extends LazyLogging {
case Default => d
case Flip => swap(d)
}
- def times(g: Gender, d: Direction): Direction = times(d, g)
- def times(d: Direction, g: Gender): Direction = g match {
- case FEMALE => d
- case MALE => swap(d) // MALE == INPUT == REVERSE
+ def times(g: Flow, d: Direction): Direction = times(d, g)
+ def times(d: Direction, g: Flow): Direction = g match {
+ case SinkFlow => d
+ case SourceFlow => swap(d) // SourceFlow == INPUT == REVERSE
}
- def times(g: Gender, flip: Orientation): Gender = times(flip, g)
- def times(flip: Orientation, g: Gender): Gender = flip match {
+ def times(g: Flow, flip: Orientation): Flow = times(flip, g)
+ def times(flip: Orientation, g: Flow): Flow = flip match {
case Default => g
case Flip => swap(g)
}
@@ -548,35 +548,35 @@ object Utils extends LazyLogging {
case ex: WSubAccess => kind(ex.expr)
case ex => ExpKind
}
- def gender(e: Expression): Gender = e match {
- case ex: WRef => ex.gender
- case ex: WSubField => ex.gender
- case ex: WSubIndex => ex.gender
- case ex: WSubAccess => ex.gender
- case ex: DoPrim => MALE
- case ex: UIntLiteral => MALE
- case ex: SIntLiteral => MALE
- case ex: Mux => MALE
- case ex: ValidIf => MALE
- case WInvalid => MALE
- case ex => throwInternalError(s"gender: shouldn't be here - $e")
- }
- def get_gender(s: Statement): Gender = s match {
- case sx: DefWire => BIGENDER
- case sx: DefRegister => BIGENDER
- case sx: WDefInstance => MALE
- case sx: DefNode => MALE
- case sx: DefInstance => MALE
- case sx: DefMemory => MALE
- case sx: Block => UNKNOWNGENDER
- case sx: Connect => UNKNOWNGENDER
- case sx: PartialConnect => UNKNOWNGENDER
- case sx: Stop => UNKNOWNGENDER
- case sx: Print => UNKNOWNGENDER
- case sx: IsInvalid => UNKNOWNGENDER
- case EmptyStmt => UNKNOWNGENDER
- }
- def get_gender(p: Port): Gender = if (p.direction == Input) MALE else FEMALE
+ def flow(e: Expression): Flow = e match {
+ case ex: WRef => ex.flow
+ case ex: WSubField => ex.flow
+ case ex: WSubIndex => ex.flow
+ case ex: WSubAccess => ex.flow
+ case ex: DoPrim => SourceFlow
+ case ex: UIntLiteral => SourceFlow
+ case ex: SIntLiteral => SourceFlow
+ case ex: Mux => SourceFlow
+ case ex: ValidIf => SourceFlow
+ case WInvalid => SourceFlow
+ case ex => throwInternalError(s"flow: shouldn't be here - $e")
+ }
+ def get_flow(s: Statement): Flow = s match {
+ case sx: DefWire => DuplexFlow
+ case sx: DefRegister => DuplexFlow
+ case sx: WDefInstance => SourceFlow
+ case sx: DefNode => SourceFlow
+ case sx: DefInstance => SourceFlow
+ case sx: DefMemory => SourceFlow
+ case sx: Block => UnknownFlow
+ case sx: Connect => UnknownFlow
+ case sx: PartialConnect => UnknownFlow
+ case sx: Stop => UnknownFlow
+ case sx: Print => UnknownFlow
+ case sx: IsInvalid => UnknownFlow
+ case EmptyStmt => UnknownFlow
+ }
+ def get_flow(p: Port): Flow = if (p.direction == Input) SourceFlow else SinkFlow
def get_info(s: Statement): Info = s match {
case s: HasInfo => s.info
case _ => NoInfo
@@ -598,23 +598,23 @@ object Utils extends LazyLogging {
case e: WRef => (e, EmptyExpression)
case e: WSubIndex =>
val (root, tail) = splitRef(e.expr)
- (root, WSubIndex(tail, e.value, e.tpe, e.gender))
+ (root, WSubIndex(tail, e.value, e.tpe, e.flow))
case e: WSubField =>
val (root, tail) = splitRef(e.expr)
tail match {
- case EmptyExpression => (root, WRef(e.name, e.tpe, root.kind, e.gender))
- case exp => (root, WSubField(tail, e.name, e.tpe, e.gender))
+ case EmptyExpression => (root, WRef(e.name, e.tpe, root.kind, e.flow))
+ case exp => (root, WSubField(tail, e.name, e.tpe, e.flow))
}
}
/** Adds a root reference to some SubField/SubIndex chain */
def mergeRef(root: Expression, body: Expression): Expression = body match {
case e: WRef =>
- WSubField(root, e.name, e.tpe, e.gender)
+ WSubField(root, e.name, e.tpe, e.flow)
case e: WSubIndex =>
- WSubIndex(mergeRef(root, e.expr), e.value, e.tpe, e.gender)
+ WSubIndex(mergeRef(root, e.expr), e.value, e.tpe, e.flow)
case e: WSubField =>
- WSubField(mergeRef(root, e.expr), e.name, e.tpe, e.gender)
+ WSubField(mergeRef(root, e.expr), e.name, e.tpe, e.flow)
case EmptyExpression => root
}