From 05b20d49877de4bcdec202cf1a479441445f621f Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 19 Jan 2012 19:25:04 +0100 Subject: [PATCH] Only include context prefix when necessary --- migen/fhdl/namer.py | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/migen/fhdl/namer.py b/migen/fhdl/namer.py index 5f658bba..d5995f97 100644 --- a/migen/fhdl/namer.py +++ b/migen/fhdl/namer.py @@ -35,7 +35,7 @@ class _StepNamer(): def __init__(self): self.name_to_ids = {} - def basename(self, obj): + def context_prefix(self, obj): if isinstance(obj, str): return obj else: @@ -53,18 +53,40 @@ class _StepNamer(): l.append(id(obj)) return n + str(idx) - def name(self, step): - n = self.basename(step[0]) - if step[1] is not None: - n += "_" + step[1] + 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): - terminals = [] - bins = {} + status = [] for signal, it in sig_iters: step, last = next(it) - step_name = sn.name(step) + 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) if last: terminals.append((step_name, signal)) else: -- 2.30.2