1
0
mirror of https://github.com/myhdl/myhdl.git synced 2024-12-14 07:44:38 +08:00

more appropriate handling of enum signals

--HG--
branch : 0.8-dev
This commit is contained in:
Jan Decaluwe 2011-05-25 15:57:12 +02:00
parent ae63cdb848
commit a07f0c8333
2 changed files with 28 additions and 19 deletions

View File

@ -34,6 +34,7 @@ from myhdl import _simulator as sim
from myhdl._simulator import _signals, _siglist, _futureEvents, now
from myhdl._intbv import intbv
from myhdl._bin import bin
from myhdl._enum import EnumItemType
_schedule = _futureEvents.append
@ -145,7 +146,10 @@ class _Signal(object):
self._printVcd = self._printVcdHex
else:
self._type = type(val)
self._setNextVal = self._setNextType
if isinstance(val, EnumItemType):
self._setNextVal = self._setNextNonmutable
else:
self._setNextVal = self._setNextMutable
if hasattr(val, '_nrbits'):
self._nrbits = val._nrbits
self._eventWaiters = _WaiterList()
@ -181,7 +185,7 @@ class _Signal(object):
self._val = None
elif isinstance(val, intbv):
self._val._val = next._val
elif isinstance(val, (int, long)):
elif isinstance(val, (int, long, EnumItemType)):
self._val = next
else:
self._val = deepcopy(next)
@ -273,10 +277,15 @@ class _Signal(object):
self._next._val = val
self._next._handleBounds()
def _setNextType(self, val):
def _setNextNonmutable(self, val):
if not isinstance(val, self._type):
raise TypeError("Expected %s, got %s" % (self._type, type(val)))
self._next = deepcopy(val)
self._next = val
def _setNextMutable(self, val):
if not isinstance(val, self._type):
raise TypeError("Expected %s, got %s" % (self._type, type(val)))
self._next = deepcopy(val)
# vcd print methods
def _printVcdStr(self):

View File

@ -3,39 +3,39 @@ Test: timer
=====
pypy
----
real 82.32
user 82.28
sys 0.02
real 81.87
user 81.57
sys 0.27
Test: lfsr24
=====
pypy
----
real 104.06
user 104.00
sys 0.03
real 103.32
user 103.09
sys 0.21
Test: randgen
=====
pypy
----
real 90.33
user 90.05
sys 0.08
real 89.86
user 89.54
sys 0.27
Test: longdiv
=====
pypy
----
real 87.96
user 87.88
sys 0.04
real 88.03
user 87.82
sys 0.18
Test: findmax
=====
pypy
----
real 113.69
user 113.62
sys 0.03
real 111.71
user 111.48
sys 0.19