Back to skills
SKILL.md
Ic Verilog Style
ASecurity纯 Verilog-2001 (.v) 代码规范编写、代码审查与 Verilator + Icarus Verilog 双工具 Lint 门禁 Skill。 当需要新建纯 Verilog-2001 RTL 文件、修改已有 .v 代码、修复综合/仿真语法与位宽告警、或进行 RTL 代码质量审查时使用本 skill。
- 2 stars
- 0 votes
- 0 copies
- 0 views
- Added December 2, 2026
Security analysis
100/100Pro scans all 5 files and shows the line behind each finding
npx -y skills add lihhf666-rgb/open-verilog-ip-skills --skill ic-verilog-style --agent claude-codeAre you the author of Ic Verilog Style?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/lihhf666-rgb-ic-verilog-style)---
name: ic-verilog-style
description: >-
纯 Verilog-2001 (.v) 代码规范编写、代码审查与 Verilator + Icarus Verilog 双工具 Lint 门禁 Skill。
当需要新建纯 Verilog-2001 RTL 文件、修改已有 .v 代码、修复综合/仿真语法与位宽告警、或进行 RTL 代码质量审查时使用本 skill。
---
# 纯 Verilog-2001 代码规范与 Lint 门禁(`ic-verilog-style`)
## 一、定位与边界
* **只负责**:保证 `.v` 文件 100% 符合纯 **IEEE 1364-2001** 语法、无 Latch、无多驱动、无位宽/有符号隐蔽 Bug,并通过 Verilator 与 Icarus Verilog 静态门禁。
* **不负责**:复杂状态机设计(交给 `ic-fsm-design`)、时序违例优化(交给 `ic-timing-cdc`)、动态波形排错(交给 `ic-sim-debug`)。
* **一键双工具 Lint 门禁(支持 `--params` 参数扫测与可选 `--yosys` 通用综合检查)**:
```bash
python skills/ic-verilog-style/scripts/lint_v2001.py --top <TOP_MODULE> --rtl rtl/<ip>.v rtl/common/open_skid_buffer.v [--params DATA_W=64] [--yosys]
```
* 详细编码规范见 [verilog-2001-coding-guide.md](./references/verilog-2001-coding-guide.md),新建模块可直接参考模板 [module_template.v](./resources/module_template.v)。
* 通用底层原语优先例化 `rtl/common/open_*.v`。
---
## 二、编写 `.v` 的 10 条核心规则
1. 文件第 1~2 行必须为 `` `timescale 1ns / 1ps `` 和 `` `default_nettype none ``;最后一行必须为 `` `default_nettype wire ``。
2. 端口必须使用 **Verilog-2001 ANSI 风格**,每个端口显式写出 `input wire` / `output wire` / `output reg`。
3. **禁用 SystemVerilog 语法**:禁止 `logic`、`always_ff`、`always_comb`、`enum`、`struct`、`typedef`、`++`、`--`、`+=`、`.*` 以及 `for (int i = 0; ...)`(循环变量须在外部声明为 `integer i;` 或 `genvar g;`)。
4. **时序与组合严格分离**:`always @(posedge clk)` 只用非阻塞赋值 `<=`;`always @(*)` 只用阻塞赋值 `=`;严禁混用。
5. **杜绝 Latch**:每个 `always @(*)` 块首必须给块内**每一个**被赋值的 `reg` 赋默认值;所有 `case` 必须写 `default:`。
6. **严禁无位宽整数运算**:禁止写 `cnt + 1`、`a == 0`;必须显式标定位宽(如 `1'b0`、`16'd1` 或参数化 `localparam [W-1:0] ONE = {{(W-1){1'b0}}, 1'b1};`)。
7. **严禁有符号/无符号混算**:涉及有符号运算时,所有参与操作数必须显式 `$signed(...)`(无符号数先高位补 `1'b0` 再 `$signed({1'b0, u})`)。
8. **仅复位控制通路**:状态机、`valid`、指针、计数器接复位;宽位宽数据通路寄存器(如 `tdata`、流水线数据暂存、RAM 阵列)**禁止加复位**,以减少 Control Sets 并提升主频。
9. **例化与生成规范**:模块例化一律命名端口连接(`.clk(clk)`);`generate for` 块必须命名(`begin : gen_xxx`);**严禁在 `always @(*)` 中读取未打包二维数组**(会触发 `iverilog` 告警及老旧仿真器灵敏度表漏触发),必须使用一维扁平向量配合索引切片 `[g*W +: W]`。
10. **综合纯净度**:RTL 中禁止 `#delay` 与可综合路径外的 `initial`;仿真调试打印必须包在 `` `ifndef SYNTHESIS ... `endif `` 内。
---
## 三、静态 Lint 闭环修复(Max Iterations = 5)
```text
[STEP 1] 运行 lint_v2001.py(内部同时执行 Verilator 1364-2001 -Wall 与 iverilog -g2001 -Wall)
│
├── 退出码 == 0 且 0 Warning ──▶ [PASS 退出]
└── 存在报错/告警 ──▶ 查下方高频错误对照表,精准修复对应行号,回到 [STEP 1](最多 5 轮)
```
### 高频 Lint 告警精确修复表
| Verilator / iverilog 告警类型 | 根因 | 标准修复动作 |
| :--- | :--- | :--- |
| `WIDTH` | 赋值/比较两侧位宽不匹配 | 显式补零 `{1'b0, a}` 或显式切片 `sum[W-1:0]`,禁止用 `lint_off` 掩盖 |
| `LATCH` | `always @(*)` 中存在分支未赋值 | 在 `always @(*)` 块首为所有被赋值 `reg` 设置默认值,并补齐 `case` 的 `default:` |
| `BLKSEQ` / `COMBDLY` | 时序块误用 `=` 或组合块误用 `<=` | 严格改为时序 `<=`、组合 `=` |
| `UNUSED` / `UNDRIVEN` | 存在未使用的输入或未驱动信号 | 删除冗余线网;若因协议端口保留未用位,显式归约 `wire unused_ok = &{1'b0, sig};` |
| `UNOPTFLAT` | 存在潜在组合环或同向量位间依赖 | 拆分组合依赖或插入寄存器打断环路 |
| `TIMESCALEMOD` | 多文件联编时部分模块缺少 `` `timescale `` | 确保所有 `.v` 文件顶部统一声明 `` `timescale 1ns / 1ps `` |
| `MULTIDRIVEN`(仅限双时钟真双口 RAM) | 真双口 RAM(`open_tdp_ram.v`)设计上需要 `clka` 与 `clkb` 双写同一数组 | 仅对该存储数组声明一行局部包裹 `/* verilator lint_off MULTIDRIVEN */ ... /* verilator lint_on MULTIDRIVEN */`(普通逻辑严禁使用!) |
Files in this skill
- SKILL.md
- references/verilog-2001-coding-guide.md
- resources/module_template.v
- scripts/lint_v2001.py
- scripts/manifest_tool.py
Attribution
Related skills
View all in ai-agents →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.