mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
fhdl: better signal naming heuristic
This commit is contained in:
parent
b6763c28ea
commit
cdd9977a40
1 changed files with 38 additions and 11 deletions
|
@ -131,20 +131,47 @@ def _cst(x):
|
||||||
else:
|
else:
|
||||||
return x
|
return x
|
||||||
|
|
||||||
def _make_signal_name():
|
def _try_class_name(frame):
|
||||||
frame = inspect.currentframe().f_back.f_back
|
while frame is not None:
|
||||||
line = inspect.getframeinfo(frame).code_context[0]
|
try:
|
||||||
m = re.match('[\t ]*([0-9A-Za-z_\.]+)[\t ]*=', line)
|
cl = frame.f_locals['self']
|
||||||
if m is None:
|
prefix = cl.__class__.__name__.lower()
|
||||||
return "anonymous"
|
if prefix != 'inst' and prefix != 'source' and prefix != 'sink':
|
||||||
name = m.group(1)
|
return prefix
|
||||||
name = name.split('.')
|
except KeyError:
|
||||||
name = name[len(name)-1]
|
pass
|
||||||
|
frame = frame.f_back
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _try_module_name(frame):
|
||||||
modules = frame.f_globals["__name__"]
|
modules = frame.f_globals["__name__"]
|
||||||
if modules != "__main__":
|
if modules != "__main__":
|
||||||
modules = modules.split('.')
|
modules = modules.split('.')
|
||||||
name = modules[len(modules)-1] + "_" + name
|
prefix = modules[len(modules)-1]
|
||||||
return name
|
return prefix
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _make_signal_name():
|
||||||
|
frame = inspect.currentframe().f_back.f_back
|
||||||
|
|
||||||
|
line = inspect.getframeinfo(frame).code_context[0]
|
||||||
|
m = re.match('[\t ]*([0-9A-Za-z_\.]+)[\t ]*=', line)
|
||||||
|
if m is None:
|
||||||
|
name = "anonymous"
|
||||||
|
else:
|
||||||
|
names = m.group(1).split('.')
|
||||||
|
name = names[len(names)-1]
|
||||||
|
|
||||||
|
prefix = _try_class_name(frame)
|
||||||
|
if prefix is None:
|
||||||
|
prefix = _try_module_name(frame)
|
||||||
|
if prefix is None:
|
||||||
|
prefix = ""
|
||||||
|
else:
|
||||||
|
prefix += "_"
|
||||||
|
|
||||||
|
return prefix + name
|
||||||
|
|
||||||
class Signal(Value):
|
class Signal(Value):
|
||||||
def __init__(self, bv=BV(), name=None, variable=False, reset=0):
|
def __init__(self, bv=BV(), name=None, variable=False, reset=0):
|
||||||
|
|
Loading…
Reference in a new issue