readable-verilog-generator
VerifiedUse when creating, writing, reviewing, annotating, repairing, refactoring, or validating readable Verilog RTL, including synthesizable Verilog-2001 .v files, existing-RTL analysis, semantic comment annotation, testbench scaffold planning, ASIC-quality review, local or remote Vivado/xsim validation, evidence-backed repair, and workflow trace diagnosis.
references/rules/verilog-comment-placement.md
View on GitHub# Verilog Comment Placement Contract
Use this reference when generating, reviewing, or validating comments in generated RTL and testbench `.v` files.
The comment gate checks placement and basic usefulness at the code-entity level. Parameters, ports, declarations, assigns, FSM branches, instances, generate blocks, and non-trivial procedural blocks need comments that explain intent, ownership, reset/enable behavior, or interface meaning. Do not add mechanical comments to every syntax-only line merely to satisfy density. Pure comments may introduce a block, but they do not satisfy unrelated entities.
## Strict Placement Rules
- Block comments are forbidden. Any `/*` or `*/` marker fails the gate; use `//` only.
- Signal definitions, including `reg`, `wire`, `integer`, `real`, `input`, `output`, and `inout`, require same-line right-side comments.
- Assign statements and assignments inside `always`, `function`, `task`, `generate`, or `initial` blocks require same-line right-side comments.
- `parameter` and `localparam` definitions require same-line right-side comments.
- Instance `.formal(actual)` parameter and port mappings require same-line right-side comments.
- Same-line `//` markers align to the current region banner right-side `//` display column. If the code is too long, the marker may move right, but it must not be left of that anchor.
- Leading comments for `always`, `function`, `task`, `generate`, `initial`, `case(state_current)` branches (`ST_*:begin` and `default:begin`), definition groups, and instances sit immediately above the target, align with the target start column, and have exactly one blank line above unless they directly follow a region banner.
- The formatter binds pure comments immediately before a `case` item to that item and emits them before the label at the item indentation. A same-line label comment is normalized to the same leading position, while a comment between a label-only item and its first body statement remains the first child of that body. Comments that cannot be bound before `endcase` fail closed instead of being discarded.
- Formatting a `case` statement must converge in one pass: a second formatter pass produces byte-identical output, including the leading comments for `ST_*` and `default` items.
- If a pure comment introduces an `assign` subgroup, it is optional, but once written it must follow the same one-blank-line rule above the comment unless it directly follows a region banner or a stacked pure-comment group.
- Parameter and signal definition sections require a pure group comment above each group. A region banner is only an anchor and does not satisfy the group-comment requirement. Module instances require a pure function comment above the instance.
- When a `parameter_check` region exists, place it as the final internal region before `endmodule`, and keep each parameter-check branch comment adjacent to the concrete constraint it explains.
- Entity comments must be unique to the hardware object they describe. Reusing the same sentence, a numbered variant, or a lightly edited template across parameters, ports, signals, assigns, procedural assignments, or instance mappings fails `VG066` in strict mode.
## Gate Ownership
- `VG063` keeps ownership of leading-comment adjacency, alignment, and blank-line layout for procedural blocks, instances, and `case(state_current)` branches via `comments.case_branch_leading_comment`.
- The formatter AST stores comments bound before a branch label on the corresponding `CaseItem.leading_comments`; renderers must preserve that field before the item label so formatter output cannot create a later `VG063` violation.
- `VG067` owns pure `assign` subgroup spacing via `comments.assign_group_spacing`. The gate does not require every `assign` subgroup to exist; it only constrains the layout when such a pure comment is present.
- `VG150` owns semantic-integrity checks for formatter-bound entity comments. Configured workflow evidence phrases are reported on their entity line, while unrelated tail strings are blocked only after the same entity category forms the configured high-confidence rotation family; banners and ordinary Chinese descriptions remain outside this detector.
- `VG054` keeps ownership of next-state defaults, holds, and branch closure. `VG144` additionally requires a separate procedural combinational next-state process, forbids continuous assignment to `state_next`, and requires blocking `state_next = ...;` assignments in that process.
## Placement Matrix
- File header: keep the fixed bilingual header at the file top when `rtl_style_profile=erie_strict`; describe module purpose, version, revision date, and history there.
- Macro: single-line `define` uses a same-line comment. Multiline backslash macros use one pure leading comment bound to the macro name; continuation lines should not carry inline explanatory comments.
- Module: the `module <name>` declaration is covered by the fixed bilingual header and nearby module-purpose comment. `endmodule` may carry a close phrase when it improves readability, but do not add noise to trivial closures.
- Parameter and localparam: each definition uses a same-line comment explaining configurability or state meaning.
- Port: group protocol/channel ports with pure comments; each port line still uses a same-line comment explaining direction, role, validity condition, or width meaning.
- Signal: each `reg`, `wire`, `integer`, and `genvar` declaration uses a same-line comment explaining driver, purpose, or clock domain.
- Assign: each `assign` line uses a same-line comment explaining the left-hand output and source semantics. If a pure comment introduces an `assign` subgroup, it follows the `VG067` one-blank-line-or-region-banner rule.
- Region banner: banners are navigation only and never replace same-line comments on code statements.
- Always and initial: a pure leading block-purpose comment is required for non-trivial blocks; it should explain combinational/sequential intent, trigger, target register family, or test phase. Parameter-check `initial` blocks should state which constraint family they enforce.
- FSM and case: each FSM block has a fixed block comment; `case` comments name the selector; every `ST_*:begin` and `default:begin` branch under `case(state_current)` has a pure leading comment immediately above it, aligned with the branch label, and explains the transition or output behavior when the branch is not self-evident.
- If and else: branch comments explain reset, enable, exception, or default behavior when that intent is not already clear from the nearby entity comment. Do not comment every `end` line mechanically.
- Instance: add a pure leading instance-purpose comment; instance, parameter mapping, and port mapping lines use same-line comments.
- Generate: branches use `gen_` labels and same-line comments; `endgenerate` names the generated structure being closed.
- Task and function: generated RTL forbids `task` and `function`. Testbenches may use helpers only with a pure leading purpose comment plus same-line comments on declaration, body, local signals, and end lines.
- Testbench statements: stimulus, checks, PASS/FAIL reporting, timeout, waveform setup, and finish calls use same-line comments explaining verification purpose. Human-readable Verilog `$display` messages must start with ` > INFO: [Verilog]`, ` > WARNING: [Verilog]`, or ` > ERR: [Verilog]`; machine-readable transcript tags such as `VERILOG-GEN-RESULT` stay exempt.
## Rejected Comment Forms
- Generic filler such as "line comment", "generic comment", "placeholder", "reset", "state task", or "bypass path".
- Formatter fallback comments such as `parameter`, `port signal`, `signal`, `assign`, `output bridge`, or `internal output signal`.
- Hollow Chinese comments whose meaning is only "Chinese comment", "signal comment", "logic handling", "module logic", "data handling", or "port description".
- Exact or near-duplicate entity comments after removing decorative dashes, numbering, identifier-only noise, and zero-width characters.
- Workflow/evidence slogans attached to an RTL entity, or a fixed-length periodic tail family that is unrelated to that entity's meaning; the detector is configuration-driven and does not reject an isolated Chinese word by itself.
- A pure comment placed between two code lines and reused for both.
- Mechanical line-by-line comments that restate syntax without design meaning.
- A continuation comment on a multiline macro that can hide or break backslash continuation semantics.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| planning-and-task-breakdownaddyosmani/agent-skillsBreaks work into ordered tasks. Use when you have a spec or clear requirements and need to break work into implementable tasks. Use when a task feels too large to start, when you need to estimate scope, or when parallel work is possible. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| screenpipethedotmack/claude-memSearch screen and audio history recorded by Screenpipe and optionally save selected context into claude-mem. Use when the user asks to recall desktop activity, a meeting, or something seen in another app through Screenpipe. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| contact-widgetnexu-io/open-designSelf-contained floating chat widget with welcome screen, social links, meeting button, and message input. Single HTML file, zero dependencies. | Stars: 108k | Updated | Claude CodeCodex | Verified | Install |
| meeting-notesnexu-io/open-designMeeting notes page — title bar with attendees, agenda checklist, decisions block, action items table with owners + dates, and a "next meeting" footer. Use when the brief mentions "meeting notes", "minutes", "1:1 notes", "all-hands recap", or "会议纪要". | Stars: 108k | Updated | Claude CodeCodex | Verified | Install |