diff options
| author | Jim Lawson | 2016-10-06 10:50:58 -0700 |
|---|---|---|
| committer | GitHub | 2016-10-06 10:50:58 -0700 |
| commit | c9fe6005080f7695ff104253c1bf27388f749091 (patch) | |
| tree | 85041ff5e8f882311d1eddabd549f8d134f5e362 | |
| parent | 8251cbf93070b93a5db97b2d44db855b3c676b09 (diff) | |
| parent | a5aba40349e290c30280df25bc5b0ba848183469 (diff) | |
Merge pull request #307 from ucb-bar/clonefirrtldirection
clone firrtlDirection when cloning - Issue #306
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/Data.scala | 13 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/ComplexAssign.scala | 2 |
2 files changed, 14 insertions, 1 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Data.scala b/chiselFrontend/src/main/scala/chisel3/core/Data.scala index 4167be98..bd2e9065 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Data.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Data.scala @@ -173,7 +173,19 @@ abstract class Data extends HasId { private[core] def width: Width private[core] def legacyConnect(that: Data)(implicit sourceInfo: SourceInfo): Unit + /** cloneType must be defined for any Chisel object extending Data. + * It is responsible for constructing a basic copy of the object being cloned. + * If cloneType needs to recursively clone elements of an object, it should call + * the cloneType methods on those elements. + * @return a copy of the object. + */ def cloneType: this.type + + /** chiselCloneType is called at the top-level of a clone chain. + * It calls the client's cloneType() method to construct a basic copy of the object being cloned, + * then performs any fixups required to reconstruct the appropriate core state of the cloned object. + * @return a copy of the object with appropriate core state. + */ def chiselCloneType: this.type = { // Call the user-supplied cloneType method val clone = this.cloneType @@ -181,6 +193,7 @@ abstract class Data extends HasId { //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) + Data.setFirrtlDirection(clone_elem, Data.getFirrtlDirection(source_elem)) } clone } diff --git a/src/test/scala/chiselTests/ComplexAssign.scala b/src/test/scala/chiselTests/ComplexAssign.scala index 0a1f31cc..c5a23f82 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.chiselCloneType, im.chiselCloneType).asInstanceOf[this.type] + new Complex(re.cloneType, im.cloneType).asInstanceOf[this.type] } class ComplexAssign(w: Int) extends Module { |
