svlint icon indicating copy to clipboard operation
svlint copied to clipboard

re_require_port_interface doesn't work with corresponding rules for inout, input, and output

Open Binvention opened this issue 1 year ago • 1 comments

with the re_required_port rules interfaces get mistaken for inout, input, or output depending on which was the last used. This makes it impossible to use the rules at the same time especially if different regex is used for each. For example the module

module test_module
(
    I.i    test_bad_if_1,
    input wire i_input_test,
    I.i    test_bad_if_2,
    output wire o_output_test,
    I.i    test_bad_if_3,
    inout wire io_inout_test,
    I.i    test_bad_if_4
);

endmodule : test_module

with the regex rules re_required_port_interface = "^[a-z]+[a-z0-9_]$" re_required_port_inout = "^[iov?[A-Za-z]+[A-Za-z0-9]$" re_required_port_input = "^[iv?[A-Za-z]+[A-Za-z0-9]$" re_required_port_output = "^[ov?[A-Za-z]+[A-Za-z0-9]$"

throws an error on all interfaces in the module but it does it for the inout rule on the first one, input rule on the second one, output rule on the third one, and inout rule on the 4th one. If the port name for the interface is changed to not match the regex it still throws the interface rule error but it also throws the other error as well.

Looking through the source code it looks like it is because the rules for inout, input, and output have checks in place for if the previous port direction was an input, output, inout, or ref but not a check for if it is an interface. (see re_required_port_inout.rs lines 28-44 as an example compare with re_require_port_interface.rs lines 26-34). I'm not familiar enough with the source code yet to know for sure or to fix it but that is what I was able to find

Binvention avatar Apr 04 '24 16:04 Binvention

Good catch. I think the fix is to add RefNode::ListOfInterfaceIdentifiers and RefNode::InterfacePortHeader to the list of things which reset self.previous_port_direction_* et al in the rules re_(forbidden|required)_port_(inout|input|output|ref) around line 40. @Binvention Would you feel comfortable opening a PR?

DaveMcEwan avatar Dec 12 '24 16:12 DaveMcEwan