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

[ExportVerilog] Bound type size considered for decl alignment #6171

Merged
merged 1 commit into from
Oct 2, 2023

Conversation

fabianschuiki
Copy link
Contributor

We currently blindly align the types and names of declarations, which causes excessively large types like structs to ruin the alignment of declarations. Instead, introduce an upper bound above which a type does not contribute towards the maxTypeWidth count. This means that excessively large types are just emitted without alignment, without other declarations being forced to follow the same alignment. This change is purely cosmetic.

Also tweak the code that emits the spacing around declarations to work by specifying a target column up to which spaces should be filled, and then filling in those spaces, or a minimum of 1. This makes it harder to get the alignment off by 1 just because some type or decl word was empty and didn't need a trailing space.

Copy link
Member

@uenoku uenoku left a comment

Choose a reason for hiding this comment

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

LGTM, could you add a small test to test file which has --strict-whitespace? (probably ExportVerilog/decl-align.mlir`)

Copy link
Contributor

@dtzSiFive dtzSiFive left a comment

Choose a reason for hiding this comment

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

LGTM, but yes a strict-whitespace test would be nice.

Looks like this fixes the weird wrapping behavior bug when there's no decl word and it would "break" after the (empty) decl? Adding a regression test for that would be a good candidate for the test and something already have on-hand! 👍 .

We currently blindly align the types and names of declarations, which
causes excessively large types like structs to ruin the alignment of
declarations. Instead, introduce an upper bound above which a type does
not contribute towards the `maxTypeWidth` count. This means that
excessively large types are just emitted without alignment, without
other declarations being forced to follow the same alignment. This
change is purely cosmetic.

Also tweak the code that emits the spacing around declarations to work
by specifying a target column up to which spaces should be filled, and
then filling in those spaces, or a minimum of 1. This makes it harder
to get the alignment off by 1 just because some type or decl word was
empty and didn't need a trailing space.
@fabianschuiki fabianschuiki force-pushed the fschuiki/verilog-decl-alignment branch from ae40179 to a1d97a3 Compare October 2, 2023 18:55
@fabianschuiki
Copy link
Contributor Author

Great point! I've added a check to the existing pretty.mlir strict-whitespace test.

@fabianschuiki fabianschuiki merged commit 8fa33c1 into main Oct 2, 2023
5 checks passed
@fabianschuiki fabianschuiki deleted the fschuiki/verilog-decl-alignment branch October 2, 2023 19:08
@dtzSiFive
Copy link
Contributor

Woohoo!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants