@@ -109,11 +109,11 @@ source .github/scripts/check_for_missing_readme_md.sh
109109
110110### Prerequisites
111111
112- - the script must be run while being in the root directory (/hdl)
113- - clean the repository to remove the files generated by Vivado
114- - it will be run only on Verilog files that do not contain "tb" in their path
115- - doesn't run on SystemVerilog files
116- - uses Python 3.x
112+ * the script must be run while being in the root directory (/hdl)
113+ * clean the repository to remove the files generated by Vivado
114+ * runs on Verilog (.v) and SystemVerilog (.sv) files, except those containing
115+ "tb" in their path/name (testbenches are ignored)
116+ * uses Python 3.x
117117
118118### Rules that are checked
119119
@@ -126,19 +126,24 @@ the year range. Exceptions are the JESD files and the ones specified in the
126126` avoid_list ` string list.
127127If ` -e ` option is added, the script can update the year range.
128128
129- #### 2. Two or more consecutive empty lines
129+ #### 2. Empty lines
130130
131- It checks in the whole file if there are two or more consecutive empty lines.
132- If ` -e ` option is added, the script can remove them and leave only one empty line.
131+ It checks if the file contains empty line issues:
132+ * Two or more consecutive empty lines.
133+ * An empty line at the beginning of the file.
134+ * An empty line at the end of the file.
135+ If the ` -e ` option is added, the script removes redundant empty lines and ensures
136+ that at most one empty line is kept, while also removing any leading or trailing
137+ empty lines.
133138
134139#### 3. Trailing whitespace
135140
136141It checks if there are whitespace characters at the end of the lines.
137142If ` -e ` option is added, then they can be removed.
138143
139- #### 4. Lines after ` endmodule ` tag
144+ #### 4. Lines after end token
140145
141- It checks if there are lines after it .
146+ It checks if there are lines after end token ( ` endmodule ` or ` endpackage ` ) .
142147If ` -e ` option is added, the script can remove them.
143148
144149#### 5. Parentheses around the module declaration
@@ -151,62 +156,128 @@ If `-e` option is added, the script can put them in their proper place.
151156
152157#### 6. Indentation of code
153158
154- It checks if all lines (except for the ones that are commented) have an indentation
155- of two or multiple of two spaces.
156- Other exceptions to this are the ` module ` line, the ` endmodule ` line, the ` ) ( `
157- and the ` ); ` from the module declaration.
159+ It checks that indentation is done with spaces in multiples of 2 (minimum 2).
160+ This applies to parameters, ports, and code inside modules or packages.
158161
159162#### 7. Position of the module instances
160163
161164It checks if the parameters' list (if that's the case) is in proper position,
162165meaning that the position of ` # ` is checked, the parameters to be specified each
163- on its own line, the parentheses around the instance name and the closing parenthesis
164- of the module instance.
166+ on its own line, the parentheses around the instance name and the closing
167+ parenthesis of the module instance.
165168
166169_ NOTE_ : these rules are marked in the script with ** GC** (stands for Guideline Check)
167170in the comments.
168171
169- ### Changes done by the script to your files
172+ #### 8. SystemVerilog packages
173+
174+ It checks if SystemVerilog packages are defined correctly:
175+ * ` package <name>; ` starts at column 0, with no extra spaces before or after ;.
176+ * ` endpackage ` is alone on its line at column 0.
177+ * Exactly one newline follows ` endpackage ` .
178+ * Inside the package, typedefs and localparams follow the same indentation and
179+ alignment rules.
180+ If the ` -e ` option is added, the script rewrites these to the guideline-compliant
181+ format.
182+
183+ #### 9. Localparams
184+
185+ It checks if localparam declarations follow the rules:
186+ * Indented by a multiple of 2 spaces (minimum 2).
187+ * ** List form:** each item is on a new line, ` = ` operator is aligned, and the last
188+ item has no comma.
189+ * ** Concatenation form ({ … }):**
190+ * The first element is on the same line as ` { ` .
191+ * Following elements are indented +2 spaces.
192+ * Inline comments are aligned at least 4 spaces after the longest element.
193+ * The closing ` }; ` is attached to the last element.
194+ If the ` -e ` option is added, the script normalizes the block automatically.
195+
196+ #### 10. Typedefs
197+
198+ It checks if typedef blocks are formatted correctly:
199+ * They are not written as one-liners, each item is on its own line.
200+ * Base indentation is a multiple of 2 and at least 2.
201+ * Inner items are indented +2.
202+ * Closing ` } type_name; ` is aligned with the opening ` typedef ` .
203+ * Inline comments after the closing are moved to a separate line.
204+ If the ` -e ` option is added, the script rewrites the block to the guideline-compliant
205+ format.
206+
207+ #### 11. Project name vs. path
208+
209+ It checks that in each system_project.tcl, the project name used in ` adi_project `
210+ matches the relative project path under ` projects/ ` .
211+
212+ Example:
213+ ```
214+ projects/ad9783_ebz/zcu102 ⇒ adi_project ad9783_ebz_zcu102
215+ ```
216+
217+ If the ` -e ` option is added, the script updates the project name automatically.
170218
171- If one wants the script to make changes in files, they will be regarding:
219+ ### Changes done by the script to your files
172220
173- - license header, except for JESD files and the ones specified in ` avoid_list `
174- - two or more consecutive empty lines
175- - trailing whitespaces
176- - lines after ` endmodule ` tag
177- - parentheses around the module declaration (meaning ` ) ( ` for the parameters'
221+ If edits are enabled (-e), the script may modify:
222+ * license header, except for files specified in ` avoid_list `
223+ * empty lines (two or more consecutive, or at file start/end)
224+ * trailing whitespaces
225+ * lines after ` endmodule ` /` endpackage ` tag
226+ * parentheses around the module declaration (meaning ` ) ( ` for the parameters'
178227 list and ` ); ` for when closing the declaration)
228+ * typedefs and localparams — rewritten into a guideline-compliant format
229+ * SystemVerilog packages — normalizes ` package <name>; ` / ` endpackage ` placement
230+ and ensures exactly one newline after ` endpackage `
231+ * project name inside ` system_project.tcl ` (to match the relative project path)
179232
180233### Ways to run the script
181234
235+ The script supports several modes of execution, depending on what files you want
236+ to check and whether edits are allowed:
237+
1822381 . With no arguments: ` python3 check_guideline.py `
183- Checks all files with the properties specified above.
184- Does not modify the files.
239+ Runs on all HDL files under ` library/ ` and ` projects/ ` , in check-only mode (does
240+ not modify the files) .
185241
1862422 . With arguments:
187- 1 . ` -e ` with no file specified
188- Checks all files with the properties specified above. Additionally,
189- it modifies the module definition parentheses according to the guideline.
190- 2 . ` -m `
191- Checks files that are given as arguments (by their names including the
192- extension).
193- 3 . ` -me `
194- Checks files that are given as arguments (by their names including the
195- extension) and modifies the files where the guideline is not respected.
196- 4 . ` -p `
197- Checks files that are given as arguments (by their relative path) and
198- modifies the files where the guideline is not respected.
199- 5 . ` -pe `
200- Checks files that are given as arguments (by their relative path) and
201- modifies the files where the guideline is not respected.
243+ 1 . ` -e ` with no file specified: ` python3 check_guideline.py -e `
244+ Checks all files with the properties specified above and applies fixes
245+ according to the guideline.
246+
247+ 2 . ` -m `
248+ Checks files that are given as arguments (by their names including the
249+ extension).
250+
251+ 3 . ` -me `
252+ Checks files that are given as arguments (by their names including the
253+ extension) and modifies the files where the guideline is not respected.
254+
255+ 4 . ` -p `
256+ Checks files that are given as arguments (by their relative path) and
257+ modifies the files where the guideline is not respected.
258+
259+ 5 . ` -pe `
260+ Checks files that are given as arguments (by their relative path) and
261+ modifies the files where the guideline is not respected.
202262
203263### Examples of running
204264
205265```
266+ # Check all files in the repo, no modifications
206267python3 check_guideline.py >> warnings.txt
268+
269+ # Check and edit every HDL file in the repo
207270python3 check_guideline.py -e >> warnings.txt
271+
272+ # Check a specific file given by name, no modifications
208273python3 check_guideline.py -m axi_ad9783.v >> warnings.txt
274+
275+ # Check and edit a specific files by name
209276python3 check_guideline.py -me axi_ad9783.v axi_ad9783_if.v up_adc_common.v >> warnings.txt
277+
278+ # Check specific files given by absolute/relative paths, no modifications
210279python3 check_guideline.py -p ./library/axi_ad9783/axi_ad9783.v ./library/common/up_adc_common.v >> warnings.txt
280+
281+ # Check and edit a specific file given by absolute/relative path
211282python3 check_guideline.py -pe ./library/axi_ad9783/axi_ad9783_if.v >> warnings.txt
212283```
0 commit comments