From 16ebe41028257839455596aba58989df170c36de Mon Sep 17 00:00:00 2001 From: David Carne Date: Wed, 17 Jul 2013 00:40:46 -0700 Subject: [PATCH] fhdl/tools: BUGFIX: fix group_by_target grouping group_by_target does not properly combine target groups if statements are presented in the order: ({A}, statement1) ({B}, statement2) ({A, B}, statement3) which returns groups: ({A, B}, [statement1, statement3]) ({B}, [statement2]) This patch fixes group_by_target such that the resulting group is: ({A, B}, [statement1, statement2, statement3]) --- migen/fhdl/tools.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/migen/fhdl/tools.py b/migen/fhdl/tools.py index 44733366..f2f57222 100644 --- a/migen/fhdl/tools.py +++ b/migen/fhdl/tools.py @@ -48,20 +48,29 @@ def list_targets(node): lister.visit(node) return lister.output_list +def resort_statements(ol): + return [statement for i, statement in + sorted(ol, key=lambda x: x[0])] + def group_by_targets(sl): groups = [] - for statement in flat_iteration(sl): + for statement_order, statement in enumerate(flat_iteration(sl)): targets = list_targets(statement) - processed = False - for g in groups: - if not targets.isdisjoint(g[0]): - g[0].update(targets) - g[1].append(statement) - processed = True - break - if not processed: - groups.append((targets, [statement])) - return groups + + chk_groups = [(targets.isdisjoint(g[0]), g) for g in groups] + merge_groups = [g for dj, g in chk_groups if not dj] + groups = [g for dj, g in chk_groups if dj] + + new_group = (set(targets), [(statement_order, statement)]) + + for g in merge_groups: + new_group[0].update(g[0]) + new_group[1].extend(g[1]) + + groups.append(new_group) + + return [(target, resort_statements(stmts)) + for target, stmts in groups] def list_special_ios(f, ins, outs, inouts): r = set() -- 2.30.2