-
Notifications
You must be signed in to change notification settings - Fork 613
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 Public trait to create public FIRRTL modules #3813
Conversation
Add a new trait, `Public`, which can be used to emit FIRRTL modules which have the public keyword. This is a weak form of "public modules" that we want to support for FIRRTL 4.0.0. This does not allow for multiple, disjoint instance graphs to be contained in a circuit, nor does it remove the "main module" from the circuit. However, it provides a mechanism for plucking modules out of a circuit later and working with them. This is self-typed on `RawModule` to prevent mix-in to an external module. Signed-off-by: Schuyler Eldridge <[email protected]>
I'm not sure that this necessarily should be a static property of the class. It seems plausible that you may want a given module to be public in some configurations but not necessarily in others. The biggest example of this is whatever your top module is which is certainly public for the build where it is the top, but may not be public in other builds. We could do something like what |
but couldn't you get the same behavior with a pattern like:
Isn't chisel emission going to have to de facto do this if you want to |
You could, but if val module = if (public) {
Module(new MyNormalModule(arg1, arg2, "foobar", arg3) with Public)
} else {
Module(new MyNormalModule(arg1, arg2, "foobar", arg3))
} My suggestion is that if you mix in class MyNormalModule(args..., public: Boolean) extends Module with Public {
// Only in cases where I may not want to be public do I need to do this:
override def isPublicModule = public
} We originally did the anonymous thing for [OpaqueType](
Pretty much, which is why thinking about it purely as a static property of a given class doesn't make sense to me since it is very context-dependent for how you are using the generator. I do think making it a |
"The main module" should "be marked public" in { | ||
|
||
println(ChiselStage.emitCHIRRTL(new Foo)) | ||
println(ChiselStage.emitSystemVerilog(new Foo)) | ||
|
||
matchesAndOmits(ChiselStage.emitCHIRRTL(new Foo))( | ||
"module Baz", | ||
"public module Bar", | ||
"module Foo" | ||
)( | ||
"public module Baz", | ||
"public module Foo" | ||
) | ||
|
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.
The words of this test seem contradictory with the behavior, Foo
is not being marked public
but shouldn't it be?
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.
Clarified below. In emission (at this point in time for the PR and later changed), Foo
does not have the "public" keyword. However, it's the main module, so it has different semantics in that it is treated as if it were public. It's less confusing to not do it this way and was changed in a later fixup.
I pushed a commit that does what I'm saying, which should be included in a test. Main concern is that the test seems to show us not marking the top module as |
From the FIRRTL spec or CIRCT perspective with how FIRRTL 4.0 is shaping up, it doesn't matter. The test was more checking the exact emission style. I.e., that the code was not forcibly making the main module public. This is FIRRTL 4.0 not as the spec is written now, but in the way that we are planning to do it where modules can have a public attribute, but the circuit still has a main module. If a circuit has a main module, then it is as if it is public from a compilation perspective---it has an implicit user and cannot be removed or have its ports removed. Whether or not it is marked public doesn't really matter as you can't have a "private" main module. We can then make a call in the spec on whether to make this publicness implicit, mandatorily explicit, or optional and without effect. CIRCT doesn't actually care about this right now and it will accept circuits where the main module is public. Internally, the main module is always treated as having a public symbol. I updated the PR to set the main module as public to show what this would look like. |
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.
Looks great, thanks!
Thanks for the review, Jack. I'm going to update the test to be more descriptive of what it is testing and then merge. |
Add a new trait,
Public
, which can be used to emit FIRRTL modules which have the public keyword. This is a weak form of "public modules" that we want to support for FIRRTL 4.0.0. This does not allow for multiple, disjoint instance graphs to be contained in a circuit, nor does it remove the "main module" from the circuit. However, it provides a mechanism for plucking modules out of a circuit later and working with them.This is self-typed on
RawModule
to prevent mix-in to an external module.For the included test Chisel:
This produces the following FIRRTL. Note the
public
keyword:And Verilog. Note that
Bar
is not eliminated because it is public whileBaz
is:Release Notes
Add
Public
keyword to create public FIRRTL modules.