diff options
| author | Richard Lin | 2018-02-02 23:30:56 -0800 |
|---|---|---|
| committer | GitHub | 2018-02-02 23:30:56 -0800 |
| commit | 1bfca502c69a26edca86d716a1ca9d24e6789e59 (patch) | |
| tree | a5c035ee45c3cd66e2d9b63c74aca75575f78f83 | |
| parent | 639617ea42c777b8dd1f4300d42784e45f294d76 (diff) | |
Autoclonetype will clone args that are of type data (#768)
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala | 6 | ||||
| -rw-r--r-- | src/main/scala/chisel3/util/Arbiter.scala | 4 | ||||
| -rw-r--r-- | src/main/scala/chisel3/util/Decoupled.scala | 10 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/AutoClonetypeSpec.scala | 11 |
4 files changed, 22 insertions, 9 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala index e45f6d72..6a2e68e0 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala @@ -702,7 +702,11 @@ class Bundle(implicit compileOptions: CompileOptions) extends Record { " Use chisel types instead: use the value before it is turned to a hardware type (with Wire(...), Reg(...), etc) or use chiselTypeOf(...) to extract the chisel type.") } - val ctorParamsVals = ctorParamsNameVals.map{ case (_, paramVal) => paramVal } + // Clone unbound parameters in case they are being used as bundle fields. + val ctorParamsVals = ctorParamsNameVals.map { + case (_, paramVal: Data) => paramVal.cloneTypeFull + case (_, paramVal) => paramVal + } // Invoke ctor val classMirror = outerClassInstance match { diff --git a/src/main/scala/chisel3/util/Arbiter.scala b/src/main/scala/chisel3/util/Arbiter.scala index ba257b41..623dd619 100644 --- a/src/main/scala/chisel3/util/Arbiter.scala +++ b/src/main/scala/chisel3/util/Arbiter.scala @@ -14,7 +14,9 @@ import chisel3.internal.naming.chiselName // can't use chisel3_ version because * @param gen data type * @param n number of inputs */ -class ArbiterIO[T <: Data](gen: T, n: Int) extends Bundle { +class ArbiterIO[T <: Data](private val gen: T, val n: Int) extends Bundle { + // See github.com/freechipsproject/chisel3/issues/765 for why gen is a private val and proposed replacement APIs. + val in = Flipped(Vec(n, Decoupled(gen))) val out = Decoupled(gen) val chosen = Output(UInt(log2Ceil(n).W)) diff --git a/src/main/scala/chisel3/util/Decoupled.scala b/src/main/scala/chisel3/util/Decoupled.scala index bcd65a1b..d2419325 100644 --- a/src/main/scala/chisel3/util/Decoupled.scala +++ b/src/main/scala/chisel3/util/Decoupled.scala @@ -101,9 +101,6 @@ object Decoupled irr.ready := d.ready d } -// override def cloneType: this.type = { -// DeqIO(gen).asInstanceOf[this.type] -// } } /** A concrete subclass of ReadyValidIO that promises to not change @@ -154,8 +151,9 @@ object DeqIO { * @param gen The type of data to queue * @param entries The max number of entries in the queue. */ -class QueueIO[T <: Data](gen: T, entries: Int) extends Bundle -{ +class QueueIO[T <: Data](private val gen: T, val entries: Int) extends Bundle +{ // See github.com/freechipsproject/chisel3/issues/765 for why gen is a private val and proposed replacement APIs. + /* These may look inverted, because the names (enq/deq) are from the perspective of the client, * but internally, the queue implementation itself sits on the other side * of the interface so uses the flipped instance. @@ -166,8 +164,6 @@ class QueueIO[T <: Data](gen: T, entries: Int) extends Bundle val deq = Flipped(DeqIO(gen)) /** The current amount of data in the queue */ val count = Output(UInt(log2Ceil(entries + 1).W)) - - override def cloneType = new QueueIO(gen, entries).asInstanceOf[this.type] } /** A hardware module implementing a Queue diff --git a/src/test/scala/chiselTests/AutoClonetypeSpec.scala b/src/test/scala/chiselTests/AutoClonetypeSpec.scala index 1170ed12..0b02c3ab 100644 --- a/src/test/scala/chiselTests/AutoClonetypeSpec.scala +++ b/src/test/scala/chiselTests/AutoClonetypeSpec.scala @@ -47,6 +47,9 @@ class ModuleWithInner extends Module { require(myWire.i == 14) } +// A Bundle with an argument that is also a field. +// Not necessarily good style (and not necessarily recommended), but allowed to preserve compatibility. +class BundleWithArgumentField(val x: Data, val y: Data) extends Bundle class AutoClonetypeSpec extends ChiselFlatSpec { "Bundles with Scala args" should "not need clonetype" in { @@ -112,4 +115,12 @@ class AutoClonetypeSpec extends ChiselFlatSpec { "Inner bundles with Scala args" should "not need clonetype" in { elaborate { new ModuleWithInner } } + + "Bundles with arguments as fields" should "not need clonetype" in { + elaborate { new Module { + val io = IO(Output(new BundleWithArgumentField(UInt(8.W), UInt(8.W)))) + io.x := 1.U + io.y := 1.U + } } + } } |
