Permalink
Browse files

fhdl/namer: simplify + more relevant names

  • Loading branch information...
1 parent 4164fb4 commit 51f9a2a963c52cff1174954ca9f48fc9e3a20ab6 @sbourdeauducq sbourdeauducq committed Sep 8, 2012
Showing with 7 additions and 30 deletions.
  1. +3 −28 migen/fhdl/namer.py
  2. +1 −1 migen/fhdl/structure.py
  3. +3 −1 migen/fhdl/tracer.py
View
@@ -2,11 +2,11 @@
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 @@ def context_prefix(self, obj):
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
@@ -168,7 +168,7 @@ def __hash__(self):
return id(self)
def __repr__(self):
- return "<Signal " + (self.backtrace[-1][1] or "anonymous") + ">"
+ return "<Signal " + (self.backtrace[-1] or "anonymous") + ">"
# statements
View
@@ -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

0 comments on commit 51f9a2a

Please sign in to comment.