# Collect all signals we're driving (on LHS of statements), and signals we're using
# (on RHS of statements, or in clock domains).
- if isinstance(self, Instance):
- for port_name, (value, dir) in self.named_ports.items():
- if dir == "i":
- add_uses(value._rhs_signals())
- if dir == "o":
- add_defs(value._lhs_signals())
- if dir == "io":
- add_io(value)
- else:
- for stmt in self.statements:
- add_uses(stmt._rhs_signals())
- add_defs(stmt._lhs_signals())
+ for stmt in self.statements:
+ add_uses(stmt._rhs_signals())
+ add_defs(stmt._lhs_signals())
- for domain, _ in self.iter_sync():
- cd = self.domains[domain]
- add_uses(cd.clk)
- if cd.rst is not None:
- add_uses(cd.rst)
+ for domain, _ in self.iter_sync():
+ cd = self.domains[domain]
+ add_uses(cd.clk)
+ if cd.rst is not None:
+ add_uses(cd.rst)
# Repeat for subfragments.
for subfrag, name in self.subfragments:
- parent[subfrag] = self
- level [subfrag] = level[self] + 1
+ if isinstance(subfrag, Instance):
+ for port_name, (value, dir) in subfrag.named_ports.items():
+ if dir == "i":
+ subfrag.add_ports(value._rhs_signals(), dir=dir)
+ add_uses(value._rhs_signals())
+ if dir == "o":
+ subfrag.add_ports(value._lhs_signals(), dir=dir)
+ add_defs(value._lhs_signals())
+ if dir == "io":
+ subfrag.add_ports(value, dir=dir)
+ add_io(value)
+ else:
+ parent[subfrag] = self
+ level [subfrag] = level[self] + 1
- subfrag._prepare_use_def_graph(parent, level, uses, defs, ios, top)
+ subfrag._prepare_use_def_graph(parent, level, uses, defs, ios, top)
def _propagate_ports(self, ports, all_undef_as_ports):
# Take this fragment graph:
o_data=Cat(self.datal, self.datah),
io_pins=self.pins
)
+ self.wrap = Fragment()
+ self.wrap.add_subfragment(self.inst)
def test_init(self):
self.setUp_cpu()
def test_prepare(self):
self.setUp_cpu()
- f = self.inst.prepare()
+ f = self.wrap.prepare()
sync_clk = f.domains["sync"].clk
self.assertEqual(f.ports, SignalDict([
(sync_clk, "i"),
def test_prepare_explicit_ports(self):
self.setUp_cpu()
- f = self.inst.prepare(ports=[self.rst, self.stb])
+ f = self.wrap.prepare(ports=[self.rst, self.stb])
sync_clk = f.domains["sync"].clk
sync_rst = f.domains["sync"].rst
self.assertEqual(f.ports, SignalDict([
(self.stb, "o"),
(self.pins, "io"),
]))
+
+ def test_prepare_slice_in_port(self):
+ s = Signal(2)
+ f = Fragment()
+ f.add_subfragment(Instance("foo", o_O=s[0]))
+ f.add_subfragment(Instance("foo", o_O=s[1]))
+ fp = f.prepare(ports=[s], ensure_sync_exists=False)
+ self.assertEqual(fp.ports, SignalDict([
+ (s, "o"),
+ ]))