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

bool check

delegated bound check to underlying intbv
set next methods instead of check methods
This commit is contained in:
jand 2003-08-27 09:45:03 +00:00
parent 13f98523b7
commit 687cbf7fa8
2 changed files with 37 additions and 19 deletions

View File

@ -64,7 +64,7 @@ class Signal(object):
__slots__ = ('_next', '_val', '_min', '_max', '_type',
'_eventWaiters', '_posedgeWaiters', '_negedgeWaiters',
'_code', '_tracing', '_nrbits', '_checkVal',
'_code', '_tracing', '_nrbits', '_checkVal', '_setNextVal',
'_printVcd', '_info',
)
@ -89,29 +89,24 @@ class Signal(object):
self._printVcd = self._printVcdStr
if type(val) is bool:
self._type = bool
self._checkVal = self._checkBool
self._setNextVal = self._setNextBool
self._printVcd = self._printVcdBit
self._nrbits = 1
elif isinstance(val, (int, long)):
self._type = (int, long)
self._checkVal = self._checkInt
self._setNextVal = self._setNextInt
elif isinstance(val, intbv):
self._type = intbv
self._min = val._min
self._max = val._max
self._nrbits = val._len
if self._nrbits:
self._checkVal = self._checkIntbvBounds
self._printVcd = self._printVcdVec
else:
self._checkVal = self._checkInt
self._printVcd = self._printVcdHex
self._setNextVal = self._setNextIntbv
elif val is None:
self._type = None
self._checkVal = self._checkNone
self._setNextVal = self._setNext
else:
self._type = type(val)
self._checkVal = self._checkType
self._setNextVal = self._setNextType
self._eventWaiters = _WaiterList()
self._posedgeWaiters = _WaiterList()
self._negedgeWaiters = _WaiterList()
@ -150,8 +145,7 @@ class Signal(object):
def _set_next(self, val):
if isinstance(val, Signal):
val = val._val
self._checkVal(val)
self._next = val
self._setNextVal(val)
_siglist.append(self)
next = property(_get_next, _set_next, None, "'next' access methods")
@ -197,6 +191,33 @@ class Signal(object):
def _checkNone(self, val):
pass
# set next methods
def _setNextBool(self, val):
if not val in (0, 1):
raise ValueError("Expected value 0 or 1, got %s" % val)
self._next = val
def _setNextInt(self, val):
if not isinstance(val, (int, long, intbv)):
raise TypeError("Expected int or intbv, got %s" % type(val))
self._next = val
def _setNextIntbv(self, val):
if isinstance(val, intbv):
val = val._val
elif not isinstance(val, (int, long)):
raise TypeError("Expected int or intbv, got %s" % type(val))
self._next._val = val
self._next._checkBounds()
def _setNextType(self, val):
if not isinstance(val, self._type):
raise TypeError("Expected %s, got %s" % (self._type, type(val)))
self._next = val
def _setNext(self, val):
self._next = val
# vcd print methods
def _printVcdStr(self):
print >> sim._tf, "s%s %s" % (str(self._val), self._code)

View File

@ -47,6 +47,8 @@ class SigTest(TestCase):
self.nexts += [intbv(0), intbv(1), 1 , 0 , intbv(3) ]
self.vals += [ [1,2,3], (1,2,3), {1:1, 2:2}, (0, [2, 3], (1, 2)) ]
self.nexts += [ [4,5,6], (4,5,5), {3:3, 4:4}, (1, (0, 1), [2, 3]) ]
self.vals += [bool(0), bool(1), bool(0), bool(1), bool(0), bool(1)]
self.nexts += [bool(0), bool(1), bool(1), bool(0), 1 , 0 ]
self.sigs = [Signal(i) for i in self.vals]
self.incompatibleVals = [ [3, 4], (1, 2), 3 , intbv(0), [1] ]
@ -128,12 +130,7 @@ class SigTest(TestCase):
try:
oldval = s.val
s.next = n
#s._update()
#s.val
except TypeError:
# restore
#s.next = oldval
#s._update()
except (TypeError, ValueError):
pass
else:
self.fail()