Skip to content

Commit 0ee1fef

Browse files
committed
synth: error on typos in SYNTH_KEEP_MODULES
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 <oyvind.harboe@zylin.com>
1 parent 74b5f96 commit 0ee1fef

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

flow/scripts/synth.tcl

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ if { $::env(SYNTH_GUT) } {
7373
}
7474

7575
if { [env_var_exists_and_non_empty SYNTH_KEEP_MODULES] } {
76+
# In partition mode (SYNTH_BLACKBOXES set) only this partition's top
77+
# module plus its own subhierarchy is present; the other kept modules
78+
# are blackboxed and won't be found. The same SYNTH_KEEP_MODULES list
79+
# is reused across partitions, so a missing name there is expected.
80+
# Outside partition mode, a missing name is almost certainly a typo or
81+
# a stale post-refactor reference, and silently skipping it turns the
82+
# whole keep into a no-op -- collect all missing names and fail loudly.
83+
set strict [expr { ![env_var_exists_and_non_empty SYNTH_BLACKBOXES] }]
84+
set missing [list]
7685
foreach module $::env(SYNTH_KEEP_MODULES) {
7786
# Two patterns so both frontends work:
7887
# - `$module` matches the bare name produced by verilog.
@@ -87,10 +96,26 @@ if { [env_var_exists_and_non_empty SYNTH_KEEP_MODULES] } {
8796
# other pattern still applies -- no regression for non-slang.
8897
# `-module <name>` would error if the module doesn't exist, which
8998
# is why we use bare patterns instead.
90-
select "$module" "$module\\\$*"
99+
if { $strict } {
100+
# `-assert-any` errors out if neither pattern matched. Catch so
101+
# all missing names are reported in one consolidated error rather
102+
# than failing on the first.
103+
if { [catch { select -assert-any "$module" "$module\\\$*" }] } {
104+
lappend missing $module
105+
select -clear
106+
continue
107+
}
108+
} else {
109+
select "$module" "$module\\\$*"
110+
}
91111
setattr -mod -set keep_hierarchy 1
92112
select -clear
93113
}
114+
if { [llength $missing] > 0 } {
115+
error "SYNTH_KEEP_MODULES contains [llength $missing] module name(s)\
116+
not present in the elaborated design (typos, post-refactor renames,\
117+
or wrong-design list): [join $missing {, }]"
118+
}
94119
}
95120

96121
if { [env_var_exists_and_non_empty SYNTH_HIER_SEPARATOR] } {

0 commit comments

Comments
 (0)