ワンクリックで
bb-code-review
对抗性代码评审:代码质量 / 可维护性 / 时序风险 / 综合友好度 / MAS 对齐度。默认 ruthless 模式,找 EVERY flaw。触发场景:(1) RTL lint 后;(2) 显式 /bb-code-review。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
对抗性代码评审:代码质量 / 可维护性 / 时序风险 / 综合友好度 / MAS 对齐度。默认 ruthless 模式,找 EVERY flaw。触发场景:(1) RTL lint 后;(2) 显式 /bb-code-review。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
基于 AST 检查 CDC/RDC 违例:对比 MAS clock_domains 找跨域信号,检查是否被 2ff-sync CBB 保护。触发场景:(1) bba-guru-synthesis 综合前;(2) 显式 /bb-check-cdc。
调用 verible-verilog-lint 检查 SV 源码。src 必须可综合(零 syntax error),tb 允许 verification constructs。发现 src error 时自动修复重检(max 3 iter)。触发:(1) bba-guru-rtl 生成后;(2) RTL 修复重检;(3) 显式 /bb-check-lint。
解析 Verilator coverage.dat + sim log,输出 functional + code coverage 数值,判断是否 100% 达标。触发场景:(1) bb-invoke-verilator 后;(2) 每次回归后;(3) 显式 /bb-collect-coverage。
从 MAS(io_ring/pad_list/clock_plan)+ 综合网表生成 Magic floorplan TCL,交给 bb-invoke-magic 执行。触发场景:(1) bba-guru-pd 综合后做 floorplan;(2) DRC 失败后调整 utilization 重生成;(3) 显式 /bb-create-floorplan。
从 MAS(clock_domains / io_timing / path_exceptions)派生 Synopsys SDC 时序约束文件,OpenSTA 语法校验。触发场景:(1) bba-guru-synthesis 综合前;(2) post-PD timing fail 修订约束;(3) 显式 /bb-create-sdc。
扫描 RTL 目录提取模块层次依赖,拓扑排序后写 file_list.f(叶模块在前,top 在最后),供 Yosys/Verilator 使用。触发场景:(1) bba-guru-rtl 生成 RTL 后生成 file_list;(2) 显式 /bb-find-module-deps。
| name | bb-code-review |
| description | 对抗性代码评审:代码质量 / 可维护性 / 时序风险 / 综合友好度 / MAS 对齐度。默认 ruthless 模式,找 EVERY flaw。触发场景:(1) RTL lint 后;(2) 显式 /bb-code-review。 |
| user-invocable | true |
读 RTL + MAS,对照设计意图做对抗评审,分维度给出 issues + severity + pass 判定。
bb-rtl-coder、用户bb-check-lint(lint 通过后)| arg | type | required | 默认 | 说明 |
|---|---|---|---|---|
| rtl_dir | path | true | — | designs/<name>/rtl/ |
| file_list | path | true | — | file_list.f |
| mas_path | path | true | — | designs/<name>/mas/mas.json |
| role | enum | false | ruthless | ruthless | linus | balanced |
| focus | string | false | timing,maintainability | 关注领域 |
| design_name | string | true | — | — |
| stamp | string | false | <auto> | — |
| field | 值 |
|---|---|
artifact_path | designs/<name>/rtl/code_review_<stamp>.md |
issues_found | int |
severity_summary | {critical,high,medium,low} |
timing_risks | list[str] |
maintainability_issues | list[str] |
synthesis_friendly | bool |
mas_alignment | full | partial | none |
pass | bool(critical==0 && high≤1) |
valid | bool |
| 角色 | 风格 | 适用 |
|---|---|---|
ruthless | 无赞美只挑刺,找 EVERY flaw | 默认,重大改动前压力测试 |
linus | 直接尖锐,技术导向 | 风格/架构决策 |
balanced | 承认优点+建议 | 常规评审 |
$PROJECT_SCRIPTS/build_prompt.py:
ROLE_PROMPTS = {
"ruthless": "Ruthless reviewer. Find EVERY flaw. No compliments.",
"linus": "Linus Torvalds. Direct, no-nonsense, technically harsh.",
"balanced": "Senior engineer. Constructive, acknowledge strengths.",
}
mas = json.load(open(mas_path))
rtl = {f: open(f).read() for f in cat(file_list)}
prompt = render_prompt(
role=role,
rtl=rtl,
mas=mas,
dimensions=["timing","maintainability","synthesis","mas_alignment"]
)
claude --print "<prompt>" > <artifact_path> 或 agent 内部生成。
$PROJECT_SCRIPTS/parse_review.py:
## Timing Risks / ## Maintainability 等)[CRITICAL] / [HIGH] / [MEDIUM] / [LOW]pass = (critical == 0 && high <= 1)返回 JSON。pass=false → bb-rtl-coder 反馈重生成(≤3 iter)。
| 维度 | 检查 |
|---|---|
| timing_risks | 长组合路径 / 无 pipeline / CDC 未处理 |
| maintainability | 深嵌套 / 大模块 / 命名 |
| synthesis_friendly | 非综合语法 / blackbox |
| mas_alignment | RTL ↔ MAS FSM/datapath 一致性 |
| traceability | REQ_ID 覆盖率 / 孤儿代码 / @requirement 注释完整性 |
| spec_header | Spec Header 完整性 / @spec_hash 一致性 / Key Constraints 覆盖 |
| selective_inline | 选择性内联合规(FSM/协议/datapath 必须标注,简单赋值不标注) |
| register_map | 寄存器定义 → 文档 + SVA 断言完整性 |
| sdc_traceability | SDC 约束 → REQ_ID 关联完整性 |
扫描 RTL 文件中的 @requirement 注释,与 MAS §10 追踪矩阵对比:
def check_traceability(rtl_files, mas_path):
"""检查 @requirement 注释覆盖率"""
# 1. 从 MAS §10 提取声明的 REQ_ID 列表
declared = extract_req_ids_from_mas(mas_path)
# 2. 从 RTL 扫描 @requirement 注释中的 REQ_ID
implemented = set()
for f in rtl_files:
for line in open(f):
if "@requirement" in line:
implemented |= extract_req_ids(line)
# 3. 计算覆盖率
coverage = len(declared & implemented) / len(declared) * 100
missing = declared - implemented
orphans = implemented - declared # 实现了但 MAS 未声明
return {
"coverage_pct": coverage,
"missing_reqs": sorted(missing),
"orphan_reqs": sorted(orphans),
}
无 @requirement 注释的代码块(排除 traceability/ignore.txt 白名单):
uv run $PROJECT_SCRIPTS/check_req_uniqueness.py
@verifies 覆盖率检查 RTL 中的 SVA 断言是否都包含 @verifies 标注:
def check_sva_verifies(rtl_files):
"""检查 SVA 断言的 @verifies 标注覆盖率"""
sva_count = 0 # assert property 总数
sva_with_verifies = 0 # 有 @verifies 的 assert property
for f in rtl_files:
lines = open(f).readlines()
for i, line in enumerate(lines):
if "assert property" in line or "assert(" in line:
sva_count += 1
# 检查前 3 行是否有 @verifies
context = "".join(lines[max(0,i-3):i+1])
if "@verifies" in context:
sva_with_verifies += 1
coverage = (sva_with_verifies / sva_count * 100) if sva_count > 0 else 100
return {
"sva_total": sva_count,
"sva_with_verifies": sva_with_verifies,
"coverage_pct": coverage,
}
在评审报告中增加章节:
## Traceability
- REQ_ID 覆盖率: 95% (19/20)
- SVA @verifies 覆盖率: 100% (15/15)
- 缺失 REQ_ID: REQ-M01-F05
- 孤儿代码: M99_Top.sv (无 @requirement)
- NEEDS_REVIEW: 无
| 标准 | 要求 |
|---|---|
| traceability 覆盖率 | ≥ 90% |
| SVA @verifies 覆盖率 | == 100% |
| 孤儿 REQ_ID | == 0 |
| Spec Header 完整性 | == 100%(每个模块必须有 Spec Header) |
| @spec_hash 一致性 | == 100%(所有 Spec Hash 必须与 spec 文件匹配) |
| 寄存器文档生成 | == 100%(每个有寄存器的模块必须有 regmap 文档) |
| SDC traceability | ≥ 90%(SDC 约束必须有 @requirement 标注) |
每个 RTL 文件头部必须包含 Spec Header,包含以下字段:
def check_spec_header(rtl_files):
"""检查 Spec Header 完整性"""
required_fields = [
"Module:", "Source:", "Version:", "Status:",
"Spec Hash:", "REQ Coverage:", "Purpose:",
"Key Constraints:", "Dependencies:", "Traceability:"
]
results = []
for f in rtl_files:
content = open(f).read()
# 检查是否包含所有必需字段
missing = [field for field in required_fields if field not in content]
if missing:
results.append({
"file": f,
"status": "FAIL",
"missing_fields": missing
})
else:
results.append({
"file": f,
"status": "PASS"
})
return results
def check_spec_hash_consistency(rtl_files):
"""验证 RTL 中的 @spec_hash 与 spec 文件是否一致"""
import subprocess, re
results = []
for f in rtl_files:
content = open(f).read()
# 提取 Source 和 Spec Hash
source_match = re.search(r'// Source:\s*(\S+)', content)
hash_match = re.search(r'// Spec Hash:\s*(sha256:[a-f0-9]+)', content)
if not source_match or not hash_match:
continue # 无 Spec Header,跳过
spec_file = source_match.group(1)
rtl_hash = hash_match.group(1)
# 计算 spec 文件实际 hash
result = subprocess.run(
["uv", "run", "$PROJECT_SCRIPTS/compute_spec_hash.py", spec_file],
capture_output=True, text=True
)
actual_hash = result.stdout.strip()
if rtl_hash != actual_hash:
results.append({
"file": f,
"status": "FAIL",
"rtl_hash": rtl_hash,
"spec_hash": actual_hash,
"fix": f"uv run $PROJECT_SCRIPTS/compute_spec_hash.py {spec_file} --inject {f}"
})
else:
results.append({
"file": f,
"status": "PASS"
})
return results
在评审报告中增加章节:
## Spec Header
- 完整性: 100% (8/8 模块)
- @spec_hash 一致性: 87.5% (7/8)
- 不一致文件:
- M01_DataflowController.sv: RTL=sha256:abc123, spec=sha256:def456
Fix: `uv run $PROJECT_SCRIPTS/compute_spec_hash.py spec/MAS/M01/MAS.md --inject rtl/M01.sv`
验证 RTL 文件遵循选择性内联标准:
def check_selective_inline(rtl_files):
"""检查选择性内联合规性"""
# 必须标注的代码块类型
must_annotate = [
r'always_ff.*case\s*\(', # FSM
r'valid\s*\|->', # 协议握手 (SVA)
r'always_ff.*posedge.*\b(stage|pipe)', # pipeline stages
]
# 不应标注的代码块类型
should_not_annotate = [
r'^\s*assign\s+\w+\s*=', # 简单 assign
r'^\s*parameter\s+', # 参数定义
r'^\s*localparam\s+', # 本地参数
]
results = []
for f in rtl_files:
lines = open(f).readlines()
for i, line in enumerate(lines):
# 检查必须标注的代码块是否有 @requirement
for pattern in must_annotate:
if re.search(pattern, line):
# 检查前 3 行是否有 @requirement
context = "".join(lines[max(0,i-3):i+1])
if "@requirement" not in context and "@verifies" not in context:
results.append({
"file": f,
"line": i+1,
"status": "MISSING",
"type": "must_annotate",
"code": line.strip()
})
return results
def check_register_traceability(design_name):
"""检查寄存器定义 → 文档 → SVA 断言完整性"""
mas_path = f"spec/MAS/{design_name}/MAS.md"
regmap_doc = f"doc/regmap/{design_name}.md"
regmap_sva = f"rtl/designs/{design_name}/rtl_src/{design_name}_regmap_assertions.sv"
# 1. 检查 MAS 中是否有寄存器定义
mas_content = open(mas_path).read()
has_reg_def = "## 5. 寄存器映射" in mas_content or "## 6. 寄存器定义" in mas_content
if not has_reg_def:
return {"status": "SKIP", "reason": "No register definition in MAS"}
# 2. 检查是否生成了寄存器文档
has_doc = os.path.exists(regmap_doc)
# 3. 检查是否生成了寄存器断言
has_sva = os.path.exists(regmap_sva)
# 4. 检查断言中的 @verifies 覆盖率
if has_sva:
sva_content = open(regmap_sva).read()
assert_count = sva_content.count("assert property")
verifies_count = sva_content.count("@verifies")
verifies_coverage = (verifies_count / assert_count * 100) if assert_count > 0 else 100
else:
verifies_coverage = 0
return {
"status": "PASS" if (has_doc and has_sva and verifies_coverage == 100) else "FAIL",
"has_reg_def": has_reg_def,
"has_doc": has_doc,
"has_sva": has_sva,
"verifies_coverage": verifies_coverage
}
def check_sdc_traceability(design_name):
"""检查 SDC 约束 → REQ_ID 关联完整性"""
sdc_path = f"designs/{design_name}/constraints/{design_name}.sdc"
if not os.path.exists(sdc_path):
return {"status": "SKIP", "reason": "No SDC file"}
sdc_content = open(sdc_path).read()
lines = sdc_content.splitlines()
# 统计 SDC 命令数量
sdc_commands = [
"create_clock", "set_input_delay", "set_output_delay",
"set_false_path", "set_multicycle_path", "set_clock_groups"
]
total_commands = 0
annotated_commands = 0
for i, line in enumerate(lines):
for cmd in sdc_commands:
if cmd in line:
total_commands += 1
# 检查前 5 行是否有 @requirement
context = "\n".join(lines[max(0,i-5):i+1])
if "@requirement" in context:
annotated_commands += 1
coverage = (annotated_commands / total_commands * 100) if total_commands > 0 else 100
return {
"status": "PASS" if coverage >= 90 else "FAIL",
"total_commands": total_commands,
"annotated_commands": annotated_commands,
"coverage_pct": coverage
}
## SDC Traceability
- SDC 命令总数: 12
- 已标注 @requirement: 11
- 覆盖率: 91.7%
- 未标注:
- Line 45: set_false_path -from [get_pins ...]
| 级别 | 通过 |
|---|---|
| critical | == 0 |
| high | ≤ 1 |
| 状态 | 行动 |
|---|---|
| pass=true | 写 rtl_artifact.json + 进下一阶段 |
| pass=false & iter<3 | 反馈 bb-rtl-coder 重生成 |
| iter≥3 | 开 arch-needs-fix |
PROJECT_SCRIPTS = {{ PROJECT_DIR }}/scripts
$PROJECT_SCRIPTS/build_prompt.py、$PROJECT_SCRIPTS/run_review.py、$PROJECT_SCRIPTS/parse_review.pyreferences/rtl_review_dimensions.mdreferences/role_personas.md — 三角色详细提示词项目级 Coding Style 参考:
wiki/codingstyle/systemverilog_styleguide.md — SystemVerilog Style Guide (systemverilog.io)wiki/codingstyle/freescale_verilog_standard.md — Freescale Verilog HDL Coding Standard SRS V3.2