diff options
| author | Andrew Waterman | 2015-07-24 19:00:29 -0700 |
|---|---|---|
| committer | Andrew Waterman | 2015-07-24 19:00:29 -0700 |
| commit | 54c57837d357af7d629bfe591b55fe645cd0ca9d (patch) | |
| tree | d84cde66d2c509347d4c53cb7f61fd8099eebad8 /src | |
| parent | 90cf2623a3491c5b5bc076e2e9f8c84a3e9aa86d (diff) | |
Undo doCloneType; fix collectElts shenanigans
We now call collectElts when the module stack is popped,
rather than having to do it all over the place.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/Chisel/Core.scala | 79 | ||||
| -rw-r--r-- | src/main/scala/Chisel/FP.scala | 4 | ||||
| -rw-r--r-- | src/main/scala/Chisel/utils.scala | 20 | ||||
| -rw-r--r-- | src/test/scala/ChiselTests/ComplexAssign.scala | 2 |
4 files changed, 39 insertions, 66 deletions
diff --git a/src/main/scala/Chisel/Core.scala b/src/main/scala/Chisel/Core.scala index ad5ab8da..94f97468 100644 --- a/src/main/scala/Chisel/Core.scala +++ b/src/main/scala/Chisel/Core.scala @@ -297,7 +297,9 @@ object debug { } abstract class Data(dirArg: Direction) extends Id { - val mod = getComponent() + private[Chisel] val mod = getComponent() + mod._nodes += this + def toType: Kind var isFlipVar = dirArg == INPUT def isFlip = isFlipVar @@ -305,7 +307,6 @@ abstract class Data(dirArg: Direction) extends Id { def setDir(dir: Direction) { isFlipVar = (dir == INPUT) } - def init(dummy:Int = 0) = { } def asInput: this.type = { setDir(INPUT) this @@ -322,13 +323,8 @@ abstract class Data(dirArg: Direction) extends Id { pushCommand(Connect(this.lref, other.ref)) def <>(other: Data) = pushCommand(BulkConnect(this.lref, other.lref)) - final def cloneType: this.type = { - val res = doCloneType - collectElts - res - } - def collectElts = { } - def doCloneType: this.type + private[Chisel] def collectElts = { } + def cloneType: this.type def cloneTypeWidth(width: Int): this.type def lref: Alias = Alias(cid) @@ -484,13 +480,10 @@ class Vec[T <: Data](elts: Iterable[T], dirArg: Direction = NO_DIR) extends Aggr private val self = elts.toIndexedSeq private val elt0 = elts.head - // println("BEGIN VEC NAMING " + this) - for ((e, i) <- self zipWithIndex) { - // println(" NAME " + i + " -> " + cid) - e.collectElts - setIndexForId(cid, e.cid, i) + override def collectElts = { + for ((e, i) <- self zipWithIndex) + setIndexForId(cid, e.cid, i) } - // println("DONE VEC NAMING " + this) def <> (that: Iterable[T]): Unit = this <> Vec(that).asInstanceOf[Data] @@ -512,19 +505,8 @@ class Vec[T <: Data](elts: Iterable[T], dirArg: Direction = NO_DIR) extends Aggr self.map(d => d.toPort).toArray def toType: Kind = VectorType(self.size, elt0.toType, isFlipVar) - override def doCloneType: this.type = + override def cloneType: this.type = Vec(elt0.cloneType, self.size).asInstanceOf[this.type] - override def init(dummy:Int = 0) = - for (e <- self) e.init() - def inits (f: (Int, T, (Int, T, T) => Unit) => Unit) = { - var i = 0 - def doInit (index: Int, elt: T, init: T) = - pushCommand(ConnectInitIndex(elt.lref, index, init.ref)) - for (d <- self) { - f(i, d, doInit) - i += 1; - } - } override def flatten: IndexedSeq[Bits] = self.map(_.flatten).reduce(_ ++ _) @@ -568,7 +550,7 @@ class BitPat(val value: String, val width: Int) extends Data(NO_DIR) { override def toType: Kind = UIntType(UnknownWidth(), isFlip) override def getWidth: Int = width override def flatten: IndexedSeq[Bits] = throw new Exception("BitPat.flatten") - override def doCloneType: this.type = + override def cloneType: this.type = new BitPat(value, width).asInstanceOf[this.type] def fromInt(x: BigInt): BitPat = BitPat(x.toString(2), -1).asInstanceOf[this.type] val (bits, mask, swidth) = parseLit(value) @@ -598,7 +580,7 @@ abstract class Bits(dirArg: Direction, width: Int) extends Element(dirArg, width override def isLitValue(): Boolean = litValueVar.isDefined override def litValue(): BigInt = if (isLitValue) litValueVar.get.num else -1 override def setLitValue(x: LitArg) { litValueVar = Some(x) } - override def doCloneType : this.type = cloneTypeWidth(width) + override def cloneType : this.type = cloneTypeWidth(width) def fromInt(x: BigInt): this.type = makeLit(x, -1) override def flatten: IndexedSeq[Bits] = IndexedSeq(this) @@ -957,7 +939,7 @@ object Cat { object Bundle { val keywords = HashSet[String]("elements", "flip", "toString", "flatten", "binding", "asInput", "asOutput", "unary_$tilde", - "unary_$bang", "unary_$minus", "cloneType", "doCloneType", "clone", + "unary_$bang", "unary_$minus", "cloneType", "clone", "toUInt", "toBits", "toBool", "toSInt", "asDirectionless") def apply[T <: Bundle](b: => T)(implicit p: Parameters): T = { @@ -979,41 +961,33 @@ class Bundle(dirArg: Direction = NO_DIR) extends Aggregate(dirArg) { def toType: BundleType = BundleType(this.toPorts, isFlipVar) - override def flatten: IndexedSeq[Bits] = { - val sortedElts = elements.values.toIndexedSeq sortWith (_._id < _._id) - sortedElts.map(_.flatten).reduce(_ ++ _) - } + override def flatten: IndexedSeq[Bits] = + sortedElts.map(_._2.flatten).reduce(_ ++ _) - override def init(dummy:Int = 0) = - for ((s, e) <- elements) e.init() lazy val elements: LinkedHashMap[String, Data] = { val elts = LinkedHashMap[String, Data]() - // println("BEGIN BUNDLE NAMING " + cid) for (m <- getClass.getMethods) { val name = m.getName - // println("NAME = " + name) val rtype = m.getReturnType val isInterface = classOf[Data].isAssignableFrom(rtype) if (m.getParameterTypes.isEmpty && !isStatic(m.getModifiers) && isInterface && !(Bundle.keywords contains name)) { - val obj = m.invoke(this) - obj match { - case data: Data => - // println(" NAMING " + name + " -> " + cid) - setFieldForId(cid, data.cid, name) - elts(name) = data - case _ => () + m.invoke(this) match { + case data: Data => elts(name) = data + case _ => } } } - // println("DONE BUNDLE NAMING " + cid) elts } - override def collectElts = elements + private lazy val sortedElts = + elements.toIndexedSeq sortWith (_._2._id < _._2._id) + override def collectElts = + sortedElts.foreach(e => setFieldForId(cid, e._2.cid, e._1)) - override def doCloneType : this.type = { + override def cloneType : this.type = { try { val constructor = this.getClass.getConstructors.head val res = constructor.newInstance(Array.fill(constructor.getParameterTypes.size)(null):_*) @@ -1055,13 +1029,15 @@ object Module { } abstract class Module(private[Chisel] _reset: Bool = null) extends Id { - val parent = modulez.headOption + private[Chisel] val _parent = modulez.headOption + private[Chisel] val _nodes = ArrayBuffer[Data]() + pushModule(this) pushScope pushCommands addModule(this) - lazy val params = Module.params + val params = Module.params params.path = this.getClass :: params.path def io: Bundle @@ -1075,12 +1051,13 @@ abstract class Module(private[Chisel] _reset: Bool = null) extends Id { getClass.getName.split('.').last } def debugName: String = { - val p = parent.getOrElse(null) + val p = _parent.getOrElse(null) val pname = if (p == null) "" else (p.debugName + ".") pname + getRefForId(cid).debugName } def setRefs { + _nodes.foreach(_.collectElts) setRefForId(io.cid, "this") for (m <- getClass.getDeclaredMethods) { diff --git a/src/main/scala/Chisel/FP.scala b/src/main/scala/Chisel/FP.scala index c22ee475..f7bbaae5 100644 --- a/src/main/scala/Chisel/FP.scala +++ b/src/main/scala/Chisel/FP.scala @@ -93,7 +93,7 @@ class Flo(dir: Direction = NO_DIR, val value:Option[Float] = None) extends Eleme d } def toType: Kind = FloType(isFlip) - def doCloneType: this.type = new Flo(dir).asInstanceOf[this.type] + def cloneType: this.type = new Flo(dir).asInstanceOf[this.type] def flatten: IndexedSeq[Bits] = IndexedSeq(toBits) def fromInt(x: Int): Flo = @@ -208,7 +208,7 @@ class Dbl(dir: Direction, val value: Option[Double] = None) extends Element(dir, d } def toType: Kind = DblType(isFlip) - def doCloneType: this.type = new Dbl(dir).asInstanceOf[this.type] + def cloneType: this.type = new Dbl(dir).asInstanceOf[this.type] def flatten: IndexedSeq[Bits] = IndexedSeq(toBits) def fromInt(x: Int): this.type = diff --git a/src/main/scala/Chisel/utils.scala b/src/main/scala/Chisel/utils.scala index 3bbea34a..7f9811fd 100644 --- a/src/main/scala/Chisel/utils.scala +++ b/src/main/scala/Chisel/utils.scala @@ -280,7 +280,7 @@ class ValidIO[+T <: Data](gen2: T) extends Bundle val valid = Bool(OUTPUT) val bits = gen2.cloneType.asOutput def fire(dummy: Int = 0): Bool = valid - override def doCloneType: this.type = new ValidIO(gen2).asInstanceOf[this.type] + override def cloneType: this.type = new ValidIO(gen2).asInstanceOf[this.type] } /** Adds a valid protocol to any interface. The standard used is @@ -296,7 +296,7 @@ class DecoupledIO[+T <: Data](gen: T) extends Bundle val valid = Bool(OUTPUT) val bits = gen.cloneType.asOutput def fire(dummy: Int = 0): Bool = ready && valid - override def doCloneType: this.type = new DecoupledIO(gen).asInstanceOf[this.type] + override def cloneType: this.type = new DecoupledIO(gen).asInstanceOf[this.type] } /** Adds a ready-valid handshaking protocol to any interface. @@ -310,22 +310,18 @@ object Decoupled { class EnqIO[T <: Data](gen: T) extends DecoupledIO(gen) { def enq(dat: T): T = { valid := Bool(true); bits := dat; dat } - override def init(dummy: Int = 0) = { - valid := Bool(false); - for (io <- bits.flatten) - io := UInt(0) - } - override def doCloneType: this.type = { new EnqIO(gen).asInstanceOf[this.type]; } + valid := Bool(false) + for (io <- bits.flatten) + io := UInt(0) + override def cloneType: this.type = { new EnqIO(gen).asInstanceOf[this.type]; } } class DeqIO[T <: Data](gen: T) extends DecoupledIO(gen) { flip() - override def init(dummy: Int = 0) = { - ready := Bool(false) - } + ready := Bool(false) def deq(b: Boolean = false): T = { ready := Bool(true); bits } - override def doCloneType: this.type = { new DeqIO(gen).asInstanceOf[this.type]; } + override def cloneType: this.type = { new DeqIO(gen).asInstanceOf[this.type]; } } diff --git a/src/test/scala/ChiselTests/ComplexAssign.scala b/src/test/scala/ChiselTests/ComplexAssign.scala index fb335aed..bcc49543 100644 --- a/src/test/scala/ChiselTests/ComplexAssign.scala +++ b/src/test/scala/ChiselTests/ComplexAssign.scala @@ -3,7 +3,7 @@ import Chisel._ class Complex[T <: Data](val re: T, val im: T, dir: Direction = OUTPUT) extends Bundle(dir) { - override def doCloneType: this.type = + override def cloneType: this.type = new Complex(re.cloneType, im.cloneType, dir).asInstanceOf[this.type] } |
