hdl.mem: coerce memory init values to integers.

The coercion is carefully chosen to accept (other than normal ints)
instances of e.g. np.int64, but reject instances of e.g. float.
See https://stackoverflow.com/a/48940855/254415 for details.

Fixes #93.
This commit is contained in:
whitequark 2019-06-11 03:38:44 +00:00
parent 2423eabc15
commit 58e39f90ce
2 changed files with 18 additions and 6 deletions

View file

@ -1,3 +1,5 @@
import operator
from .. import tracer
from .ast import *
from .ir import Elaboratable, Instance
@ -40,11 +42,15 @@ class Memory:
raise ValueError("Memory initialization value count exceed memory depth ({} > {})"
.format(len(self.init), self.depth))
for addr in range(len(self._array)):
if addr < len(self._init):
self._array[addr].reset = self._init[addr]
else:
self._array[addr].reset = 0
try:
for addr in range(len(self._array)):
if addr < len(self._init):
self._array[addr].reset = operator.index(self._init[addr])
else:
self._array[addr].reset = 0
except TypeError as e:
raise TypeError("Memory initialization value at address {:x}: {}"
.format(addr, e)) from None
def read_port(self, domain="sync", synchronous=True, transparent=True):
if not synchronous and not transparent: