mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
sim: proxy
This commit is contained in:
parent
081b658e2d
commit
bb864c65dc
1 changed files with 17 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue