From: Sebastien Bourdeauducq Date: Fri, 30 Mar 2012 14:40:26 +0000 (+0200) Subject: sim: proxy X-Git-Tag: 24jan2021_ls180~2099^2~961 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bb864c65dc3c4df4f8e3bc84db8c8b80de6b236d;p=litex.git sim: proxy --- diff --git a/migen/sim/generic.py b/migen/sim/generic.py index 5eb3670e..12e40ed2 100644 --- a/migen/sim/generic.py +++ b/migen/sim/generic.py @@ -138,3 +138,20 @@ class Simulator: value += 2**nbits assert(value >= 0 and value < 2**nbits) self.ipc.send(MessageWrite(name, Int32(index), value)) + +class Proxy: + def __init__(self, sim, obj): + self.__dict__["_sim"] = sim + self.__dict__["_obj"] = obj + + def __getattr__(self, name): + item = getattr(self._obj, name) + if isinstance(item, Signal): + return self._sim.rd(item) + else: + return Proxy(self._sim, item) + + def __setattr__(self, name, value): + item = getattr(self._obj, name) + assert(isinstance(item, Signal)) + self._sim.wr(item, value)