fhdl: automatic signal name from assignment
This commit is contained in:
parent
135a2eb868
commit
41e2430e2b
|
@ -1,4 +1,6 @@
|
||||||
import math
|
import math
|
||||||
|
import inspect
|
||||||
|
import re
|
||||||
|
|
||||||
def bits_for(n):
|
def bits_for(n):
|
||||||
if isinstance(n, Constant):
|
if isinstance(n, Constant):
|
||||||
|
@ -123,11 +125,27 @@ def _cst(x):
|
||||||
else:
|
else:
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
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_]+) =', line)
|
||||||
|
if m is None: return None
|
||||||
|
name = m.group(1)
|
||||||
|
modules = frame.f_globals["__name__"]
|
||||||
|
if modules != "__main__":
|
||||||
|
modules = modules.split('.')
|
||||||
|
name = modules[len(modules)-1] + "_" + name
|
||||||
|
return name
|
||||||
|
|
||||||
class Signal(Value):
|
class Signal(Value):
|
||||||
def __init__(self, bv=BV(), name="anonymous", variable=False, reset=0):
|
def __init__(self, bv=BV(), name=None, variable=False, reset=0):
|
||||||
self.bv = bv
|
self.bv = bv
|
||||||
self.variable = variable
|
self.variable = variable
|
||||||
self.name = name
|
self.name = name
|
||||||
|
if self.name is None:
|
||||||
|
self.name = _make_signal_name()
|
||||||
|
if self.name is None:
|
||||||
|
self.name = "anonymous"
|
||||||
self.reset = Constant(reset, bv)
|
self.reset = Constant(reset, bv)
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
|
|
Loading…
Reference in New Issue