fhdl/namer: detect leaf nodes better
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 8 Aug 2013 10:22:58 +0000 (12:22 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 8 Aug 2013 10:22:58 +0000 (12:22 +0200)
migen/fhdl/namer.py

index ddb5f6544baf4566ee6e72ae991be92e0ec5e645..a97c7d3fb6582bc3ab9331c4144181bd3b217c2a 100644 (file)
@@ -61,24 +61,25 @@ def _build_tree(signals, basic_tree=None):
        return root
 
 def _set_use_name(node, node_name=""):
-       if not node.children:
+       cnames = [(k, _set_use_name(v, k)) for k, v in node.children.items()]
+       for (c1_prefix, c1_names), (c2_prefix, c2_names) in combinations(cnames, 2):
+               if not c1_names.isdisjoint(c2_names):
+                       node.children[c1_prefix].use_name = True
+                       node.children[c2_prefix].use_name = True
+       r = set()
+       for c_prefix, c_names in cnames:
+               if node.children[c_prefix].use_name:
+                       for c_name in c_names:
+                               r.add((c_prefix, ) + c_name)
+               else:
+                       r |= c_names
+       
+       if node.signal_count > sum(c.signal_count for c in node.children.values()):
                node.use_name = True
-               return {(node_name, )}
-       else:
-               cnames = [(k, _set_use_name(v, k)) for k, v in node.children.items()]
-               for (c1_prefix, c1_names), (c2_prefix, c2_names) in combinations(cnames, 2):
-                       if not c1_names.isdisjoint(c2_names):
-                               node.children[c1_prefix].use_name = True
-                               node.children[c2_prefix].use_name = True
-               r = set()
-               for c_prefix, c_names in cnames:
-                       if node.children[c_prefix].use_name:
-                               for c_name in c_names:
-                                       r.add((c_prefix, ) + c_name)
-                       else:
-                               r |= c_names
-               return r
+               r.add((node_name, ))
 
+       return r
+               
 def _name_signal(tree, signal):
        elements = []
        treepos = tree