TODO section 33. Every rule states a Severity (error: would likely fail
to compile or elaborate, or silently mis-synthesize; warning: a probable
bug; style), printed in lucisv check text and JSON, mapped to
ERROR/WARNING/INFORMATION in the editor, grouped in --rules-doc, and
accepted by --select/--ignore and [lint] as a class word. VS Code gains
lucisv.lint.severity.{error,warning,style} and one tri-state
lucisv.lint.rules.<rule> per rule (default/on/off - a client sends
every key, so a boolean cannot say unset), generated by
vlog_linter::vscode with a drift test, and lint::enabled_rules is the
one documented ladder: defaults -> select -> class switches -> per-rule
-> ignore. Nineteen new rules (17 -> 36), one file each with true
positives and near-misses: Error - mismatched-labels,
duplicate-declaration (Semantics::duplicates(), additive),
undeclared-identifier (with a project; silent for macro text, included
fragments, hierarchical tails, any name another file mentions),
unknown-port, unknown-parameter; Warning - forbid-defparam,
invalid-system-task-function, truncated-numeric-literal,
undersized-binary-literal (safe fix), suspicious-semicolon,
packed-dimensions-range-ordering, module-port, module-parameter,
explicit-function-task-parameter-type, plusarg-assignment,
instance-shadowing, forbid-negative-array-dim, void-cast,
incomplete-assignment. Every false-positive class found on opentitan
closed with a named test; 3 383 tests / 48 binaries; corpus 814/820
and byte-identical (formatter untouched); vsix smoke OK.
docs/features/linter-expansion-1/README.md.
Co-Authored-By: Claude Fable 5 <[email protected]>
106 lines
3.4 KiB
Rust
106 lines
3.4 KiB
Rust
//! `always-ff-non-blocking` — clocked logic assigns with `<=`.
|
|
|
|
use crate::context::LintContext;
|
|
use crate::registry::Rule;
|
|
use crate::severity::Severity;
|
|
use crate::violation::Violation;
|
|
use crate::visit::{walk_items, walk_stmts};
|
|
use vlog_parser::ast::{ItemKind, StmtKind};
|
|
|
|
/// See [`Rule::doc`].
|
|
pub struct AlwaysFfNonBlocking;
|
|
|
|
const NAME: &str = "always-ff-non-blocking";
|
|
|
|
impl Rule for AlwaysFfNonBlocking {
|
|
fn name(&self) -> &'static str {
|
|
NAME
|
|
}
|
|
|
|
fn summary(&self) -> &'static str {
|
|
"assign with `<=` inside always_ff"
|
|
}
|
|
|
|
fn severity(&self) -> Severity {
|
|
Severity::Warning
|
|
}
|
|
|
|
fn doc(&self) -> &'static str {
|
|
"A blocking assignment in a clocked block updates immediately, so two \
|
|
flops written in one `always_ff` can see each other's new value in \
|
|
simulation while the synthesized netlist shows the old one — the \
|
|
canonical simulation/synthesis mismatch. Verible's style guide, like \
|
|
every RTL guide since Cummings' paper, asks for `<=` in sequential \
|
|
blocks and `=` in combinational ones. No automatic fix: swapping the \
|
|
operator changes what the circuit does, which is exactly the kind of \
|
|
edit a human has to make."
|
|
}
|
|
|
|
fn check(&self, ctx: &LintContext) -> Vec<Violation> {
|
|
let mut out = Vec::new();
|
|
walk_items(ctx.file(), &mut |item| {
|
|
let ItemKind::Always { kw, stmt } = &item.kind else { return };
|
|
if kw != "always_ff" {
|
|
return;
|
|
}
|
|
walk_stmts(stmt, &mut |inner| {
|
|
if let StmtKind::Assign { op, .. } = &inner.kind {
|
|
if op != "<=" {
|
|
out.push(Violation::new(
|
|
NAME,
|
|
format!("blocking assignment `{op}` in `always_ff`; use `<=`"),
|
|
inner.span,
|
|
));
|
|
}
|
|
}
|
|
});
|
|
});
|
|
out
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
fn violations(src: &str) -> Vec<Violation> {
|
|
AlwaysFfNonBlocking.check(&LintContext::new(src, None))
|
|
}
|
|
|
|
fn wrap(body: &str) -> String {
|
|
format!("module m;\n always_ff @(posedge clk) begin\n{body} end\nendmodule\n")
|
|
}
|
|
|
|
#[test]
|
|
fn flags_a_blocking_assignment() {
|
|
let found = violations(&wrap(" q = d;\n"));
|
|
assert_eq!(found.len(), 1);
|
|
assert!(found[0].message.contains("`=`"), "{}", found[0].message);
|
|
assert!(found[0].fix.is_none(), "changing the operator changes the circuit");
|
|
}
|
|
|
|
#[test]
|
|
fn compound_assignments_are_blocking_too() {
|
|
assert_eq!(violations(&wrap(" q += 1;\n")).len(), 1);
|
|
}
|
|
|
|
#[test]
|
|
fn nonblocking_is_clean() {
|
|
assert!(violations(&wrap(" q <= d;\n")).is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn a_loop_variable_is_not_an_assignment_statement() {
|
|
// `for (int i = 0; i < 4; i++)` is loop syntax, not a procedural
|
|
// assignment, so it must not be flagged.
|
|
let src = wrap(" for (int i = 0; i < 4; i++) q[i] <= d[i];\n");
|
|
assert!(violations(&src).is_empty(), "{:?}", violations(&src));
|
|
}
|
|
|
|
#[test]
|
|
fn other_process_kinds_are_left_to_their_own_rules() {
|
|
let src = "module m;\n always_comb q = d;\n initial q = 0;\nendmodule\n";
|
|
assert!(violations(src).is_empty());
|
|
}
|
|
}
|