attrs=None, decoder=None, src_loc_at=0):
super().__init__(src_loc_at=src_loc_at)
- if name is None:
- try:
- name = tracer.get_var_name(depth=2 + src_loc_at)
- except tracer.NameNotFound:
- name = "$signal"
- self.name = name
+ self.name = name or tracer.get_var_name(depth=2 + src_loc_at, default="$signal")
if shape is None:
if min is None:
other : Value
Object to base this Signal on.
"""
- 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)
+ name = name or tracer.get_var_name(depth=2 + src_loc_at, default="$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)
raise TypeError("Memory depth must be a non-negative integer, not '{!r}'"
.format(depth))
- if name is None:
- try:
- name = tracer.get_var_name(depth=2)
- except tracer.NameNotFound:
- name = "$memory"
- self.name = name
+ self.name = name or tracer.get_var_name(depth=2, default="$memory")
self.src_loc = tracer.get_src_loc()
self.width = width
if granularity is None:
granularity = width
if name is None:
- try:
- name = tracer.get_var_name(depth=2)
- except tracer.NameNotFound:
- name = "dummy"
+ name = tracer.get_var_name(depth=2, default="dummy")
self.addr = Signal(addr_bits,
name="{}_addr".format(name))
class Record(Value):
def __init__(self, layout, name=None):
if name is None:
- try:
- name = tracer.get_var_name()
- except tracer.NameNotFound:
- pass
+ name = tracer.get_var_name(default=None)
+
self.name = name
self.src_loc = tracer.get_src_loc()
pass
-def get_var_name(depth=2):
+_raise_exception = object()
+
+
+def get_var_name(depth=2, default=_raise_exception):
frame = inspect.currentframe()
for _ in range(depth):
frame = frame.f_back
"DUP_TOP", "BUILD_LIST"):
index += 2
else:
- raise NameNotFound
+ if default is _raise_exception:
+ raise NameNotFound
+ else:
+ return default
def get_src_loc(src_loc_at=0):