From 330749a3b0603cff6dca82d8488b97a9a9aaf119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Wed, 23 Sep 2026 11:28:21 +0200 Subject: [PATCH] tinyRocket: the tag_array override carries the pins and geometry it needs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit asap7/tinyRocket force-converts tag_array through ADDITIONAL_MEMORIES, because the RTL gives that wrapper no behavioral body: it instantiates a tag_array_ext the sources never define. Detection finds memories by their inferred $mem_v2 cells and tag_array has none, so the override is taken whole (schema.merge: "it must then carry pins and geometry itself to be emittable"). It carried only name, idiomatic and reason, and gen_memories stopped in validate_emittable: schema.SchemaError: memory tag_array: no pins The override now carries what the module boundary in freechips.rocketchip.system.TinyConfig.v says: one read-write port, rows 4 (addr_w 2), bits 25, and the six RW0 pins, no mask. schema_test.py gains TinyRocketTagArrayTest: the override taken whole is emittable, and its pins equal the tag_array module's ports read from the RTL, so the data cannot drift from the design. Both fail before this change. Co-Authored-By: Claude Opus 5.5 (1M context) Signed-off-by: Øyvind Harboe --- .../asap7/tinyRocket/tag_array.memories | 51 +++++++++++++++++++ flow/scripts/memories/schema_test.py | 42 +++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/flow/designs/asap7/tinyRocket/tag_array.memories b/flow/designs/asap7/tinyRocket/tag_array.memories index fc03b36d73..5c5e482d48 100644 --- a/flow/designs/asap7/tinyRocket/tag_array.memories +++ b/flow/designs/asap7/tinyRocket/tag_array.memories @@ -3,6 +3,57 @@ "memories": [ { "name": "tag_array", + "rows": 4, + "bits": 25, + "addr_w": 2, + "read_ports": 0, + "write_ports": 0, + "rw_ports": 1, + "mask_lanes": 0, + "pins": [ + { + "name": "RW0_addr", + "direction": "input", + "width": 2, + "port_id": "RW0", + "function": "addr" + }, + { + "name": "RW0_en", + "direction": "input", + "width": 1, + "port_id": "RW0", + "function": "en" + }, + { + "name": "RW0_clk", + "direction": "input", + "width": 1, + "port_id": "RW0", + "function": "clk" + }, + { + "name": "RW0_wmode", + "direction": "input", + "width": 1, + "port_id": "RW0", + "function": "wmode" + }, + { + "name": "RW0_wdata_0", + "direction": "input", + "width": 25, + "port_id": "RW0", + "function": "data_in" + }, + { + "name": "RW0_rdata_0", + "direction": "output", + "width": 25, + "port_id": "RW0", + "function": "data_out" + } + ], "idiomatic": true, "reason": "forced: the RTL provides no behavioral fallback for this wrapper" } diff --git a/flow/scripts/memories/schema_test.py b/flow/scripts/memories/schema_test.py index 31775f1b01..ccf0211267 100644 --- a/flow/scripts/memories/schema_test.py +++ b/flow/scripts/memories/schema_test.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import json +import re import sys import tempfile import unittest @@ -116,5 +117,46 @@ def test_validate_emittable(self): schema.validate_emittable(dataless) +FLOW_DIR = Path(__file__).resolve().parents[2] + + +def module_ports(verilog: Path, module: str) -> dict[str, tuple[str, int]]: + """{name: (direction, width)} from an ANSI-style module header.""" + ports = {} + in_header = False + for line in verilog.read_text().splitlines(): + if line.startswith(f"module {module}("): + in_header = True + continue + if in_header: + if line.startswith(");"): + return ports + m = re.match(r"\s*(input|output)\s+(?:\[(\d+):0\])?\s*(\w+)", line) + if m: + direction, msb, name = m.groups() + ports[name] = (direction, int(msb) + 1 if msb else 1) + raise AssertionError(f"module {module} not found in {verilog}") + + +class TinyRocketTagArrayTest(unittest.TestCase): + """tinyRocket's tag_array wrapper has no inferred memory for detection + to find, so its override is taken whole and must be emittable on its + own, with the pins of the module it replaces.""" + + def setUp(self): + path = FLOW_DIR / "designs/asap7/tinyRocket/tag_array.memories" + (self.mem,) = schema.merge([], schema.load(path)) + + def test_override_is_emittable(self): + schema.validate_emittable(self.mem) + + def test_pins_match_the_rtl(self): + rtl = ( + FLOW_DIR / "designs/src/tinyRocket/freechips.rocketchip.system.TinyConfig.v" + ) + pins = {p.name: (p.direction, p.width) for p in self.mem.pins} + self.assertEqual(pins, module_ports(rtl, "tag_array")) + + if __name__ == "__main__": unittest.main()