fhdl/structure: use sets for memories and instance collections
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Fri, 23 Nov 2012 16:20:08 +0000 (17:20 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Fri, 23 Nov 2012 16:20:08 +0000 (17:20 +0100)
migen/fhdl/structure.py
migen/fhdl/tools.py
migen/uio/ioo.py

index 2249b466f5115ae32056e11aea97ee603d1d0b4c..4db0580bcc03d52e2c47ed44682a35a6616fa302 100644 (file)
@@ -324,8 +324,8 @@ class Fragment:
        def __init__(self, comb=None, sync=None, instances=None, memories=None, sim=None):
                if comb is None: comb = []
                if sync is None: sync = dict()
-               if instances is None: instances = []
-               if memories is None: memories = []
+               if instances is None: instances = set()
+               if memories is None: memories = set()
                if sim is None: sim = []
                
                if isinstance(sync, list):
@@ -333,8 +333,8 @@ class Fragment:
                
                self.comb = comb
                self.sync = sync
-               self.instances = instances
-               self.memories = memories
+               self.instances = set(instances)
+               self.memories = set(memories)
                self.sim = sim
                
        
@@ -345,8 +345,8 @@ class Fragment:
                for k, v in other.sync.items():
                        newsync[k].extend(v)
                return Fragment(self.comb + other.comb, newsync,
-                       self.instances + other.instances,
-                       self.memories + other.memories,
+                       self.instances | other.instances,
+                       self.memories | other.memories,
                        self.sim + other.sim)
        
        def rename_clock_domain(self, old, new):
index 0b12692138e2f58028c0a071d3b1ec4a43254bf6..0382892d839e8be74a48bf7a569ab6a4f993b00b 100644 (file)
@@ -84,7 +84,7 @@ def group_by_targets(sl):
 def list_inst_ios(i, ins, outs, inouts):
        if isinstance(i, Fragment):
                return list_inst_ios(i.instances, ins, outs, inouts)
-       elif isinstance(i, list):
+       elif isinstance(i, set):
                if i:
                        return set.union(*(list_inst_ios(e, ins, outs, inouts) for e in i))
                else:
index 907d85e9027d9f54117a4bfaec5929693a1c3ae9..c5b9263e00e0fa011d2cef50e38a87a886611c31 100644 (file)
@@ -14,7 +14,7 @@ class UnifiedIOObject(Actor):
                self._memories = set(v for v in self.buses.values() if isinstance(v, Memory))
        
        def get_fragment(self):
-               return Fragment(memories=list(self._memories))
+               return Fragment(memories=self._memories)
 
 (_WAIT_COMPLETE, _WAIT_POLL) = range(2)