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

Add Probes to .toString Data methods #4478

Merged
merged 5 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 13 additions & 2 deletions core/src/main/scala/chisel3/DataImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -470,21 +470,32 @@ private[chisel3] trait DataImpl extends HasId with NamedComponent { self: Data =
}
}

// Specializes the .toString method of a [[Data]] for conditions such as
// DataView, Probe modifiers, a DontCare, and whether it is bound or a pure chisel type
private[chisel3] def stringAccessor(chiselType: String): String = {
// Add probe and layer color (if they exist) to the returned String
def addProbeModifier(chiselType: String): String = {
probeInfo match {
case None => chiselType
case Some(ProbeInfo(writeable, layer)) =>
val layerString = layer.map(x => s", ${x.fullName}").getOrElse("")
(if (writeable) "RWProbe" else "Probe") + s"<$chiselType$layerString>"
}
}
// Trace views to give better error messages
// 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(reifySingleTarget(this)).toOption.flatten.getOrElse(this)
thiz.topBindingOpt match {
case None => chiselType
case None => addProbeModifier(chiselType)
// Handle DontCares specially as they are "literal-like" but not actually literals
case Some(DontCareBinding()) => s"$chiselType(DontCare)"
case Some(topBinding) =>
val binding: String = thiz._bindingToString(topBinding)
val name = thiz.earlyName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sort of surprised the test is below is working:

Wire(probe.Probe(UInt(1.W))).toString should be("BoundDataModule.?: Wire[Probe<UInt<1>>]")

A Wire of probe should have a top binding...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does have a top binding? Not sure I understand..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should have top binding, this does not make sense to me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I missed that you also had addProbeModifier below.

I think it would be better to only do that once, will suggest above.

val mod = thiz.parentNameOpt.map(_ + ".").getOrElse("")

s"$mod$name: $binding[$chiselType]"
s"$mod$name: $binding[${addProbeModifier(chiselType)}]"
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/test/scala/chiselTests/DataPrint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,26 @@ class DataPrintSpec extends ChiselFlatSpec with Matchers {
val f = EnumTest.Type()
}

object A extends layer.Layer(layer.LayerConfig.Extract()) {
object B extends layer.Layer(layer.LayerConfig.Extract())
}

"Data types" should "have a meaningful string representation" in {
ChiselStage.emitCHIRRTL {
new RawModule {
UInt().toString should be("UInt")
UInt(8.W).toString should be("UInt<8>")
probe.Probe(UInt(8.W)).toString should be("Probe<UInt<8>>")
probe.RWProbe(UInt(8.W)).toString should be("RWProbe<UInt<8>>")
probe.Probe(UInt(8.W), A).toString should be("Probe<UInt<8>, A>")
probe.Probe(UInt(8.W), A.B).toString should be("Probe<UInt<8>, A.B>")
SInt(15.W).toString should be("SInt<15>")
Bool().toString should be("Bool")
Clock().toString should be("Clock")
Vec(3, UInt(2.W)).toString should be("UInt<2>[3]")
EnumTest.Type().toString should be("EnumTest")
(new BundleTest).toString should be("BundleTest")
(probe.Probe(new BundleTest)).toString should be("Probe<BundleTest>")
new Bundle { val a = UInt(8.W) }.toString should be("AnonymousBundle")
new Bundle { val a = UInt(8.W) }.a.toString should be("UInt<8>")
}
Expand All @@ -45,6 +54,7 @@ class DataPrintSpec extends ChiselFlatSpec with Matchers {

class BoundDataModule extends Module { // not in the test to avoid anon naming suffixes
Wire(UInt()).toString should be("BoundDataModule.?: Wire[UInt]")
Wire(probe.Probe(UInt(1.W))).toString should be("BoundDataModule.?: Wire[Probe<UInt<1>>]")
Reg(SInt()).toString should be("BoundDataModule.?: Reg[SInt]")
val io = IO(Output(Bool())) // needs a name so elaboration doesn't fail
io.toString should be("BoundDataModule.io: IO[Bool]")
Expand Down
Loading