Skip to content

Commit

Permalink
Preserve probe-ness and const-ness in Output() and friends. (#3654)
Browse files Browse the repository at this point in the history
Using `Output()` shouldn't drop important type information,
only override the specified direction to force alignment.

Until #3647 is addressed, use `cloneTypeFull` to get the expected behavior.
The cloned direction information is unnecessary but is
overridden by the coerced direction.

cc #3647.

Co-authored-by: Jack Koenig <koenig@sifive.com>
  • Loading branch information
dtzSiFive and jackkoenig authored Jan 16, 2024
1 parent f6d65c5 commit f9b5d21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/scala/chisel3/Data.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object SpecifiedDirection {
val prevId = Builder.idGen.value
val data = source // evaluate source once (passed by name)
requireIsChiselType(data)
val out = if (!data.mustClone(prevId)) data else data.cloneType.asInstanceOf[T]
val out = if (!data.mustClone(prevId)) data else data.cloneTypeFull.asInstanceOf[T]
out.specifiedDirection = dir(data) // Must use original data, specified direction of clone is cleared
out
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/scala/chiselTests/Direction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,13 @@ class DirectionSpec extends ChiselPropSpec with Matchers with Utils {
)
)
}

property("Probe and const are preserved by Output()") {
class MyModule extends RawModule {
val tpe = probe.Probe(Const(Bool()))
val test = IO(Output(tpe))
}
val emitted: String = ChiselStage.emitCHIRRTL(new MyModule)
assert(emitted.contains("Probe<const UInt<1>>"))
}
}

0 comments on commit f9b5d21

Please sign in to comment.