summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala18
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Bits.scala6
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Data.scala24
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Mem.scala6
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Reg.scala4
-rw-r--r--src/main/scala/chisel3/util/Decoupled.scala8
-rw-r--r--src/main/scala/chisel3/util/Reg.scala4
-rw-r--r--src/main/scala/chisel3/util/Valid.scala8
-rw-r--r--src/test/scala/chiselTests/ComplexAssign.scala2
-rw-r--r--src/test/scala/chiselTests/Module.scala2
10 files changed, 34 insertions, 48 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
index a80dfec8..7707d906 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
@@ -24,10 +24,10 @@ object Vec {
*
* @note elements are NOT assigned by default and have no value
*/
- def apply[T <: Data](n: Int, gen: T): Vec[T] = new Vec(gen.cloneType, n)
+ def apply[T <: Data](n: Int, gen: T): Vec[T] = new Vec(gen, n)
@deprecated("Vec argument order should be size, t; this will be removed by the official release", "chisel3")
- def apply[T <: Data](gen: T, n: Int): Vec[T] = new Vec(gen.cloneType, n)
+ def apply[T <: Data](gen: T, n: Int): Vec[T] = new Vec(gen, n)
/** Creates a new [[Vec]] composed of elements of the input Seq of [[Data]]
* nodes.
@@ -104,12 +104,12 @@ object Vec {
* @note Vecs, unlike classes in Scala's collection library, are propagated
* intact to FIRRTL as a vector type, which may make debugging easier
*/
-sealed class Vec[T <: Data] private (gen: => T, val length: Int)
+sealed class Vec[T <: Data] private (gen: T, val length: Int)
extends Aggregate with VecLike[T] {
// Note: the constructor takes a gen() function instead of a Seq to enforce
// that all elements must be the same and because it makes FIRRTL generation
// simpler.
- private val self = IndexedSeq.fill(length)(gen)
+ private val self: Seq[T] = Vector.fill(length)(gen.chiselCloneType)
/**
* sample_element 'tracks' all changes to the elements of self.
@@ -118,7 +118,7 @@ sealed class Vec[T <: Data] private (gen: => T, val length: Int)
*
* Needed specifically for the case when the Vec is length 0.
*/
- private[core] val sample_element: T = gen
+ private[core] val sample_element: T = gen.chiselCloneType
// allElements current includes sample_element
// This is somewhat weird although I think the best course of action here is
@@ -157,7 +157,7 @@ sealed class Vec[T <: Data] private (gen: => T, val length: Int)
*/
def apply(idx: UInt): T = {
Binding.checkSynthesizable(idx ,s"'idx' ($idx)")
- val port = sample_element.cloneType
+ val port = sample_element.chiselCloneType
port.setRef(this, idx) //TODO(twigg): This is a bit too magical
// Bind each element of port to being whatever the base type is
@@ -180,9 +180,7 @@ sealed class Vec[T <: Data] private (gen: => T, val length: Int)
def write(idx: UInt, data: T): Unit = apply(idx).:=(data)(DeprecatedSourceInfo)
override def cloneType: this.type = {
- val clone = Vec(length, gen).asInstanceOf[this.type]
- clone.unBind()
- clone
+ Vec(length, gen).asInstanceOf[this.type]
}
private[chisel3] def toType: String = s"${sample_element.toType}[$length]"
@@ -390,5 +388,5 @@ class Bundle extends Aggregate {
}
private[core] object Bundle {
- val keywords = List("flip", "asInput", "asOutput", "cloneType", "toBits")
+ val keywords = List("flip", "asInput", "asOutput", "cloneType", "toBits", "chiselCloneType")
}
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
index ee0acd86..07c113fd 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
@@ -51,11 +51,7 @@ sealed abstract class Bits(width: Width, override val litArg: Option[LitArg])
private[chisel3] def flatten: IndexedSeq[Bits] = IndexedSeq(this)
- def cloneType: this.type = {
- val clone = cloneTypeWidth(width)
- clone.unBind()
- clone
- }
+ def cloneType: this.type = cloneTypeWidth(width)
final def tail(n: Int): UInt = macro SourceInfoTransform.nArg
final def head(n: Int): UInt = macro SourceInfoTransform.nArg
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Data.scala b/chiselFrontend/src/main/scala/chisel3/core/Data.scala
index 79119114..fee5c01c 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Data.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Data.scala
@@ -120,6 +120,15 @@ abstract class Data extends HasId {
private[chisel3] def toType: String
def cloneType: this.type
+ def chiselCloneType: this.type = {
+ // Call the user-supplied cloneType method
+ val clone = this.cloneType
+ //TODO(twigg): Do recursively for better error messages
+ for((clone_elem, source_elem) <- clone.allElements zip this.allElements) {
+ clone_elem.binding = UnboundBinding(source_elem.binding.direction)
+ }
+ clone
+ }
final def := (that: Data)(implicit sourceInfo: SourceInfo): Unit = this connect that
final def <> (that: Data)(implicit sourceInfo: SourceInfo): Unit = this bulkConnect that
def litArg(): Option[LitArg] = None
@@ -154,7 +163,7 @@ abstract class Data extends HasId {
def do_fromBits(that: Bits)(implicit sourceInfo: SourceInfo): this.type = {
var i = 0
- val wire = Wire(this.cloneType)
+ val wire = Wire(this.chiselCloneType)
val bits =
if (that.width.known && that.width.get >= wire.width.get) {
that
@@ -174,13 +183,6 @@ abstract class Data extends HasId {
*/
@deprecated("Use asBits, which makes the reinterpret cast more explicit and actually returns Bits", "chisel3")
def toBits(): UInt = SeqUtils.do_asUInt(this.flatten)(DeprecatedSourceInfo)
-
- protected def unBind(): Unit = {
- //TODO(twigg): Do recursively for better error messages
- for(elem <- this.allElements) {
- elem.binding = UnboundBinding(elem.binding.direction)
- }
- }
}
object Wire {
@@ -217,11 +219,7 @@ object Clock {
// TODO: Document this.
sealed class Clock extends Element(Width(1)) {
- def cloneType: this.type = {
- val clone = Clock().asInstanceOf[this.type]
- clone.unBind()
- clone
- }
+ def cloneType: this.type = Clock().asInstanceOf[this.type]
private[chisel3] override def flatten: IndexedSeq[Bits] = IndexedSeq()
private[chisel3] def cloneTypeWidth(width: Width): this.type = cloneType
private[chisel3] def toType = "Clock"
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Mem.scala b/chiselFrontend/src/main/scala/chisel3/core/Mem.scala
index a4e6bee3..fd0897a2 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Mem.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Mem.scala
@@ -20,7 +20,7 @@ object Mem {
*/
def apply[T <: Data](size: Int, t: T): Mem[T] = macro MemTransform.apply[T]
def do_apply[T <: Data](size: Int, t: T)(implicit sourceInfo: SourceInfo): Mem[T] = {
- val mt = t.cloneType
+ val mt = t.chiselCloneType
Binding.bind(mt, NoDirectionBinder, "Error: fresh t")
// TODO(twigg): Remove need for this Binding
@@ -86,7 +86,7 @@ sealed abstract class MemBase[T <: Data](t: T, val length: Int) extends HasId wi
val port = pushCommand(
DefMemPort(sourceInfo,
- t.cloneType, Node(this), dir, idx.ref, Node(idx._parent.get.clock))
+ t.chiselCloneType, Node(this), dir, idx.ref, Node(idx._parent.get.clock))
).id
// Bind each element of port to being a MemoryPort
Binding.bind(port, MemoryPortBinder(Builder.forcedModule), "Error: Fresh t")
@@ -117,7 +117,7 @@ object SeqMem {
def apply[T <: Data](size: Int, t: T): SeqMem[T] = macro MemTransform.apply[T]
def do_apply[T <: Data](size: Int, t: T)(implicit sourceInfo: SourceInfo): SeqMem[T] = {
- val mt = t.cloneType
+ val mt = t.chiselCloneType
Binding.bind(mt, NoDirectionBinder, "Error: fresh t")
// TODO(twigg): Remove need for this Binding
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Reg.scala b/chiselFrontend/src/main/scala/chisel3/core/Reg.scala
index e0607520..c1693531 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Reg.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Reg.scala
@@ -12,13 +12,13 @@ object Reg {
init: T = null): T = {
if (t ne null) {
Binding.checkUnbound(t, s"t ($t) must be unbound Type. Try using cloneType?")
- t.cloneType
+ t.chiselCloneType
} else if (next ne null) {
next.cloneTypeWidth(Width())
} else if (init ne null) {
init.litArg match {
// For e.g. Reg(init=UInt(0, k)), fix the Reg's width to k
- case Some(lit) if lit.forcedWidth => init.cloneType
+ case Some(lit) if lit.forcedWidth => init.chiselCloneType
case _ => init.cloneTypeWidth(Width())
}
} else {
diff --git a/src/main/scala/chisel3/util/Decoupled.scala b/src/main/scala/chisel3/util/Decoupled.scala
index 037f9a22..76bf4842 100644
--- a/src/main/scala/chisel3/util/Decoupled.scala
+++ b/src/main/scala/chisel3/util/Decoupled.scala
@@ -12,7 +12,7 @@ class DecoupledIO[+T <: Data](gen: T) extends Bundle
{
val ready = Input(Bool())
val valid = Output(Bool())
- val bits = Output(gen.cloneType)
+ val bits = Output(gen.chiselCloneType)
override def cloneType: this.type = DecoupledIO(gen).asInstanceOf[this.type]
}
@@ -59,9 +59,7 @@ object DecoupledIO {
}
}
// override def cloneType: this.type = {
-// val clone = DeqIO(gen).asInstanceOf[this.type]
-// clone.unBind()
-// clone
+// DeqIO(gen).asInstanceOf[this.type]
// }
}
@@ -171,7 +169,7 @@ extends Module(override_reset=override_reset) {
object Queue
{
def apply[T <: Data](enq: DecoupledIO[T], entries: Int = 2, pipe: Boolean = false): DecoupledIO[T] = {
- val q = Module(new Queue(enq.bits.cloneType, entries, pipe))
+ val q = Module(new Queue(enq.bits.chiselCloneType, entries, pipe))
q.io.enq.valid := enq.valid // not using <> so that override is allowed
q.io.enq.bits := enq.bits
enq.ready := q.io.enq.ready
diff --git a/src/main/scala/chisel3/util/Reg.scala b/src/main/scala/chisel3/util/Reg.scala
index 81de4754..f77a9667 100644
--- a/src/main/scala/chisel3/util/Reg.scala
+++ b/src/main/scala/chisel3/util/Reg.scala
@@ -26,12 +26,12 @@ object RegEnable
{
def apply[T <: Data](updateData: T, enable: Bool): T = {
val r = Reg(updateData)
- when (enable) { r := updateData }
+ when (enable) { r := updateData.chiselCloneType }
r
}
def apply[T <: Data](updateData: T, resetData: T, enable: Bool): T = {
val r = RegInit(resetData)
- when (enable) { r := updateData }
+ when (enable) { r := updateData.chiselCloneType }
r
}
}
diff --git a/src/main/scala/chisel3/util/Valid.scala b/src/main/scala/chisel3/util/Valid.scala
index 5641f0f2..743038f3 100644
--- a/src/main/scala/chisel3/util/Valid.scala
+++ b/src/main/scala/chisel3/util/Valid.scala
@@ -11,13 +11,9 @@ import chisel3._
class Valid[+T <: Data](gen: T) extends Bundle
{
val valid = Output(Bool())
- val bits = Output(gen.cloneType)
+ val bits = Output(gen.chiselCloneType)
def fire(dummy: Int = 0): Bool = valid
- override def cloneType: this.type = {
- val clone = Valid(gen).asInstanceOf[this.type]
- clone.unBind()
- clone
- }
+ override def cloneType: this.type = Valid(gen).asInstanceOf[this.type]
}
/** Adds a valid protocol to any interface */
diff --git a/src/test/scala/chiselTests/ComplexAssign.scala b/src/test/scala/chiselTests/ComplexAssign.scala
index c5aaa554..fce2c602 100644
--- a/src/test/scala/chiselTests/ComplexAssign.scala
+++ b/src/test/scala/chiselTests/ComplexAssign.scala
@@ -11,7 +11,7 @@ import chisel3.util._
class Complex[T <: Data](val re: T, val im: T) extends Bundle {
override def cloneType: this.type =
- new Complex(re.cloneType, im.cloneType).asInstanceOf[this.type]
+ new Complex(re.chiselCloneType, im.chiselCloneType).asInstanceOf[this.type]
}
class ComplexAssign(w: Int) extends Module {
diff --git a/src/test/scala/chiselTests/Module.scala b/src/test/scala/chiselTests/Module.scala
index 59451a2b..26953f5f 100644
--- a/src/test/scala/chiselTests/Module.scala
+++ b/src/test/scala/chiselTests/Module.scala
@@ -41,7 +41,7 @@ class ModuleVecTester(c: ModuleVec) extends Tester(c) {
class ModuleWire extends Module {
val io = IO(new SimpleIO)
- val inc = Wire(Module(new PlusOne).io.cloneType)
+ val inc = Wire(Module(new PlusOne).io.chiselCloneType)
inc.in := io.in
io.out := inc.out
}