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:
parent
54d92f8725
commit
693ed3f180
@ -82,10 +82,10 @@ class intbv(object):
|
|||||||
width += w
|
width += w
|
||||||
else:
|
else:
|
||||||
raise TypeError
|
raise TypeError
|
||||||
res = intbv(v)
|
|
||||||
if basewidth:
|
if basewidth:
|
||||||
res._len = basewidth + width
|
return intbv(v, _len=basewidth + width)
|
||||||
return res
|
else:
|
||||||
|
return intbv(v)
|
||||||
|
|
||||||
# hash
|
# hash
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
@ -113,8 +113,7 @@ class intbv(object):
|
|||||||
# indexing and slicing methods
|
# indexing and slicing methods
|
||||||
|
|
||||||
def __getitem__(self, i):
|
def __getitem__(self, i):
|
||||||
res = intbv((self._val >> i) & 0x1)
|
res = intbv((self._val >> i) & 0x1, _len=1)
|
||||||
res._len = 1
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def __getslice__(self, i, j):
|
def __getslice__(self, i, j):
|
||||||
@ -128,8 +127,7 @@ class intbv(object):
|
|||||||
if i <= j:
|
if i <= j:
|
||||||
raise ValueError, "intbv[i:j] requires i > j\n" \
|
raise ValueError, "intbv[i:j] requires i > j\n" \
|
||||||
" i, j == %s, %s" % (i, j)
|
" i, j == %s, %s" % (i, j)
|
||||||
res = intbv((self._val & 2**i-1) >> j)
|
res = intbv((self._val & 2**i-1) >> j, _len=i-j)
|
||||||
res._len = i-j
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def __setitem__(self, i, val):
|
def __setitem__(self, i, val):
|
||||||
|
@ -24,9 +24,10 @@ __revision__ = "$Revision$"
|
|||||||
__date__ = "$Date$"
|
__date__ = "$Date$"
|
||||||
|
|
||||||
import test_Simulation, test_Signal, test_intbv, test_Cosimulation, test_misc, \
|
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
|
import unittest
|
||||||
|
|
||||||
|
@ -66,6 +66,17 @@ class TestIntbvBounds(TestCase):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.fail()
|
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):
|
def checkBounds(self, i, j, op):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user