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

Format module port expressions in tabular style #50

Merged
merged 3 commits into from
May 24, 2021

Conversation

imphil
Copy link
Contributor

@imphil imphil commented Apr 19, 2021

Port expressions in module instantiations should be formatted in tabular style, as discussed in #48.

imphil added 2 commits April 19, 2021 18:43
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.
Comment on lines +1542 to +1573
.Height(5),
.Width(10)
Copy link

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.

Copy link
Contributor Author

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.

) my_module (
...etc...

my_reg #(16) my_reg0 (.clk_i, .rst_ni, .d_i(data_in), .q_o(data_out));
Copy link

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)
);

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)
);

@@ -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).

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.

Copy link
Contributor Author

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.

@imphil imphil force-pushed the module-portlists branch from 9a5c883 to b251fd0 Compare April 19, 2021 21:15
@imphil
Copy link
Contributor Author

imphil commented Apr 19, 2021

Thanks for your feedback @sriyerg and @mdhayter, I updated the PR to include your suggestions.

@GregAC
Copy link
Contributor

GregAC commented Apr 20, 2021

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 ...'?

@imphil
Copy link
Contributor Author

imphil commented Apr 20, 2021

Do we want to explicitly require tabular alignment, and if so specify a particular style for doing so?

This change is intended to require tabular alignment, which is further described in the "Tabular Alignment" section at the top of the document.

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 ...'?

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.)

@GregAC
Copy link
Contributor

GregAC commented Apr 20, 2021

This change is intended to require tabular alignment, which is further described in the "Tabular Alignment" section at the top of the document.

In that case I think we need stronger wording, the "Tabular Alignment" section starts

Adding whitespace to cause related things to align is encouraged.

Should we switch this to

Tabular alignment of ports of module instantiations is required.
Adding whitespace to cause related things to align elsewhere is encouraged.

With some explanation of the desired style

There must be no trailing or leading whitespace inside the parenthesis containing a port expression. Within a aligned port block there must be no whitespace between the longest port name and the parenthesis.

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
@imphil imphil force-pushed the module-portlists branch from b251fd0 to 8316d25 Compare April 20, 2021 10:07
@imphil
Copy link
Contributor Author

imphil commented Apr 20, 2021

@GregAC good points. I clarified these points, PTAL.

Copy link
Contributor

@GregAC GregAC left a comment

Choose a reason for hiding this comment

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

Looks good, thanks

@imphil
Copy link
Contributor Author

imphil commented May 24, 2021

The discussion in #48 has concluded and we do have a large majority for this change. Let's get it in!

@imphil imphil merged commit 31df429 into lowRISC:master May 24, 2021
@imphil imphil deleted the module-portlists branch May 24, 2021 08:51
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