@@ -4,6 +4,7 @@ package chisel3
44
55import chisel3 .experimental .dataview .reify
66
7+ import chisel3 .Data .DataExtensions
78import chisel3 .experimental .{requireIsChiselType , requireIsHardware , Analog , BaseModule }
89import chisel3 .experimental .{prefix , SourceInfo , UnlocatableSourceInfo }
910import chisel3 .experimental .dataview .{reifyIdentityView , reifySingleTarget , DataViewable }
@@ -781,28 +782,12 @@ private[chisel3] trait DataImpl extends HasId with NamedComponent { self: Data =
781782 private [chisel3] def width : Width
782783 private [chisel3] def firrtlConnect (that : Data )(implicit sourceInfo : SourceInfo ): Unit
783784
784- /** Internal API; Chisel users should look at chisel3.chiselTypeOf(...).
785+ /** Private implementation of cloneType
785786 *
786- * cloneType must be defined for any Chisel object extending Data.
787- * It is responsible for constructing a basic copy of the object being cloned.
788- *
789- * @return a copy of the object.
790- */
791- def cloneType : this .type
792-
793- /** Internal API; Chisel users should look at chisel3.chiselTypeOf(...).
794- *
795- * Returns a copy of this data type, with hardware bindings (if any) removed.
796- * Directionality data and probe information is still preserved.
787+ * _cloneType must be defined for any Chisel object extending Data.
788+ * It is implemented by Chisel itself or by the compiler plugin for user-defined types.
797789 */
798- private [chisel3] def cloneTypeFull : this .type = {
799- val clone = this .cloneType // get a fresh object, without bindings
800- // Only the top-level direction needs to be fixed up, cloneType should do the rest
801- clone.specifiedDirection = specifiedDirection
802- probe.setProbeModifier(clone, probeInfo)
803- clone.isConst = isConst
804- clone
805- }
790+ def _cloneType : Data
806791
807792 /** The "strong connect" operator.
808793 *
@@ -994,6 +979,7 @@ private[chisel3] trait ObjectDataImpl {
994979 *
995980 * @param lhs The [[Data ]] hardware on the left-hand side of the equality
996981 */
982+ // TODO fold this into DataExtensions
997983 implicit class DataEquality [T <: Data ](lhs : T )(implicit sourceInfo : SourceInfo ) {
998984
999985 /** Dynamic recursive equality operator for generic [[Data ]]
@@ -1072,6 +1058,33 @@ private[chisel3] trait ObjectDataImpl {
10721058 }
10731059 }
10741060 }
1061+
1062+ implicit class DataExtensions [T <: Data ](self : T ) {
1063+
1064+ /** Internal API; Chisel users should look at chisel3.chiselTypeOf(...).
1065+ *
1066+ * cloneType must be defined for any Chisel object extending Data.
1067+ * It is responsible for constructing a basic copy of the object being cloned.
1068+ *
1069+ * @return a copy of the object.
1070+ */
1071+ def cloneType : T = self._cloneType.asInstanceOf [T ]
1072+
1073+ /** Internal API; Chisel users should look at chisel3.chiselTypeOf(...).
1074+ *
1075+ * Returns a copy of this data type, with hardware bindings (if any) removed.
1076+ * Directionality data and probe information is still preserved.
1077+ */
1078+ private [chisel3] def cloneTypeFull : T = {
1079+ val clone = self.cloneType // get a fresh object, without bindings
1080+ // Only the top-level direction needs to be fixed up, cloneType should do the rest
1081+ clone.specifiedDirection = self.specifiedDirection
1082+ // TODO do we need to exclude probe and const from cloneTypeFull on Properties?
1083+ probe.setProbeModifier(clone, self.probeInfo)
1084+ clone.isConst = self.isConst
1085+ clone.asInstanceOf [T ]
1086+ }
1087+ }
10751088}
10761089
10771090trait WireFactory {
@@ -1243,7 +1256,8 @@ final case object DontCare extends Element with connectable.ConnectableDocs {
12431256 private [chisel3] override val width : Width = UnknownWidth
12441257
12451258 bind(DontCareBinding (), SpecifiedDirection .Output )
1246- override def cloneType : this .type = DontCare
1259+
1260+ override def _cloneType : Data = DontCare
12471261
12481262 override def toString : String = " DontCare()"
12491263
0 commit comments