hdl.ast: fix naming of Signal.like() signals when tracer fails.
authorwhitequark <cz@m-labs.hk>
Wed, 16 Jan 2019 15:55:28 +0000 (15:55 +0000)
committerwhitequark <cz@m-labs.hk>
Wed, 16 Jan 2019 17:20:38 +0000 (17:20 +0000)
nmigen/hdl/ast.py
nmigen/test/test_hdl_ast.py

index 5a03ef741affe388940384040470f3650feb0ba1..be1440b7b50112733223cb56954b1765a3bc1ed5 100644 (file)
@@ -611,7 +611,7 @@ class Signal(Value, DUID):
         self.decoder = decoder
 
     @classmethod
-    def like(cls, other, src_loc_at=0, **kwargs):
+    def like(cls, other, name=None, src_loc_at=0, **kwargs):
         """Create Signal based on another.
 
         Parameters
@@ -619,8 +619,12 @@ class Signal(Value, DUID):
         other : Value
             Object to base this Signal on.
         """
-        kw = dict(shape=cls.wrap(other).shape(),
-                  name=tracer.get_var_name(depth=2 + src_loc_at))
+        if name is None:
+            try:
+                name = tracer.get_var_name(depth=2 + src_loc_at)
+            except tracer.NameNotFound:
+                name = "$like"
+        kw = dict(shape=cls.wrap(other).shape(), name=name)
         if isinstance(other, cls):
             kw.update(reset=other.reset, reset_less=other.reset_less,
                       attrs=other.attrs, decoder=other.decoder)
index bf6b0fd375fbd00d7343c3cdf2a7e667ceb1fa18..603a6cc13818105111fa1a526c518f59cb5b43e3 100644 (file)
@@ -458,6 +458,8 @@ class SignalTestCase(FHDLTestCase):
         self.assertEqual(s5.decoder, str)
         s6 = Signal.like(10)
         self.assertEqual(s6.shape(), (4, False))
+        s7 = [Signal.like(Signal(4))][0]
+        self.assertEqual(s7.name, "$like")
 
 
 class ClockSignalTestCase(FHDLTestCase):