From 51f9a2a963c52cff1174954ca9f48fc9e3a20ab6 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 9 Sep 2012 01:26:33 +0200 Subject: [PATCH] fhdl/namer: simplify + more relevant names --- migen/fhdl/namer.py | 31 +++---------------------------- migen/fhdl/structure.py | 2 +- migen/fhdl/tracer.py | 4 +++- 3 files changed, 7 insertions(+), 30 deletions(-) diff --git a/migen/fhdl/namer.py b/migen/fhdl/namer.py index 55a79c3e2..433882bfc 100644 --- a/migen/fhdl/namer.py +++ b/migen/fhdl/namer.py @@ -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: diff --git a/migen/fhdl/structure.py b/migen/fhdl/structure.py index 9946e29ba..bf86e162d 100644 --- a/migen/fhdl/structure.py +++ b/migen/fhdl/structure.py @@ -168,7 +168,7 @@ class Signal(Value): return id(self) def __repr__(self): - return "" + return "" # statements diff --git a/migen/fhdl/tracer.py b/migen/fhdl/tracer.py index c363eadd8..8a782a48f 100644 --- a/migen/fhdl/tracer.py +++ b/migen/fhdl/tracer.py @@ -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