sim: multiread/multiwrite

This commit is contained in:
Sebastien Bourdeauducq 2012-06-08 17:52:32 +02:00
parent f38ef626de
commit b145f9e5e2
1 changed files with 21 additions and 0 deletions

View File

@ -140,6 +140,27 @@ class Simulator:
assert(value >= 0 and value < 2**nbits) assert(value >= 0 and value < 2**nbits)
self.ipc.send(MessageWrite(name, Int32(index), value)) 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: class Proxy:
def __init__(self, sim, obj): def __init__(self, sim, obj):
self.__dict__["_sim"] = sim self.__dict__["_sim"] = sim