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

Suppress exception throwing in Data.toString (backport #4147) #4153

Merged
merged 1 commit into from
Jun 7, 2024
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: 3 additions & 1 deletion core/src/main/scala/chisel3/Data.scala
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ abstract class Data extends HasId with NamedComponent with SourceInfoDoc {

private[chisel3] def stringAccessor(chiselType: String): String = {
// Trace views to give better error messages
val thiz = reifySingleData(this).getOrElse(this)
// Reifying involves checking against ViewParent which requires being in a Builder context
// Since we're just printing a String, suppress such errors and use this object
val thiz = Try(reifySingleData(this)).toOption.flatten.getOrElse(this)
thiz.topBindingOpt match {
case None => chiselType
// Handle DontCares specially as they are "literal-like" but not actually literals
Expand Down
32 changes: 14 additions & 18 deletions src/test/scala/chiselTests/DataPrint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,19 @@ class DataPrintSpec extends ChiselFlatSpec with Matchers {
}

"Literals" should "have a meaningful string representation" in {
ChiselStage.emitCHIRRTL {
new RawModule {
3.U.toString should be("UInt<2>(3)")
3.U(5.W).toString should be("UInt<5>(3)")
-1.S.toString should be("SInt<1>(-1)")
false.B.toString should be("Bool(false)")
true.B.toString should be("Bool(true)")
Vec(3, UInt(4.W)).toString should be("UInt<4>[3]")
EnumTest.sNone.toString should be("EnumTest(0=sNone)")
EnumTest.sTwo.toString should be("EnumTest(2=sTwo)")
EnumTest(1.U).toString should be("EnumTest(1=sOne)")
(new BundleTest).Lit(_.a -> 2.U, _.b -> false.B).toString should be("BundleTest(a=UInt<8>(2), b=Bool(false))")
(new PartialBundleTest).Lit().toString should be(
"PartialBundleTest(a=UInt<8>(DontCare), b=Bool(DontCare), c=SInt<8>(DontCare), f=EnumTest(DontCare))"
)
DontCare.toString should be("DontCare()")
}
}
3.U.toString should be("UInt<2>(3)")
3.U(5.W).toString should be("UInt<5>(3)")
-1.S.toString should be("SInt<1>(-1)")
false.B.toString should be("Bool(false)")
true.B.toString should be("Bool(true)")
Vec(3, UInt(4.W)).toString should be("UInt<4>[3]")
EnumTest.sNone.toString should be("EnumTest(0=sNone)")
EnumTest.sTwo.toString should be("EnumTest(2=sTwo)")
EnumTest(1.U).toString should be("EnumTest(1=sOne)")
(new BundleTest).Lit(_.a -> 2.U, _.b -> false.B).toString should be("BundleTest(a=UInt<8>(2), b=Bool(false))")
(new PartialBundleTest).Lit().toString should be(
"PartialBundleTest(a=UInt<8>(DontCare), b=Bool(DontCare), c=SInt<8>(DontCare), f=EnumTest(DontCare))"
)
DontCare.toString should be("DontCare()")
}
}
Loading