sim: multiread/multiwrite
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Fri, 8 Jun 2012 15:52:32 +0000 (17:52 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Fri, 8 Jun 2012 15:52:32 +0000 (17:52 +0200)
migen/sim/generic.py

index 323f62ff22b7ff5be898d1569bd056b6e213e36d..d503289a8bf628f2ab1e46de8967d34634ad0aa9 100644 (file)
@@ -139,7 +139,28 @@ class Simulator:
                        value += 2**nbits
                assert(value >= 0 and value < 2**nbits)
                self.ipc.send(MessageWrite(name, Int32(index), value))
+       
+       def multiread(self, obj):
+               if isinstance(obj, Signal):
+                       return self.rd(obj)
+               elif isinstance(obj, list):
+                       return [self.multiread(item) for item in obj]
+               elif hasattr(obj, "__dict__"):
+                       return dict([(k, self.multiread(v)) for k, v in obj.__dict__.items()])
+       
+       def multiwrite(self, obj, value):
+               if isinstance(obj, Signal):
+                       self.wr(obj, value)
+               elif isinstance(obj, list):
+                       for target, source in zip(obj, value):
+                               self.multiwrite(target, source)
+               else:
+                       for k, v in value.items():
+                               self.multiwrite(getattr(obj, k), v)
+
 
+# Contrary to multiread/multiwrite, Proxy fetches the necessary signals only and
+# immediately forwards writes into the simulation.
 class Proxy:
        def __init__(self, sim, obj):
                self.__dict__["_sim"] = sim