diff options
| author | Angie | 2017-02-22 20:03:27 -0800 |
|---|---|---|
| committer | Adam Izraelevitz | 2017-02-23 14:55:00 -0800 |
| commit | 1f9fd2f9b9e9a0117b0dd65524c9dcb767c02778 (patch) | |
| tree | b4ef1d8fdadd89e942e321cf4495a127cb9bfe59 /src/main/scala/firrtl/passes/memlib/MemUtils.scala | |
| parent | 1d652352b752502dd6d130aeb85981df214d7021 (diff) | |
move more general utils out of memutils, mov WIR helpers to WIR.scala and update uses
Diffstat (limited to 'src/main/scala/firrtl/passes/memlib/MemUtils.scala')
| -rw-r--r-- | src/main/scala/firrtl/passes/memlib/MemUtils.scala | 118 |
1 files changed, 0 insertions, 118 deletions
diff --git a/src/main/scala/firrtl/passes/memlib/MemUtils.scala b/src/main/scala/firrtl/passes/memlib/MemUtils.scala index c7eb4539..40f81555 100644 --- a/src/main/scala/firrtl/passes/memlib/MemUtils.scala +++ b/src/main/scala/firrtl/passes/memlib/MemUtils.scala @@ -7,35 +7,6 @@ import firrtl.ir._ import firrtl.Utils._ import firrtl.PrimOps._ -object seqCat { - def apply(args: Seq[Expression]): Expression = args.length match { - case 0 => error("Empty Seq passed to seqcat") - case 1 => args.head - case 2 => DoPrim(PrimOps.Cat, args, Nil, UIntType(UnknownWidth)) - case _ => - val (high, low) = args splitAt (args.length / 2) - DoPrim(PrimOps.Cat, Seq(seqCat(high), seqCat(low)), Nil, UIntType(UnknownWidth)) - } -} - -/** Given an expression, return an expression consisting of all sub-expressions - * concatenated (or flattened). - */ -object toBits { - def apply(e: Expression): Expression = e match { - case ex @ (_: WRef | _: WSubField | _: WSubIndex) => hiercat(ex) - case t => error("Invalid operand expression for 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)))) - case t: BundleType => seqCat(t.fields map (f => - hiercat(WSubField(e, f.name, f.tpe, UNKNOWNGENDER)))) - case t: GroundType => DoPrim(AsUInt, Seq(e), Seq.empty, UnknownType) - case t => error("Unknown type encountered in toBits!") - } -} - /** Given a mask, return a bitmask corresponding to the desired datatype. * Requirements: * - The mask type and datatype must be equivalent, except any ground type in @@ -71,74 +42,6 @@ object toBitMask { } } -object getWidth { - def apply(t: Type): Width = t match { - case t: GroundType => t.width - case _ => error("No width!") - } - def apply(e: Expression): Width = apply(e.tpe) -} - -object bitWidth { - def apply(dt: Type): BigInt = widthOf(dt) - private def widthOf(dt: Type): BigInt = dt match { - case t: VectorType => t.size * bitWidth(t.tpe) - case t: BundleType => t.fields.map(f => bitWidth(f.tpe)).foldLeft(BigInt(0))(_+_) - case GroundType(IntWidth(width)) => width - case t => error("Unknown type encountered in bitWidth!") - } -} - -object castRhs { - def apply(lhst: Type, rhs: Expression) = { - lhst match { - case _: SIntType => DoPrim(AsSInt, Seq(rhs), Seq.empty, lhst) - case FixedType(_, IntWidth(p)) => DoPrim(AsFixedPoint, Seq(rhs), Seq(p), lhst) - case ClockType => DoPrim(AsClock, Seq(rhs), Seq.empty, lhst) - case _: UIntType => rhs - } - } -} - -object fromBits { - def apply(lhs: Expression, rhs: Expression): Statement = { - val fbits = lhs match { - case ex @ (_: WRef | _: WSubField | _: WSubIndex) => getPart(ex, ex.tpe, rhs, 0) - case _ => error("Invalid LHS expression for fromBits!") - } - Block(fbits._2) - } - private def getPartGround(lhs: Expression, - lhst: Type, - rhs: Expression, - offset: BigInt): (BigInt, Seq[Statement]) = { - val intWidth = bitWidth(lhst) - val sel = DoPrim(PrimOps.Bits, Seq(rhs), Seq(offset + intWidth - 1, offset), UnknownType) - val rhsConnect = castRhs(lhst, sel) - (offset + intWidth, Seq(Connect(NoInfo, lhs, rhsConnect))) - } - private def getPart(lhs: Expression, - lhst: Type, - rhs: Expression, - offset: BigInt): (BigInt, Seq[Statement]) = - 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 (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 (tmpOffset, substmts) = getPart(subfield, f.tpe, rhs, curOffset) - (tmpOffset, stmts ++ substmts) - } - case t: GroundType => getPartGround(lhs, t, rhs, offset) - case t => error("Unknown type encountered in fromBits!") - } -} - object createMask { def apply(dt: Type): Type = dt match { case t: VectorType => VectorType(apply(t.tpe), t.size) @@ -147,27 +50,6 @@ object createMask { } } -object createRef { - def apply(n: String, t: Type = UnknownType, k: Kind = ExpKind) = WRef(n, t, k, UNKNOWNGENDER) -} - -object createSubField { - def apply(exp: Expression, n: String) = WSubField(exp, n, field_type(exp.tpe, n), UNKNOWNGENDER) -} - -object createInstance { - def apply(name: String, module: String) = WDefInstance(NoInfo, name, module, UnknownType) -} - -object connectFields { - def apply(lref: Expression, lname: String, rref: Expression, rname: String): Connect = - Connect(NoInfo, createSubField(lref, lname), createSubField(rref, rname)) -} - -object flattenType { - def apply(t: Type) = UIntType(IntWidth(bitWidth(t))) -} - object MemPortUtils { type MemPortMap = collection.mutable.HashMap[String, Expression] type Memories = collection.mutable.ArrayBuffer[DefMemory] |
