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

Fix alignment of structs and enums. #1789

Merged
merged 1 commit into from
Jul 17, 2022

Conversation

gmlarumbe
Copy link
Contributor

Hi,

This PR fixes the alignment of (typedef) enums and structs declarations. Since these were being detected wrongly, the new changes just ignore them when running verilog-pretty-declarations. However, fields inside a struct still get aligned properly.

For example, considering the following example from #1752 discussion:

module pr_example;

logic correct_0;
logic signed [1:0] incorrect_0;
logic correct_1;
logic signed [1:0] incorrect_1;

typedef enum logic [1:0]
{STATE_0,
STATE_1,
STATE_2,
STATE_3} t_incorrect_2;
t_incorrect_2 incorrect_3;

endmodule

After indenting and executing verilog-pretty-declarations this is the result before the PR:

module pr_example;
    
    logic              correct_0;
    logic signed [1:0] incorrect_0;
    logic              correct_1;
    logic signed [1:0] incorrect_1;

    typedef enum       logic [1:0]
                       {STATE_0,
                       STATE_1,
                       STATE_2,
                       STATE_3} t_incorrect_2;
    t_incorrect_2 incorrect_3;
    
endmodule // pr_example

And this is the result after these changes:

module pr_example;
    
    logic              correct_0;
    logic signed [1:0] incorrect_0;
    logic              correct_1;
    logic signed [1:0] incorrect_1;

    typedef enum logic [1:0]
        {STATE_0,
        STATE_1,
        STATE_2,
        STATE_3} t_incorrect_2;
    t_incorrect_2 incorrect_3;
    
endmodule // pr_example

Regarding typedef structs, considering the already indented piece of code:

module pr_example;

    typedef struct packed {
        int field1;
        int unsigned field2;
        logic [7:0] field3;
    } my_type_t;

endmodule

This is the result before running verilog-pretty-declarations at typedef struct line before PR changes:

module pr_example;

    typedef struct packed {
    int            field1;
    int unsigned   field2;
    logic [7:0]    field3;
    } my_type_t;

endmodule

After these changes, there would be no effect if running verilog-pretty-declarations at typedef struct line. However, if running it over one of the field's lines they get properly aligned inside the struct:

module pr_example;

    typedef struct packed {
        int          field1;
        int unsigned field2;
        logic [7:0]  field3;
    } my_type_t;

endmodule

I also added a couple of tests. One of them still needs some indentation fixes (with verilog-indent-lists set to t), but that will come in a different PR.

Thanks!

* verilog-mode.el (verilog-at-enum-decl-p, verilog-at-enum-p,
verilog-at-struct-decl-p, verilog-do-indent,
verilog-looking-at-decl-to-align, verilog-pretty-declarations,
verilog-typedef-enum-re):

Fix alignment of structs and enums.

Signed-off-by: Gonzalo Larumbe <[email protected]>
Copy link
Member

@wsnyder wsnyder left a comment

Choose a reason for hiding this comment

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

New output looks much better!

@gmlarumbe gmlarumbe merged commit dad7c92 into veripool:master Jul 17, 2022
@bluewww
Copy link

bluewww commented Jul 18, 2022

thanks looks like a great change!

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.

3 participants