-
Notifications
You must be signed in to change notification settings - Fork 123
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
Format module port expressions in tabular style #50
Conversation
The module instantiation section was titled "Parameterized Module Instantiation" and started with guide on instantiating *parametrized* modules, but then went on to the more general case of instantiating all kinds of modules. To better match the content of the section, and to have most general guidance first, rename the section and reshuffle its contents.
.Height(5), | ||
.Width(10) |
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.
We should also tabular-align parameter set.
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.
Yes, but let's handle that in a separate PR. I'll push that as soon as we have merged this one to avoid the merge conflict.
VerilogCodingStyle.md
Outdated
) my_module ( | ||
...etc... | ||
|
||
my_reg #(16) my_reg0 (.clk_i, .rst_ni, .d_i(data_in), .q_o(data_out)); |
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.
Verible will format this to have each port connection on a new line (which I actually like, since it makes to port connections easier to read).
|
||
.in_another_block_i(my_signal_in), | ||
.sig3_i (something) | ||
); |
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 worth an additional example with a comment rather than a blank line?
mod u_mod (
.clk_i,
.rst_ni,
.sig_i (my_signal_in),
.sig2_i (my_signal_out),
// comment with no blank line maintains the block
.in_same_block_i(my_signal_in),
.sig3_i (something)
);
VerilogCodingStyle.md
Outdated
@@ -1527,6 +1526,33 @@ Do not use positional arguments to connect signals to ports. | |||
|
|||
Instantiate ports in the same order as they are defined in the module. | |||
|
|||
Align expressions in [tabular style](#tabular-alignment). |
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.
Maybe "port expressions" rather than just "expressions"? I don't have a strong view.
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 SystemVerilog spec calls it "expression", but I also find it too generic. I updated the text to read "port expressions", as suggested.
9a5c883
to
b251fd0
Compare
Do we want to explicitly require tabular alignment, and if so specify a particular style for doing so? As is this just encourages aligning ports but doesn't mandate it and leave it up to the code author to choose a style for doing it. A strict 'you must do it like this' is problematic because we'll have lots of RTL violating the style guide, but maybe a 'ports must be aligned, style can vary but must be kept consistent across a block and our preferred style(s) is/are ...'? |
This change is intended to require tabular alignment, which is further described in the "Tabular Alignment" section at the top of the document.
The intend of this clarification is to mandate one way of formatting port expressions, which can then be enforced by tooling. I do not plan to go around and change all violating RTL code right now, we can do that as we stumble across it, or just rely on Verible format or another tool to do it for us once it is ready. (Which is the same approach we used when introducing clang-format.) |
In that case I think we need stronger wording, the "Tabular Alignment" section starts
Should we switch this to
With some explanation of the desired style
Then a couple of bad examples to demonstrate violations: mod u_mod(
.clk_i,
.rst_ni,
// Not allowed, leading/trailing whitespace in parenthesis
.sig_1_i( sig_1 ),
.sig_2_i( sig_2 )
); mod u_mod(
.clk_i,
.rst_ni,
.short_sig_i (sig_1),
// Not allowed, there should be no whitespace between the longest signal name and the parenthesis
.a_very_long_signal_name_indeed_i (sig_2)
); |
Require expressions in port lists in a module instantiation to be formatted in tabular style. Fixes lowRISC#48
b251fd0
to
8316d25
Compare
@GregAC good points. I clarified these points, PTAL. |
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 good, thanks
The discussion in #48 has concluded and we do have a large majority for this change. Let's get it in! |
Port expressions in module instantiations should be formatted in tabular style, as discussed in #48.