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

Enable @chiselName on non-module classes #1209

Conversation

johnsbrew
Copy link
Contributor

Type of change: other enhancement

Impact: API addition (no impact on existing code)

Development Phase: implementation

Release Notes
Enable @chiselName on non-module classes

Hardware val declared inside the scope of a standard scala class (ie that do not extend any kind of Module) can now benefit from the @chiselName macro and get hw-user-friendly names thanks to the existing fancy macro work of @ducky64 & @jackkoenig =)

@johnsbrew johnsbrew requested a review from a team as a code owner October 14, 2019 15:46
@ghost
Copy link

ghost commented Oct 14, 2019

Can one of the admins verify this patch?

@edwardcwang
Copy link
Contributor

Does this affect #1046?

@johnsbrew
Copy link
Contributor Author

@edwardcwang Well, I don't know... it does not break the existing tests but I am not sure they are fully exhaustive ?

@ucbjrl
Copy link
Contributor

ucbjrl commented Oct 14, 2019

ok to test

@johnsbrew
Copy link
Contributor Author

Any chance to get a review on this one ? @azidar ?

@jackkoenig
Copy link
Contributor

@ducky64 could you take a look at this? Looks very useful

Copy link
Contributor

@ducky64 ducky64 left a comment

Choose a reason for hiding this comment

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

A question about edge cases, and documentation (comments) need updating.

i'm also curious, what's the use case here?

@@ -118,12 +118,14 @@ class NamingTransforms(val c: Context) {
def transformModuleBody(stats: List[c.Tree]): Tree = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment needs to be revised, the class may not be the naming top level. You might also want to rename associated items like ModuleTransformer and transformModuleBody so that it doesn't imply it only applies to Modules anymore, but handles all classes. Documentation in Namer.scala also needs to be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I didn't see any comments to be updated in Namer.scala though since the case of Module is described as a special behaviour.
Closing context on a non-module is not an issue.
The only change to Namer.scala I would suggest is to rename namePrefix as closeContext as it sounds a bit clearer to me.

$contextVar.namePrefix("")
$globalNamingStack.popReturnContext((), $contextVar)
if($globalNamingStack.length == 1){
$contextVar.namePrefix("")
Copy link
Contributor

Choose a reason for hiding this comment

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

This made sense when Module was top-level, since in all cases the first naming prefix you get would correlate directly with something in the Module. In this case, you could have a non-Module class as the top-level, and the first naming prefix would not necessarily correlate with anything in the Module. Is this behavior we want? Or do we want a check somewhere that the naming top-level is the Module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I understand the macro, when top level is not a module what does the transform is harmless and does not reflect in anyway to the emitted names so it is not an issue.

Copy link
Contributor Author

@johnsbrew johnsbrew left a comment

Choose a reason for hiding this comment

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

@ducky64

The use-case is pretty simple : be able to play with oriented-hardware-object programming.
The idea is to have standard classes that are not module but still contains some hardware objects like wire and registers.
I see this non-module hardware classes as tiny reusable blocks on which I implement some methods depending on the context.
Proper naming is required for any debugging related to the contained hardware registers and wires.
It is somehow like an InlineModule but without the wrapping into Module(). Moreover seeing these little reusable blocks as module would lead to great confusion when it comes to hierarchy representation.

Copy link
Contributor

@ducky64 ducky64 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 fine.

I'm not completely convinced that this is the right approach to your problem. It seems that you still want a Module, just inlined so the Verilog generation is cleaner. That aside, you can use the companion object pattern to avoid Module(...) wrappers while providing a default IO connection as argument syntax.

This solution seems like a bit of a hack, would it be cleaner just to have some way to declare a Module inline, eg a inline module annotation or mixin?

@jackkoenig
Copy link
Contributor

It's not that uncommon Chisel style to have non-Module classes for generating hardware. For example, in this repo: https://github.com/freechipsproject/chisel3/blob/410f03b9122978e43db938d7774b451f2b9111d0/src/main/scala/chisel3/util/Counter.scala#L27

@johnsbrew
Copy link
Contributor Author

I can hear your point of view @ducky64, but I agree with @jackkoenig I definitely think that being able to build hardware generator objects that are neither fully-featured modules nor functions is interesting.
Let's merge it then ? I do not have the right to do it.

@ducky64 ducky64 merged commit 9406e2b into chipsalliance:master Nov 15, 2019
@azidar
Copy link
Contributor

azidar commented Nov 25, 2019

@Mergifyio backport 3.2.x

mergify bot pushed a commit that referenced this pull request Nov 25, 2019
@mergify
Copy link
Contributor

mergify bot commented Nov 25, 2019

Command backport 3.2.x: success

Backports have been created
The following pull requests have been created:

Hey, we reacted but our real name is @Mergifyio

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.

6 participants