fhdl/namer: simplify + more relevant names
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Sat, 8 Sep 2012 23:26:33 +0000 (01:26 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Sat, 8 Sep 2012 23:26:33 +0000 (01:26 +0200)
migen/fhdl/namer.py
migen/fhdl/structure.py
migen/fhdl/tracer.py

index 55a79c3e2265ef24832c7973ba652c035850db7d..433882bfc6f2583a80994c39bbf7864dcc8c11a1 100644 (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:
index 9946e29baf89794afe04b38a855172ef85b23141..bf86e162d26289cb225827cc3859eea46c1ab6f1 100644 (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
 
index c363eadd84bc06aa8d82ffffe4da4f8188eaf82b..8a782a48fca886e63bc6ce9b745e2cec79ccb88e 100644 (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