Skip to content

Commit f9b5d21

Browse files
Preserve probe-ness and const-ness in Output() and friends. (#3654)
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>
1 parent f6d65c5 commit f9b5d21

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

core/src/main/scala/chisel3/Data.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ object SpecifiedDirection {
6565
val prevId = Builder.idGen.value
6666
val data = source // evaluate source once (passed by name)
6767
requireIsChiselType(data)
68-
val out = if (!data.mustClone(prevId)) data else data.cloneType.asInstanceOf[T]
68+
val out = if (!data.mustClone(prevId)) data else data.cloneTypeFull.asInstanceOf[T]
6969
out.specifiedDirection = dir(data) // Must use original data, specified direction of clone is cleared
7070
out
7171
}

src/test/scala/chiselTests/Direction.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,4 +550,13 @@ class DirectionSpec extends ChiselPropSpec with Matchers with Utils {
550550
)
551551
)
552552
}
553+
554+
property("Probe and const are preserved by Output()") {
555+
class MyModule extends RawModule {
556+
val tpe = probe.Probe(Const(Bool()))
557+
val test = IO(Output(tpe))
558+
}
559+
val emitted: String = ChiselStage.emitCHIRRTL(new MyModule)
560+
assert(emitted.contains("Probe<const UInt<1>>"))
561+
}
553562
}

0 commit comments

Comments
 (0)