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

[proper-parameter-declaration] parameter vs localparam in packages #2160

Open
sconwayaus opened this issue Apr 16, 2024 · 4 comments
Open

[proper-parameter-declaration] parameter vs localparam in packages #2160

sconwayaus opened this issue Apr 16, 2024 · 4 comments
Labels
style-linter Verilog style-linter issues

Comments

@sconwayaus
Copy link
Contributor

Describe the bug
After fixing a few violations from [proper-parameter-declaration] wrt checking parameters in packages, my synthesis tool (Quartus PRO) throws a warning. It seems Quartus expects "localparam" instead of "parameter". Usually I think Quartus is wrong, but after reviewing the LRM I think Quartus is right.

Section 6.20.4 in the LRM (2017 and older) states "parameters" in packages are treated as a synonym for a localparam, so tools should treat parameters as localparam's in a package. More intuitively, as parameters are overidable, a parameter in a package dosn't make sense in that packages are constant and not parameterisable.

I propose the rule default be changed to raise a violation when a parameter is used in a package.

Test case (preferably reduced)

// Ran the style linter on this code.
package test_pkg;
  parameter string PARAM = "BAD";  // No lint violation
  localparam string LOCAL_PARAM = "GOOD";  // lint violation reported here
endpackage

Actual vs. expected behavior
output from verible-verilog-lint

./test_pkg.sv:3:21-31: Non-type localparam names must be styled with CamelCase [Style: constants] [parameter-name-style]

What should have happened?
Expect "parameter" in package to be reported as lint failure.

Citations to published style guides:
System Verilog LRM IEEE Std 1800™-2017, Section 6.20.4

6.20.4 Local parameters (localparam)
Local parameters are identical to parameters except that they cannot directly be modified by defparam
statements (see 23.10.1) or instance parameter value assignments (see 23.10.2). Local parameters can be
assigned constant expressions (see 11.2.1) containing parameters, which in turn can be modified with
defparam statements or instance parameter value assignments.

Unlike nonlocal parameters, local parameters can be declared in a generate block, package, class body, or compilation-unit scope. In these contexts, the parameter keyword shall be a synonym for the localparam keyword.

Local parameters may be declared in a module’s parameter_port_list. Any parameter declaration appearing
in such a list between a localparam keyword and the next parameter keyword (or the end of the list, if
there is no next parameter keyword) shall be a local parameter. Any other parameter declaration in such a
list shall be a nonlocal parameter that may be overridden as described in 23.10.
@sconwayaus sconwayaus added the style-linter Verilog style-linter issues label Apr 16, 2024
@IEncinas10
Copy link
Collaborator

I think the behaviour is intentional. https://github.com/lowRISC/style-guides/blob/master/VerilogCodingStyle.md#constants: The preferred method of defining constants is to declare a package and declare all constants as a parameter within that package.

@sconwayaus
Copy link
Contributor Author

Thanks for the link, I guess that means there is a case for configuration.

I still think the default for parameters in packages should be changed to localparam based on the LRM. Specifically as compilers will treat parameters in packages as localparam. Better to be explicit.

@sconwayaus
Copy link
Contributor Author

Oops wrong button..

@IEncinas10
Copy link
Collaborator

Yeah, the configuration flag is the safest bet. I don't have an opinion on the default itself, but changing it might be painful for some people

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
style-linter Verilog style-linter issues
Projects
None yet
Development

No branches or pull requests

2 participants