fhdl/namer: simplify + more relevant names

This commit is contained in:
Sebastien Bourdeauducq 2012-09-09 01:26:33 +02:00
parent 4164fb4ac9
commit 51f9a2a963
3 changed files with 7 additions and 30 deletions

View File

@ -2,11 +2,11 @@ from itertools import combinations
from migen.fhdl.structure import *
class _StepNamer():
class _StepNamer:
def __init__(self):
self.name_to_ids = {}
def context_prefix(self, obj):
def get_step_str(self, obj):
if isinstance(obj, str):
return obj
else:
@ -24,40 +24,15 @@ class _StepNamer():
l.append(id(obj))
return n + str(idx)
def name(self, with_context_prefix, step):
if with_context_prefix or step[1] is None:
n = self.context_prefix(step[0])
if step[1] is not None:
n += "_" + step[1]
else:
n = step[1]
return n
# Returns True if we should include the context prefix
def _choose_strategy(objs):
id_with_name = {}
for obj in objs:
if not isinstance(obj, str):
n = obj.__class__.__name__.lower()
try:
existing_id = id_with_name[n]
except KeyError:
id_with_name[n] = id(obj)
else:
if existing_id != id(obj):
return True
return False
def _bin(sn, sig_iters):
status = []
for signal, it in sig_iters:
step, last = next(it)
status.append((signal, it, step, last))
with_context_prefix = _choose_strategy(step[0] for signal, it, step, last in status)
terminals = []
bins = {}
for signal, it, step, last in status:
step_name = sn.name(with_context_prefix, step)
step_name = sn.get_step_str(step)
if last:
terminals.append((step_name, signal))
else:

View File

@ -168,7 +168,7 @@ class Signal(Value):
return id(self)
def __repr__(self):
return "<Signal " + (self.backtrace[-1][1] or "anonymous") + ">"
return "<Signal " + (self.backtrace[-1] or "anonymous") + ">"
# statements

View File

@ -42,7 +42,9 @@ def trace_back(name=None):
if name is None:
name = get_var_name(frame)
l.insert(0, (obj, name))
if name is not None:
l.insert(0, name)
l.insert(0, obj)
name = None
frame = frame.f_back
return l