1
0
mirror of https://github.com/myhdl/myhdl.git synced 2025-01-24 21:52:56 +08:00

debugged _len attr to intbv constructors

added test for bounds inferred by getslice
This commit is contained in:
jand 2003-07-04 17:21:20 +00:00
parent 54d92f8725
commit 693ed3f180
3 changed files with 19 additions and 9 deletions

View File

@ -82,10 +82,10 @@ class intbv(object):
width += w
else:
raise TypeError
res = intbv(v)
if basewidth:
res._len = basewidth + width
return res
return intbv(v, _len=basewidth + width)
else:
return intbv(v)
# hash
def __hash__(self):
@ -113,8 +113,7 @@ class intbv(object):
# indexing and slicing methods
def __getitem__(self, i):
res = intbv((self._val >> i) & 0x1)
res._len = 1
res = intbv((self._val >> i) & 0x1, _len=1)
return res
def __getslice__(self, i, j):
@ -128,8 +127,7 @@ class intbv(object):
if i <= j:
raise ValueError, "intbv[i:j] requires i > j\n" \
" i, j == %s, %s" % (i, j)
res = intbv((self._val & 2**i-1) >> j)
res._len = i-j
res = intbv((self._val & 2**i-1) >> j, _len=i-j)
return res
def __setitem__(self, i, val):

View File

@ -24,9 +24,10 @@ __revision__ = "$Revision$"
__date__ = "$Date$"
import test_Simulation, test_Signal, test_intbv, test_Cosimulation, test_misc, \
test_always_comb
test_always_comb, test_intbvbounds
modules = (test_Simulation, test_Signal, test_intbv, test_misc, test_always_comb)
modules = (test_Simulation, test_Signal, test_intbv, test_misc, test_always_comb,
test_intbvbounds)
import unittest

View File

@ -66,6 +66,17 @@ class TestIntbvBounds(TestCase):
pass
else:
self.fail()
a = intbv(5)[8:]
a[:] = 0
a[:] = 2**8-1
try:
a[:] = -1
a[:] = 2**8
except ValueError:
pass
else:
self.fail()
def checkBounds(self, i, j, op):