Repository navigation
AUTO_MEMORIES: stop when a module to blackbox is not a black box #4661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
maliberty
merged 4 commits into
The-OpenROAD-Project:master
from
oharboe:auto-memories-blackbox-check
Oct 22, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cdbad67
AUTO_MEMORIES: stop when a module to blackbox is not a black box
oharboe 101c1ff
AUTO_MEMORIES: an escaped black box matches its unescaped name
oharboe 43f95a2
AUTO_MEMORIES: nothing to check without names; trim each listed module
oharboe 5b1a0b6
Merge remote-tracking branch 'origin/master' into auto-memories-black…
oharboe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # AUTO_MEMORIES: stop when a module synthesis was told to blackbox is not | ||
| # a black box of the design. | ||
| # | ||
| # read_slang's --blackboxed-module ignores a name it does not know. A | ||
| # name in blackboxes.txt that is not the module's definition -- a slang | ||
| # per-instance name, a typo, a module the sources no longer have -- leaves | ||
| # the memory's behavioral body in place, and the flow says so only much | ||
| # later, as a memory over SYNTH_MEMORY_MAX_BITS with no hint of why. Run | ||
| # after the sources are read; `names` is the blackboxes.txt list. | ||
| proc auto_memories_check_blackboxed { names } { | ||
| if { [llength $names] == 0 } { | ||
| return | ||
| } | ||
| # yosys lists an escaped module with its leading backslash (`\1d_ram`); | ||
| # blackboxes.txt names it as read_slang takes it (`1d_ram`). | ||
| set blackboxed {} | ||
| foreach m [split [tee -q -s result.string select -list-mod =A:blackbox] "\n"] { | ||
| set m [string trim $m] | ||
| if { $m ne "" } { | ||
| lappend blackboxed [regsub {^\\} $m {}] | ||
| } | ||
| } | ||
| set missing {} | ||
| foreach m $names { | ||
| if { [lsearch -exact $blackboxed $m] < 0 } { | ||
| lappend missing $m | ||
| } | ||
| } | ||
| if { [llength $missing] > 0 } { | ||
| error "AUTO_MEMORIES: not a black box of the design after reading the\ | ||
| sources, so its behavioral body would be synthesized:\ | ||
| [join $missing {, }]" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| #!/usr/bin/env python3 | ||
| """AUTO_MEMORIES stops synthesis when a module it asks read_slang to | ||
| blackbox is not a black box of the design. | ||
|
|
||
| read_slang's --blackboxed-module ignores a name it does not know, and | ||
| slang names a module per instance, `<definition>$<instance path>`. Only | ||
| the definition's name blackboxes the memory; any other name must stop | ||
| the flow right after the sources are read, naming the module. | ||
|
|
||
| Skipped when no yosys with read_slang is available: YOSYS_EXE or yosys on | ||
| PATH, with the plugin from SLANG_PLUGIN_PATH when read_slang is not built | ||
| in. | ||
| """ | ||
|
|
||
| import os | ||
| import shutil | ||
| import subprocess | ||
| import tempfile | ||
| import unittest | ||
|
|
||
| CHECK_TCL = os.path.join( | ||
| os.path.dirname(os.path.abspath(__file__)), | ||
| "..", | ||
| "scripts", | ||
| "memories", | ||
| "check_blackboxed.tcl", | ||
| ) | ||
|
|
||
| DESIGN = """\ | ||
| module ram (input clk, input we, input [5:0] addr, input [15:0] d, | ||
| output logic [15:0] q); | ||
| logic [15:0] mem [0:63]; | ||
| always_ff @(posedge clk) begin | ||
| if (we) mem[addr] <= d; | ||
| q <= mem[addr]; | ||
| end | ||
| endmodule | ||
| module \\1d_ram (input clk, input we, input [5:0] addr, input [15:0] d, | ||
| output logic [15:0] q); | ||
| logic [15:0] mem [0:63]; | ||
| always_ff @(posedge clk) begin | ||
| if (we) mem[addr] <= d; | ||
| q <= mem[addr]; | ||
| end | ||
| endmodule | ||
| module top (input clk, input we, input [5:0] addr, input [15:0] d, | ||
| output [15:0] q0, q1, q2); | ||
| ram u0 (.clk, .we, .addr, .d, .q(q0)); | ||
| ram u1 (.clk, .we, .addr, .d, .q(q1)); | ||
| \\1d_ram u2 (.clk, .we, .addr, .d, .q(q2)); | ||
| endmodule | ||
| """ | ||
|
|
||
|
|
||
| def yosys_command(): | ||
| yosys = os.environ.get("YOSYS_EXE") or shutil.which("yosys") | ||
| if not yosys: | ||
| return None | ||
| cmd = [yosys, "-q"] | ||
| plugin = os.environ.get("SLANG_PLUGIN_PATH") | ||
| if plugin: | ||
| cmd += ["-m", plugin] | ||
| probe = subprocess.run(cmd + ["-p", "help read_slang"], capture_output=True) | ||
| return cmd if probe.returncode == 0 else None | ||
|
|
||
|
|
||
| class TestAutoMemoriesBlackboxed(unittest.TestCase): | ||
| def run_check(self, names): | ||
| cmd = yosys_command() | ||
| if cmd is None: | ||
| self.skipTest("no yosys with read_slang") | ||
| with tempfile.TemporaryDirectory() as tmp: | ||
| design = os.path.join(tmp, "top.sv") | ||
| with open(design, "w") as f: | ||
| f.write(DESIGN) | ||
| braced = [f"{{{n}}}" for n in names] | ||
| blackboxed = " ".join(f"--blackboxed-module {n}" for n in braced) | ||
| script = os.path.join(tmp, "check.tcl") | ||
| with open(script, "w") as f: | ||
| f.write( | ||
| "yosys -import\n" | ||
| f"source {{{CHECK_TCL}}}\n" | ||
| f"yosys read_slang --keep-hierarchy --top top {blackboxed}" | ||
| f" {{{design}}}\n" | ||
| f"auto_memories_check_blackboxed [list {' '.join(braced)}]\n" | ||
| ) | ||
| result = subprocess.run( | ||
| cmd + ["-c", script], capture_output=True, text=True | ||
| ) | ||
| return result.returncode, result.stdout + result.stderr | ||
|
|
||
| def test_definition_name_is_blackboxed(self): | ||
| returncode, output = self.run_check(["ram"]) | ||
| self.assertEqual(returncode, 0, output) | ||
|
|
||
| def test_escaped_definition_name_is_blackboxed(self): | ||
| # read_slang takes `\1d_ram` as `1d_ram`; yosys lists it escaped | ||
| returncode, output = self.run_check(["ram", "1d_ram"]) | ||
| self.assertEqual(returncode, 0, output) | ||
|
|
||
| def test_per_instance_name_stops_the_flow(self): | ||
| returncode, output = self.run_check(["ram$top.u0", "ram$top.u1"]) | ||
| self.assertNotEqual(returncode, 0, output) | ||
| self.assertIn("not a black box of the design", output) | ||
| self.assertIn("ram$top.u0, ram$top.u1", output) | ||
|
|
||
| def test_unknown_name_stops_the_flow(self): | ||
| returncode, output = self.run_check(["no_such_module"]) | ||
| self.assertNotEqual(returncode, 0, output) | ||
| self.assertIn("no_such_module", output) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.