sim: keep track of unreferenced items
* items that are never referenced in any statements do not end up in the namespace or in the verilog * this memorizes items if they can not be found in the namespace and keeps track of their values
This commit is contained in:
parent
4fe888702d
commit
5f045b7649
|
@ -103,6 +103,7 @@ class Simulator:
|
||||||
|
|
||||||
self.sim_functions = fragment.sim
|
self.sim_functions = fragment.sim
|
||||||
self.active_sim_functions = set(f for f in fragment.sim if not hasattr(f, "passive") or not f.passive)
|
self.active_sim_functions = set(f for f in fragment.sim if not hasattr(f, "passive") or not f.passive)
|
||||||
|
self.unreferenced = {}
|
||||||
|
|
||||||
def run(self, ncycles=None):
|
def run(self, ncycles=None):
|
||||||
counter = 0
|
counter = 0
|
||||||
|
@ -140,28 +141,43 @@ class Simulator:
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_unreferenced(self, item, index):
|
||||||
|
try:
|
||||||
|
return self.unreferenced[(item, index)]
|
||||||
|
except KeyError:
|
||||||
|
if isinstance(item, Memory):
|
||||||
|
try:
|
||||||
|
init = item.init[index]
|
||||||
|
except (TypeError, IndexError):
|
||||||
|
init = 0
|
||||||
|
else:
|
||||||
|
init = item.reset
|
||||||
|
self.unreferenced[(item, index)] = init
|
||||||
|
return init
|
||||||
|
|
||||||
def rd(self, item, index=0):
|
def rd(self, item, index=0):
|
||||||
name = self.top_level.top_name + "." \
|
try:
|
||||||
+ self.top_level.dut_name + "." \
|
name = self.top_level.top_name + "." \
|
||||||
+ self.namespace.get_name(item)
|
+ self.top_level.dut_name + "." \
|
||||||
self.ipc.send(MessageRead(name, Int32(index)))
|
+ self.namespace.get_name(item)
|
||||||
reply = self.ipc.recv()
|
self.ipc.send(MessageRead(name, Int32(index)))
|
||||||
assert(isinstance(reply, MessageReadReply))
|
reply = self.ipc.recv()
|
||||||
|
assert(isinstance(reply, MessageReadReply))
|
||||||
|
value = reply.value
|
||||||
|
except KeyError:
|
||||||
|
value = self.get_unreferenced(item, index)
|
||||||
if isinstance(item, Memory):
|
if isinstance(item, Memory):
|
||||||
signed = False
|
signed = False
|
||||||
nbits = item.width
|
nbits = item.width
|
||||||
else:
|
else:
|
||||||
signed = item.signed
|
signed = item.signed
|
||||||
nbits = flen(item)
|
nbits = flen(item)
|
||||||
value = reply.value & (2**nbits - 1)
|
value = value & (2**nbits - 1)
|
||||||
if signed and (value & 2**(nbits - 1)):
|
if signed and (value & 2**(nbits - 1)):
|
||||||
value -= 2**nbits
|
value -= 2**nbits
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def wr(self, item, value, index=0):
|
def wr(self, item, value, index=0):
|
||||||
name = self.top_level.top_name + "." \
|
|
||||||
+ self.top_level.dut_name + "." \
|
|
||||||
+ self.namespace.get_name(item)
|
|
||||||
if isinstance(item, Memory):
|
if isinstance(item, Memory):
|
||||||
nbits = item.width
|
nbits = item.width
|
||||||
else:
|
else:
|
||||||
|
@ -169,7 +185,13 @@ class Simulator:
|
||||||
if value < 0:
|
if value < 0:
|
||||||
value += 2**nbits
|
value += 2**nbits
|
||||||
assert(value >= 0 and value < 2**nbits)
|
assert(value >= 0 and value < 2**nbits)
|
||||||
self.ipc.send(MessageWrite(name, Int32(index), value))
|
try:
|
||||||
|
name = self.top_level.top_name + "." \
|
||||||
|
+ self.top_level.dut_name + "." \
|
||||||
|
+ self.namespace.get_name(item)
|
||||||
|
self.ipc.send(MessageWrite(name, Int32(index), value))
|
||||||
|
except KeyError:
|
||||||
|
self.unreferenced[(item, index)] = value
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if hasattr(self, "ipc"):
|
if hasattr(self, "ipc"):
|
||||||
|
|
Loading…
Reference in New Issue