From 146a1b5d516878e3a1208c8b2c1490c6847dad54 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 8 Aug 2013 00:15:18 +0200 Subject: [PATCH] namer: add HUID suffix step --- migen/fhdl/namer.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/migen/fhdl/namer.py b/migen/fhdl/namer.py index 5e4806ebc..ddb5f6544 100644 --- a/migen/fhdl/namer.py +++ b/migen/fhdl/namer.py @@ -99,11 +99,15 @@ def _name_signal(tree, signal): def _build_pnd(tree, signals): return dict((signal, _name_signal(tree, signal)) for signal in signals) -def _list_conflicting_signals(pnd): +def _invert_pnd(pnd): inv_pnd = dict() for k, v in pnd.items(): inv_pnd[v] = inv_pnd.get(v, []) inv_pnd[v].append(k) + return inv_pnd + +def _list_conflicting_signals(pnd): + inv_pnd = _invert_pnd(pnd) r = set() for k, v in inv_pnd.items(): if len(v) > 1: @@ -117,7 +121,7 @@ def _set_use_number(tree, signals): current = current.children[step_name] current.use_number = current.signal_count > len(current.numbers) and len(current.numbers) > 1 -_debug = True +_debug = False def build_namespace(signals): basic_tree = _build_tree(signals) @@ -143,6 +147,17 @@ def build_namespace(signals): if _debug: print("namer: using basic strategy") + # ...then add number suffixes by HUID + inv_pnd = _invert_pnd(pnd) + huid_suffixed = False + for name, signals in inv_pnd.items(): + if len(signals) > 1: + huid_suffixed = True + for n, signal in enumerate(sorted(signals, key=lambda x: x.huid)): + pnd[signal] += str(n) + if _debug and huid_suffixed: + print("namer: using HUID suffixes") + ns = Namespace(pnd) # register signals with name_override for signal in signals: