-
Notifications
You must be signed in to change notification settings - Fork 602
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
Define Data .toString #985
Conversation
General questions: is this meant to be the "standard definition/format" for printing Chisel objects? Is testers2 going to parse these strings? |
@@ -543,8 +559,6 @@ class AutoClonetypeException(message: String) extends ChiselException(message) | |||
* }}} | |||
*/ | |||
abstract class Bundle(implicit compileOptions: CompileOptions) extends Record { | |||
override def className = "Bundle" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
className
is used by Printable
for hardware pretty printing. I think just using the default Aggregate .getClass.getSimpleName
is better for obvious reasons. I can't recall my original thinking, but I think it had to do with making this pretty printing look like printing a Map in Scala (since that's sort of what Records/Bundles are), but I think giving the name of the Bundle class is generally better.
My only question is what about anonymous or inner bundles? You'll get some pretty weird names but perhaps that's still desirable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the intention of this is for human debugging, I think providing better naming on a best-effort basis makes sense. So anonymous Bundles will probably give some nasty name. Inner bundles should work fine, it's one of the test cases (though not intentionally).
Random thought: maybe we could regex match anonymous bundle names and replace it with a more friendly AnonymousBundle? Might be more trouble than it's worth though, so I'd prefer to wait for user feedback first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think that's sensible, at least MyModule$anon$1
tells you more than just Bundle
!
This is meant to provide a human-readable format for debugging. It's not meant to be (and should not be) machine readable. If there was some kind of standard, this should follow it to the extent the standard provides a human-readable format, but I'm not trying to define a standard here. The print representation can change as necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good (and useful) to me.
} | ||
|
||
class BoundDataModule extends MultiIOModule { // not in the test to avoid anon naming suffixes | ||
Wire(UInt()).toString should be("UInt(Wire in DataPrintSpec$BoundDataModule)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it might be worth having a source locator for Data? Let people know where the Wire was constructed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly. This is new enough that I don't know what the use case for this will be (other than printing literals), so I'd like to wait and see first.
There would also need to be infrastructure built for it, mainly IO needs to have a source locator attached to it, and all Bindings needs a copy of the source locator (currently is only part of the FIRRTL command). Adding source locators for literals would be more difficult because of the possibility for a chained apply, so we might have to build more source info transform macros.
Another interesting idea would be to print IO names where possible, though naming data isn't available until after the Module finishes elaboration. Perhaps something like |
val bindingString = litOption match { | ||
case Some(value) => factory.nameOfValue(value) match { | ||
case Some(name) => s"($value=$name)" | ||
case None => s"($value)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to put something like ($value=INVALID)
in the None
case?
I made a small comment, but overall, I think the changes to @ducky64 If you're talking about changing |
I attempted to dedup w/ FIRRTL emit, but there's enough different functionality that I don't think it's worth it. In particular, FIRRTL doesn't have named Record / Bundles, but it doesn't make sense to print the entire Bundle definition. Other changes:
|
significant changes, re-review requested
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good and should be helpful
Looks like anonymous bundles return a different name on different platforms ( |
toString now defined on Data subtypes, and handles literals properly.
See test cases for expected behavior.
Meant to support testers2, which uses literals as its interface. So you can directly print the result of a peek, instead of unpacking it through litValue and friends. Also gives type information for printf debugging when writing RTL.
Discussion points:
<width><<binaryPoint>>
but not how I've defined Vec<n, type>
. Note that FIRRTL defines Vec astype[n]
. @azidar thoughts if we want things to print one particular way or the other?Related issue: Resolves #953
Type of change: other enhancement
Impact: no functional change
Development Phase: implementation
Release Notes
toString now defined on Data subtypes, and handles literals properly.