Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DataMirror.internal.chiselTypeClone to preserve Scala type #3553

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/main/scala/chisel3/reflect/DataMirror.scala
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ object DataMirror {
object internal {
def isSynthesizable(target: Data): Boolean = target.isSynthesizable
// For those odd cases where you need to care about object reference and uniqueness
def chiselTypeClone[T <: Data](target: Data): T = {
target.cloneTypeFull.asInstanceOf[T]
def chiselTypeClone[T <: Data](target: T): T = {
target.cloneTypeFull
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/scala/chiselTests/reflect/DataMirrorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,15 @@ class DataMirrorSpec extends ChiselFlatSpec {
it should "not support name guesses for non-hardware" in {
an[ExpectedHardwareException] should be thrownBy DataMirror.queryNameGuess(UInt(8.W))
}

"chiselTypeClone" should "preserve Scala type information" in {
class MyModule extends Module {
val in = IO(Input(UInt(8.W)))
val out = IO(Output(DataMirror.internal.chiselTypeClone(in)))
// The connection checks the types
out :#= in
}
ChiselStage.emitCHIRRTL(new MyModule)
}

}
Loading