Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion flow/scripts/synth.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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] }]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for determining strict mode relies on SYNTH_BLACKBOXES being non-empty. While this is generally true in partition mode, it might be safer to explicitly check if the design is being synthesized in a parallel/partitioned context if such a variable exists, to avoid false positives if SYNTH_BLACKBOXES is empty but partition mode is intended.

set missing [list]
foreach module $::env(SYNTH_KEEP_MODULES) {
# Two patterns so both frontends work:
# - `$module` matches the bare name produced by verilog.
Expand All @@ -87,10 +96,26 @@ if { [env_var_exists_and_non_empty SYNTH_KEEP_MODULES] } {
# other pattern still applies -- no regression for non-slang.
# `-module <name>` 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
}
Comment on lines +103 to +107

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using catch around select -assert-any is an effective way to collect all missing modules before failing. However, ensure that select -assert-any does not leave the Yosys selection stack in an inconsistent state upon failure. Note that providing multiple patterns to select results in a union, which affects how -assert-any behaves. While select -clear is called at line 105, it might be worth verifying if Yosys selection state is fully reset when an assertion fails inside a catch block.

References
  1. In Yosys, providing multiple patterns as separate arguments to the select command results in the union of the selections.

} 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] } {
Expand Down