hdl.ir: allow ClockSignal and ResetSignal in ports.
authorwhitequark <cz@m-labs.hk>
Sun, 13 Oct 2019 03:39:56 +0000 (03:39 +0000)
committerwhitequark <cz@m-labs.hk>
Sun, 13 Oct 2019 03:39:56 +0000 (03:39 +0000)
Fixes #248.

nmigen/hdl/ir.py
nmigen/hdl/xfrm.py
nmigen/test/test_hdl_ir.py

index 0f718ffbe60e1e1a96ee8a81aef31f4fc2092212..4232c52474c229cec975c911c958235c9a904635 100644 (file)
@@ -540,6 +540,7 @@ class Fragment:
         if ports is None:
             fragment._propagate_ports(ports=(), all_undef_as_ports=True)
         else:
+            ports = map(DomainLowerer(fragment.domains).on_value, ports)
             new_ports = []
             for cd in new_domains:
                 new_ports.append(cd.clk)
index 889e4b09d747a078b88c97ccfce8f0615f0001ba..2d4e6391b1bca6cf119098118e096b84c6d73547 100644 (file)
@@ -486,8 +486,8 @@ class DomainRenamer(FragmentTransformer, ValueTransformer, StatementTransformer)
 
 
 class DomainLowerer(FragmentTransformer, ValueTransformer, StatementTransformer):
-    def __init__(self):
-        self.domains = None
+    def __init__(self, domains=None):
+        self.domains = domains
 
     def _resolve(self, domain, context):
         if domain not in self.domains:
index 82b9ed10fd4bce9ad3f4e7752ba0dc91ea13c995..e51ae4e298e0e8e49d2a05cb51679bafc4d15f56 100644 (file)
@@ -264,6 +264,17 @@ class FragmentPortsTestCase(FHDLTestCase):
             (s, "io")
         ]))
 
+    def test_clk_rst(self):
+        sync = ClockDomain()
+        f = Fragment()
+        f.add_domains(sync)
+
+        f = f.prepare(ports=(ClockSignal("sync"), ResetSignal("sync")))
+        self.assertEqual(f.ports, SignalDict([
+            (sync.clk, "i"),
+            (sync.rst, "i"),
+        ]))
+
 
 class FragmentDomainsTestCase(FHDLTestCase):
     def test_iter_signals(self):