from migen.fhdl.structure import *
-class _StepNamer:
- def __init__(self):
- self.name_to_ids = {}
-
- def get_step_str(self, obj):
- if isinstance(obj, str):
- return obj
- else:
- n = obj.__class__.__name__.lower()
- try:
- l = self.name_to_ids[n]
- except KeyError:
- self.name_to_ids[n] = [id(obj)]
- return n + "0"
- else:
- try:
- idx = l.index(id(obj))
- except ValueError:
- idx = len(l)
- l.append(id(obj))
- return n + str(idx)
-
-def _bin(sn, sig_iters):
+def _bin(sig_iters):
status = []
for signal, it in sig_iters:
step, last = next(it)
terminals = []
bins = {}
for signal, it, step, last in status:
- step_name = sn.get_step_str(step)
if last:
- terminals.append((step_name, signal))
+ terminals.append((step, signal))
else:
- if step_name not in bins:
- bins[step_name] = []
- bins[step_name].append((signal, it))
+ if step not in bins:
+ bins[step] = []
+ bins[step].append((signal, it))
return terminals, bins
def _sets_disjoint(l):
return False
return True
-def _r_build_pnd(sn, sig_iters):
- terminals, bins = _bin(sn, sig_iters)
- bins_named = [(k, _r_build_pnd(sn, v)) for k, v in bins.items()]
+def _r_build_pnd(sig_iters):
+ terminals, bins = _bin(sig_iters)
+ bins_named = [(k, _r_build_pnd(v)) for k, v in bins.items()]
name_sets = [set(sub_pnd.values()) for prefix, sub_pnd in bins_named]
r = {}
if not _sets_disjoint(name_sets):
def build_namespace(signals):
sig_iters = [(signal, last_flagged(signal.backtrace))
for signal in signals if signal.name_override is None]
- pnd = _r_build_pnd(_StepNamer(), sig_iters)
+ pnd = _r_build_pnd(sig_iters)
ns = Namespace(pnd)
# register signals with name_override
for signal in signals:
else:
return None
+classname_to_objs = dict()
+
+def index_id(l, obj):
+ for n, e in enumerate(l):
+ if id(e) == id(obj):
+ return n
+ raise ValueError
+
def trace_back(name=None):
l = []
frame = inspect.currentframe().f_back.f_back
while frame is not None:
+ if name is None:
+ name = get_var_name(frame)
+ if name is not None:
+ l.insert(0, name)
+
try:
obj = frame.f_locals["self"]
except KeyError:
obj = None
- if obj is not None and hasattr(obj, "__del__"):
+ if hasattr(obj, "__del__"):
obj = None
+
if obj is None:
modules = frame.f_globals["__name__"]
modules = modules.split(".")
- obj = modules[len(modules)-1]
+ objname = modules[len(modules)-1]
+ else:
+ classname = obj.__class__.__name__.lower()
+ try:
+ objs = classname_to_objs[classname]
+ except KeyError:
+ classname_to_objs[classname] = [obj]
+ idx = 0
+ else:
+ try:
+ idx = index_id(objs, obj)
+ except ValueError:
+ idx = len(objs)
+ objs.append(obj)
+ objname = classname + str(idx)
+ l.insert(0, objname)
- if name is None:
- name = get_var_name(frame)
- if name is not None:
- l.insert(0, name)
- l.insert(0, obj)
name = None
frame = frame.f_back
return l