Skip to content

Commit 66ad0a2

Browse files
wanda-phiwhitequark
authored andcommitted
build: get list of used I/O ports from Design.
Fixes #1365.
1 parent 86fdaba commit 66ad0a2

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

amaranth/build/plat.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def __init__(self):
3434
self.extra_files = OrderedDict()
3535

3636
self._prepared = False
37+
self._design = None
3738

3839
@property
3940
def default_clk_constraint(self):
@@ -148,9 +149,16 @@ def missing_domain_error(name):
148149
buffer = DomainLowerer()(buffer)
149150
fragment.add_subfragment(buffer, name=f"pin_{pin.name}")
150151

151-
ports = [(port.name, port, None) for port in self.iter_ports()]
152-
design = Design(fragment, ports, hierarchy=(name,))
153-
return self.toolchain_prepare(design, name, **kwargs)
152+
self._design = Design(fragment, [], hierarchy=(name,))
153+
return self.toolchain_prepare(self._design, name, **kwargs)
154+
155+
def iter_port_constraints_bits(self):
156+
for (name, port, _dir) in self._design.ports:
157+
if len(port) == 1:
158+
yield name, port.metadata[0].name, port.metadata[0].attrs
159+
else:
160+
for bit, meta in enumerate(port.metadata):
161+
yield f"{name}[{bit}]", meta.name, meta.attrs
154162

155163
@abstractmethod
156164
def toolchain_prepare(self, fragment, name, **kwargs):

amaranth/build/res.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ def __init__(self, resources, connectors):
107107
self.connectors = OrderedDict()
108108
self._conn_pins = OrderedDict()
109109

110-
# List of all IOPort instances created
111-
self._ports = []
112110
# List of (pin, port, buffer) pairs for non-dir="-" requests.
113111
self._pins = []
114112
# Constraint list
@@ -220,7 +218,6 @@ def resolve(resource, dir, xdr, path, attrs):
220218
PortMetadata(name, attrs)
221219
for name in phys_names
222220
])
223-
self._ports.append(iop)
224221
port = io.SingleEndedPort(iop, invert=phys.invert, direction=direction)
225222
if isinstance(phys, DiffPairs):
226223
phys_names_p = phys.p.map_names(self._conn_pins, resource)
@@ -234,7 +231,6 @@ def resolve(resource, dir, xdr, path, attrs):
234231
PortMetadata(name, attrs)
235232
for name in phys_names_n
236233
])
237-
self._ports += [p, n]
238234
port = io.DifferentialPort(p, n, invert=phys.invert, direction=direction)
239235

240236
for phys_name in phys_names:
@@ -274,17 +270,6 @@ def resolve(resource, dir, xdr, path, attrs):
274270
def iter_pins(self):
275271
yield from self._pins
276272

277-
def iter_ports(self):
278-
yield from self._ports
279-
280-
def iter_port_constraints_bits(self):
281-
for port in self._ports:
282-
if len(port) == 1:
283-
yield port.name, port.metadata[0].name, port.metadata[0].attrs
284-
else:
285-
for bit, meta in enumerate(port.metadata):
286-
yield f"{port.name}[{bit}]", meta.name, meta.attrs
287-
288273
def add_clock_constraint(self, clock, frequency):
289274
if isinstance(clock, ClockSignal):
290275
raise TypeError(f"A clock constraint can only be applied to a Signal, but a "

0 commit comments

Comments
 (0)