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

Define Data .toString #985

Merged
merged 12 commits into from
Jan 22, 2019
Merged

Define Data .toString #985

merged 12 commits into from
Jan 22, 2019

Conversation

ducky64
Copy link
Contributor

@ducky64 ducky64 commented Jan 16, 2019

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:

  • Naming for Bundles and ChiselEnums are inconsistent, as ChiselEnum uses a qualified path name where Bundles are just the class simpleName. Perhaps we should standardize on one? @hngenc
  • @hngenc comments on the changes to StrongEnum.scala are welcome.
  • I'm not sure why Bundle has its className hardcoded to Bundle. I removed that to get it to default to the class name in Record. @jackkoenig appears to be the last person associated with that line of code, thoughts?
  • The FixedPoint parameter print style is consistent with FIRRTL <width><<binaryPoint>> but not how I've defined Vec <n, type>. Note that FIRRTL defines Vec as type[n]. @azidar thoughts if we want things to print one particular way or the other?
  • Some potential for deduplication with Emitter.scala.
  • We currently don't have source locators for binding operations, but it could be added in the future.

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.

@ducky64 ducky64 requested a review from chick January 16, 2019 23:13
@ducky64 ducky64 requested a review from a team as a code owner January 16, 2019 23:13
@edwardcwang
Copy link
Contributor

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"

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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!

@ducky64
Copy link
Contributor Author

ducky64 commented Jan 17, 2019

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.

chick
chick previously approved these changes Jan 17, 2019
Copy link
Contributor

@chick chick left a 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)")
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@ducky64
Copy link
Contributor Author

ducky64 commented Jan 18, 2019

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
Clock(IO in unelaborated MyModule)
and
Clock(IO clock in MyModule)

val bindingString = litOption match {
case Some(value) => factory.nameOfValue(value) match {
case Some(name) => s"($value=$name)"
case None => s"($value)"
Copy link
Contributor

@hngenc hngenc Jan 18, 2019

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?

@hngenc
Copy link
Contributor

hngenc commented Jan 18, 2019

I made a small comment, but overall, I think the changes to ChiselEnum are just fine.

@ducky64 If you're talking about changing enumTypeName to the simple name, then I'm fine with that.

@ducky64
Copy link
Contributor Author

ducky64 commented Jan 19, 2019

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:

  • Changed Vec print format to match FIRRTL
  • Changed bad Enum print format to ($value=(invalid)). Not sure how to test for that since I can't create an invalid Enum.
  • Added DataMirror.fullModulePorts as a utility function, that returns the underscore-delimited names for Bundle or Vec elements.
  • Added printing IO names for elaborated modules. They're underscore-delimited, so consistent with FIRRTL but not what would be expected from Chisel. Thoughts welcome.

@ducky64 ducky64 dismissed chick’s stale review January 19, 2019 00:26

significant changes, re-review requested

@ducky64
Copy link
Contributor Author

ducky64 commented Jan 19, 2019

  • Added fallback Bundle naming so anonymous Bundles are named Bundle, otherwise they had an empty string

Copy link
Contributor

@chick chick left a 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

@ducky64
Copy link
Contributor Author

ducky64 commented Jan 22, 2019

Looks like anonymous bundles return a different name on different platforms ($anon$2 vs empty string), this now supports both versions that I've seen.
Also changed the name output of anonymous bundles to AnonymousBundle, which better indicates that it should handle named bundles properly.

@ducky64 ducky64 merged commit b39bc25 into master Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants