From 0ee1fef1ae7dc11ca706d496c5a59ebba9e5ce80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 19 May 2026 13:58:18 +0200 Subject: [PATCH] synth: error on typos in SYNTH_KEEP_MODULES MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Today a name in SYNTH_KEEP_MODULES that doesn't exist in the elaborated design (typo, post-refactor rename, wrong-design list) produces only a yosys warning from `select` -- the whole keep silently turns into a no-op and the design flattens. Catch this by passing `-assert-any` to the two-pattern `select` so an empty selection becomes a hard error. Skip the strict check in partition mode (SYNTH_BLACKBOXES set): the same SYNTH_KEEP_MODULES list is reused across partitions and other partitions' kept modules are legitimately absent from this partition's RTLIL. Collect all missing names and report them in one error rather than failing on the first -- much friendlier when several names have drifted. Signed-off-by: Øyvind Harboe --- flow/scripts/synth.tcl | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/flow/scripts/synth.tcl b/flow/scripts/synth.tcl index fa79829904..98da8dfa46 100644 --- a/flow/scripts/synth.tcl +++ b/flow/scripts/synth.tcl @@ -73,6 +73,15 @@ if { $::env(SYNTH_GUT) } { } if { [env_var_exists_and_non_empty SYNTH_KEEP_MODULES] } { + # In partition mode (SYNTH_BLACKBOXES set) only this partition's top + # module plus its own subhierarchy is present; the other kept modules + # are blackboxed and won't be found. The same SYNTH_KEEP_MODULES list + # is reused across partitions, so a missing name there is expected. + # Outside partition mode, a missing name is almost certainly a typo or + # a stale post-refactor reference, and silently skipping it turns the + # whole keep into a no-op -- collect all missing names and fail loudly. + set strict [expr { ![env_var_exists_and_non_empty SYNTH_BLACKBOXES] }] + set missing [list] foreach module $::env(SYNTH_KEEP_MODULES) { # Two patterns so both frontends work: # - `$module` matches the bare name produced by verilog. @@ -87,10 +96,26 @@ if { [env_var_exists_and_non_empty SYNTH_KEEP_MODULES] } { # other pattern still applies -- no regression for non-slang. # `-module ` would error if the module doesn't exist, which # is why we use bare patterns instead. - select "$module" "$module\\\$*" + if { $strict } { + # `-assert-any` errors out if neither pattern matched. Catch so + # all missing names are reported in one consolidated error rather + # than failing on the first. + if { [catch { select -assert-any "$module" "$module\\\$*" }] } { + lappend missing $module + select -clear + continue + } + } else { + select "$module" "$module\\\$*" + } setattr -mod -set keep_hierarchy 1 select -clear } + if { [llength $missing] > 0 } { + error "SYNTH_KEEP_MODULES contains [llength $missing] module name(s)\ + not present in the elaborated design (typos, post-refactor renames,\ + or wrong-design list): [join $missing {, }]" + } } if { [env_var_exists_and_non_empty SYNTH_HIER_SEPARATOR] } {