mirror of
https://github.com/myhdl/myhdl.git
synced 2025-01-24 21:52:56 +08:00
autopep8 the whole thing
This commit is contained in:
parent
d8910e93ba
commit
6d47ba9d25
@ -48,7 +48,6 @@ class Cosimulation(object):
|
|||||||
""" Cosimulation class. """
|
""" Cosimulation class. """
|
||||||
|
|
||||||
def __init__(self, exe="", **kwargs):
|
def __init__(self, exe="", **kwargs):
|
||||||
|
|
||||||
""" Construct a cosimulation object. """
|
""" Construct a cosimulation object. """
|
||||||
|
|
||||||
if _simulator._cosim:
|
if _simulator._cosim:
|
||||||
|
@ -50,7 +50,6 @@ class _ShadowSignal(_Signal):
|
|||||||
raise AttributeError("ShadowSignals are readonly")
|
raise AttributeError("ShadowSignals are readonly")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _SliceSignal(_ShadowSignal):
|
class _SliceSignal(_ShadowSignal):
|
||||||
|
|
||||||
__slots__ = ('_sig', '_left', '_right')
|
__slots__ = ('_sig', '_left', '_right')
|
||||||
@ -104,7 +103,6 @@ class _SliceSignal(_ShadowSignal):
|
|||||||
self._used = True
|
self._used = True
|
||||||
self._sig._used = True
|
self._sig._used = True
|
||||||
|
|
||||||
|
|
||||||
def toVerilog(self):
|
def toVerilog(self):
|
||||||
if self._right is None:
|
if self._right is None:
|
||||||
return "assign %s = %s[%s];" % (self._name, self._sig._name, self._left)
|
return "assign %s = %s[%s];" % (self._name, self._sig._name, self._left)
|
||||||
@ -118,7 +116,6 @@ class _SliceSignal(_ShadowSignal):
|
|||||||
return "%s <= %s(%s-1 downto %s);" % (self._name, self._sig._name, self._left, self._right)
|
return "%s <= %s(%s-1 downto %s);" % (self._name, self._sig._name, self._left, self._right)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ConcatSignal(_ShadowSignal):
|
class ConcatSignal(_ShadowSignal):
|
||||||
|
|
||||||
__slots__ = ('_args', '_sigargs', '_initval')
|
__slots__ = ('_args', '_sigargs', '_initval')
|
||||||
@ -148,7 +145,7 @@ class ConcatSignal(_ShadowSignal):
|
|||||||
w = len(a)
|
w = len(a)
|
||||||
v = long(a, 2)
|
v = long(a, 2)
|
||||||
else:
|
else:
|
||||||
raise TypeError("ConcatSignal: inappropriate argument type: %s" \
|
raise TypeError("ConcatSignal: inappropriate argument type: %s"
|
||||||
% type(a))
|
% type(a))
|
||||||
nrbits += w
|
nrbits += w
|
||||||
val = val << w | v & (long(1) << w) - 1
|
val = val << w | v & (long(1) << w) - 1
|
||||||
@ -214,7 +211,8 @@ class ConcatSignal(_ShadowSignal):
|
|||||||
if isinstance(a, _Signal):
|
if isinstance(a, _Signal):
|
||||||
lines.append("%s(%s-1 downto %s) <= %s;" % (self._name, hi, lo, a._name))
|
lines.append("%s(%s-1 downto %s) <= %s;" % (self._name, hi, lo, a._name))
|
||||||
else:
|
else:
|
||||||
lines.append('%s(%s-1 downto %s) <= "%s";' % (self._name, hi, lo, bin(ini[hi:lo], w)))
|
lines.append('%s(%s-1 downto %s) <= "%s";' %
|
||||||
|
(self._name, hi, lo, bin(ini[hi:lo], w)))
|
||||||
hi = lo
|
hi = lo
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
@ -240,7 +238,8 @@ class ConcatSignal(_ShadowSignal):
|
|||||||
if isinstance(a, _Signal):
|
if isinstance(a, _Signal):
|
||||||
lines.append("assign %s[%s-1:%s] = %s;" % (self._name, hi, lo, a._name))
|
lines.append("assign %s[%s-1:%s] = %s;" % (self._name, hi, lo, a._name))
|
||||||
else:
|
else:
|
||||||
lines.append("assign %s[%s-1:%s] = 'b%s;" % (self._name, hi, lo, bin(ini[hi:lo], w)))
|
lines.append("assign %s[%s-1:%s] = 'b%s;" %
|
||||||
|
(self._name, hi, lo, bin(ini[hi:lo], w)))
|
||||||
hi = lo
|
hi = lo
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
@ -301,7 +300,6 @@ class _TristateSignal(_ShadowSignal):
|
|||||||
self._next = res
|
self._next = res
|
||||||
_siglist.append(self)
|
_siglist.append(self)
|
||||||
|
|
||||||
|
|
||||||
def toVerilog(self):
|
def toVerilog(self):
|
||||||
lines = []
|
lines = []
|
||||||
for d in self._drivers:
|
for d in self._drivers:
|
||||||
@ -317,7 +315,6 @@ class _TristateSignal(_ShadowSignal):
|
|||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _TristateDriver(_Signal):
|
class _TristateDriver(_Signal):
|
||||||
|
|
||||||
__slots__ = ('_sig',)
|
__slots__ = ('_sig',)
|
||||||
|
@ -63,18 +63,25 @@ class _WaiterList(list):
|
|||||||
|
|
||||||
|
|
||||||
class _PosedgeWaiterList(_WaiterList):
|
class _PosedgeWaiterList(_WaiterList):
|
||||||
|
|
||||||
def __init__(self, sig):
|
def __init__(self, sig):
|
||||||
self.sig = sig
|
self.sig = sig
|
||||||
|
|
||||||
def _toVerilog(self):
|
def _toVerilog(self):
|
||||||
return "posedge %s" % self.sig._name
|
return "posedge %s" % self.sig._name
|
||||||
|
|
||||||
def _toVHDL(self):
|
def _toVHDL(self):
|
||||||
return "rising_edge(%s)" % self.sig._name
|
return "rising_edge(%s)" % self.sig._name
|
||||||
|
|
||||||
|
|
||||||
class _NegedgeWaiterList(_WaiterList):
|
class _NegedgeWaiterList(_WaiterList):
|
||||||
|
|
||||||
def __init__(self, sig):
|
def __init__(self, sig):
|
||||||
self.sig = sig
|
self.sig = sig
|
||||||
|
|
||||||
def _toVerilog(self):
|
def _toVerilog(self):
|
||||||
return "negedge %s" % self.sig._name
|
return "negedge %s" % self.sig._name
|
||||||
|
|
||||||
def _toVHDL(self):
|
def _toVHDL(self):
|
||||||
return "falling_edge(%s)" % self.sig._name
|
return "falling_edge(%s)" % self.sig._name
|
||||||
|
|
||||||
@ -83,11 +90,14 @@ def posedge(sig):
|
|||||||
""" Return a posedge trigger object """
|
""" Return a posedge trigger object """
|
||||||
return sig.posedge
|
return sig.posedge
|
||||||
|
|
||||||
|
|
||||||
def negedge(sig):
|
def negedge(sig):
|
||||||
""" Return a negedge trigger object """
|
""" Return a negedge trigger object """
|
||||||
return sig.negedge
|
return sig.negedge
|
||||||
|
|
||||||
# signal factory function
|
# signal factory function
|
||||||
|
|
||||||
|
|
||||||
def Signal(val=None, delay=None):
|
def Signal(val=None, delay=None):
|
||||||
""" Return a new _Signal (default or delay 0) or DelayedSignal """
|
""" Return a new _Signal (default or delay 0) or DelayedSignal """
|
||||||
if delay is not None:
|
if delay is not None:
|
||||||
@ -97,6 +107,7 @@ def Signal(val=None, delay=None):
|
|||||||
else:
|
else:
|
||||||
return _Signal(val)
|
return _Signal(val)
|
||||||
|
|
||||||
|
|
||||||
class _Signal(object):
|
class _Signal(object):
|
||||||
|
|
||||||
""" _Signal class.
|
""" _Signal class.
|
||||||
@ -116,7 +127,6 @@ class _Signal(object):
|
|||||||
'_numeric'
|
'_numeric'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, val=None):
|
def __init__(self, val=None):
|
||||||
""" Construct a signal.
|
""" Construct a signal.
|
||||||
|
|
||||||
@ -211,8 +221,8 @@ class _Signal(object):
|
|||||||
# support for the 'next' attribute
|
# support for the 'next' attribute
|
||||||
@property
|
@property
|
||||||
def next(self):
|
def next(self):
|
||||||
# if self._next is self._val:
|
# if self._next is self._val:
|
||||||
# self._next = deepcopy(self._val)
|
# self._next = deepcopy(self._val)
|
||||||
_siglist.append(self)
|
_siglist.append(self)
|
||||||
return self._next
|
return self._next
|
||||||
|
|
||||||
@ -332,13 +342,11 @@ class _Signal(object):
|
|||||||
self._slicesigs.append(s)
|
self._slicesigs.append(s)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
### operators for which delegation to current value is appropriate ###
|
### operators for which delegation to current value is appropriate ###
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
raise TypeError("Signals are unhashable")
|
raise TypeError("Signals are unhashable")
|
||||||
|
|
||||||
|
|
||||||
def __bool__(self):
|
def __bool__(self):
|
||||||
return bool(self._val)
|
return bool(self._val)
|
||||||
|
|
||||||
@ -361,6 +369,7 @@ class _Signal(object):
|
|||||||
return self._val + other._val
|
return self._val + other._val
|
||||||
else:
|
else:
|
||||||
return self._val + other
|
return self._val + other
|
||||||
|
|
||||||
def __radd__(self, other):
|
def __radd__(self, other):
|
||||||
return other + self._val
|
return other + self._val
|
||||||
|
|
||||||
@ -369,6 +378,7 @@ class _Signal(object):
|
|||||||
return self._val - other._val
|
return self._val - other._val
|
||||||
else:
|
else:
|
||||||
return self._val - other
|
return self._val - other
|
||||||
|
|
||||||
def __rsub__(self, other):
|
def __rsub__(self, other):
|
||||||
return other - self._val
|
return other - self._val
|
||||||
|
|
||||||
@ -377,6 +387,7 @@ class _Signal(object):
|
|||||||
return self._val * other._val
|
return self._val * other._val
|
||||||
else:
|
else:
|
||||||
return self._val * other
|
return self._val * other
|
||||||
|
|
||||||
def __rmul__(self, other):
|
def __rmul__(self, other):
|
||||||
return other * self._val
|
return other * self._val
|
||||||
|
|
||||||
@ -385,6 +396,7 @@ class _Signal(object):
|
|||||||
return self._val / other._val
|
return self._val / other._val
|
||||||
else:
|
else:
|
||||||
return self._val / other
|
return self._val / other
|
||||||
|
|
||||||
def __rtruediv__(self, other):
|
def __rtruediv__(self, other):
|
||||||
return other / self._val
|
return other / self._val
|
||||||
|
|
||||||
@ -393,6 +405,7 @@ class _Signal(object):
|
|||||||
return self._val // other._val
|
return self._val // other._val
|
||||||
else:
|
else:
|
||||||
return self._val // other
|
return self._val // other
|
||||||
|
|
||||||
def __rfloordiv__(self, other):
|
def __rfloordiv__(self, other):
|
||||||
return other // self._val
|
return other // self._val
|
||||||
|
|
||||||
@ -401,6 +414,7 @@ class _Signal(object):
|
|||||||
return self._val % other._val
|
return self._val % other._val
|
||||||
else:
|
else:
|
||||||
return self._val % other
|
return self._val % other
|
||||||
|
|
||||||
def __rmod__(self, other):
|
def __rmod__(self, other):
|
||||||
return other % self._val
|
return other % self._val
|
||||||
|
|
||||||
@ -411,6 +425,7 @@ class _Signal(object):
|
|||||||
return self._val ** other._val
|
return self._val ** other._val
|
||||||
else:
|
else:
|
||||||
return self._val ** other
|
return self._val ** other
|
||||||
|
|
||||||
def __rpow__(self, other):
|
def __rpow__(self, other):
|
||||||
return other ** self._val
|
return other ** self._val
|
||||||
|
|
||||||
@ -419,6 +434,7 @@ class _Signal(object):
|
|||||||
return self._val << other._val
|
return self._val << other._val
|
||||||
else:
|
else:
|
||||||
return self._val << other
|
return self._val << other
|
||||||
|
|
||||||
def __rlshift__(self, other):
|
def __rlshift__(self, other):
|
||||||
return other << self._val
|
return other << self._val
|
||||||
|
|
||||||
@ -427,6 +443,7 @@ class _Signal(object):
|
|||||||
return self._val >> other._val
|
return self._val >> other._val
|
||||||
else:
|
else:
|
||||||
return self._val >> other
|
return self._val >> other
|
||||||
|
|
||||||
def __rrshift__(self, other):
|
def __rrshift__(self, other):
|
||||||
return other >> self._val
|
return other >> self._val
|
||||||
|
|
||||||
@ -435,6 +452,7 @@ class _Signal(object):
|
|||||||
return self._val & other._val
|
return self._val & other._val
|
||||||
else:
|
else:
|
||||||
return self._val & other
|
return self._val & other
|
||||||
|
|
||||||
def __rand__(self, other):
|
def __rand__(self, other):
|
||||||
return other & self._val
|
return other & self._val
|
||||||
|
|
||||||
@ -443,6 +461,7 @@ class _Signal(object):
|
|||||||
return self._val | other._val
|
return self._val | other._val
|
||||||
else:
|
else:
|
||||||
return self._val | other
|
return self._val | other
|
||||||
|
|
||||||
def __ror__(self, other):
|
def __ror__(self, other):
|
||||||
return other | self._val
|
return other | self._val
|
||||||
|
|
||||||
@ -451,6 +470,7 @@ class _Signal(object):
|
|||||||
return self._val ^ other._val
|
return self._val ^ other._val
|
||||||
else:
|
else:
|
||||||
return self._val ^ other
|
return self._val ^ other
|
||||||
|
|
||||||
def __rxor__(self, other):
|
def __rxor__(self, other):
|
||||||
return other ^ self._val
|
return other ^ self._val
|
||||||
|
|
||||||
@ -486,22 +506,25 @@ class _Signal(object):
|
|||||||
def __index__(self):
|
def __index__(self):
|
||||||
return int(self._val)
|
return int(self._val)
|
||||||
|
|
||||||
|
|
||||||
# comparisons
|
# comparisons
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return self.val == other
|
return self.val == other
|
||||||
|
|
||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
return self.val != other
|
return self.val != other
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
return self.val < other
|
return self.val < other
|
||||||
|
|
||||||
def __le__(self, other):
|
def __le__(self, other):
|
||||||
return self.val <= other
|
return self.val <= other
|
||||||
|
|
||||||
def __gt__(self, other):
|
def __gt__(self, other):
|
||||||
return self.val > other
|
return self.val > other
|
||||||
|
|
||||||
def __ge__(self, other):
|
def __ge__(self, other):
|
||||||
return self.val >= other
|
return self.val >= other
|
||||||
|
|
||||||
|
|
||||||
# method lookup delegation
|
# method lookup delegation
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
return getattr(self._val, attr)
|
return getattr(self._val, attr)
|
||||||
@ -527,12 +550,10 @@ class _Signal(object):
|
|||||||
__ior__ = __iand__ = __ixor__ = __irshift__ = __ilshift__ = _augm
|
__ior__ = __iand__ = __ixor__ = __irshift__ = __ilshift__ = _augm
|
||||||
__itruediv__ = __ifloordiv__ = _augm
|
__itruediv__ = __ifloordiv__ = _augm
|
||||||
|
|
||||||
|
|
||||||
# index and slice assignment not supported
|
# index and slice assignment not supported
|
||||||
def __setitem__(self, key, val):
|
def __setitem__(self, key, val):
|
||||||
raise TypeError("Signal object doesn't support item/slice assignment")
|
raise TypeError("Signal object doesn't support item/slice assignment")
|
||||||
|
|
||||||
|
|
||||||
# continues assignment support
|
# continues assignment support
|
||||||
def assign(self, sig):
|
def assign(self, sig):
|
||||||
|
|
||||||
@ -609,10 +630,12 @@ class _DelayedSignal(_Signal):
|
|||||||
|
|
||||||
|
|
||||||
class _SignalWrap(object):
|
class _SignalWrap(object):
|
||||||
|
|
||||||
def __init__(self, sig, next, timeStamp):
|
def __init__(self, sig, next, timeStamp):
|
||||||
self.sig = sig
|
self.sig = sig
|
||||||
self.next = next
|
self.next = next
|
||||||
self.timeStamp = timeStamp
|
self.timeStamp = timeStamp
|
||||||
|
|
||||||
def apply(self):
|
def apply(self):
|
||||||
return self.sig._apply(self.next, self.timeStamp)
|
return self.sig._apply(self.next, self.timeStamp)
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ from myhdl._block import _Block
|
|||||||
|
|
||||||
schedule = _futureEvents.append
|
schedule = _futureEvents.append
|
||||||
|
|
||||||
|
|
||||||
class _error:
|
class _error:
|
||||||
pass
|
pass
|
||||||
_error.ArgType = "Inappriopriate argument type"
|
_error.ArgType = "Inappriopriate argument type"
|
||||||
@ -46,6 +47,8 @@ _error.MultipleCosim = "Only a single cosimulator argument allowed"
|
|||||||
_error.DuplicatedArg = "Duplicated argument"
|
_error.DuplicatedArg = "Duplicated argument"
|
||||||
|
|
||||||
# flatten Block objects out
|
# flatten Block objects out
|
||||||
|
|
||||||
|
|
||||||
def _flatten(*args):
|
def _flatten(*args):
|
||||||
arglist = []
|
arglist = []
|
||||||
for arg in args:
|
for arg in args:
|
||||||
@ -60,6 +63,7 @@ def _flatten(*args):
|
|||||||
|
|
||||||
_error.MultipleSim = "Only a single Simulation instance is allowed"
|
_error.MultipleSim = "Only a single Simulation instance is allowed"
|
||||||
|
|
||||||
|
|
||||||
class Simulation(object):
|
class Simulation(object):
|
||||||
|
|
||||||
""" Simulation class.
|
""" Simulation class.
|
||||||
@ -89,7 +93,6 @@ class Simulation(object):
|
|||||||
del _futureEvents[:]
|
del _futureEvents[:]
|
||||||
del _siglist[:]
|
del _siglist[:]
|
||||||
|
|
||||||
|
|
||||||
def _finalize(self):
|
def _finalize(self):
|
||||||
cosim = self._cosim
|
cosim = self._cosim
|
||||||
if cosim:
|
if cosim:
|
||||||
@ -110,7 +113,6 @@ class Simulation(object):
|
|||||||
self._finalize()
|
self._finalize()
|
||||||
|
|
||||||
def run(self, duration=None, quiet=0):
|
def run(self, duration=None, quiet=0):
|
||||||
|
|
||||||
""" Run the simulation for some duration.
|
""" Run the simulation for some duration.
|
||||||
|
|
||||||
duration -- specified simulation duration (default: forever)
|
duration -- specified simulation duration (default: forever)
|
||||||
|
@ -227,7 +227,6 @@ def _inferWaiter(gen):
|
|||||||
return _Waiter(gen)
|
return _Waiter(gen)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _YieldVisitor(ast.NodeVisitor):
|
class _YieldVisitor(ast.NodeVisitor):
|
||||||
|
|
||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
@ -286,7 +285,5 @@ class _YieldVisitor(ast.NodeVisitor):
|
|||||||
node.kind = _kind.EDGE
|
node.kind = _kind.EDGE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# avoid problems with recursive imports
|
# avoid problems with recursive imports
|
||||||
from myhdl._instance import _Instantiator
|
from myhdl._instance import _Instantiator
|
||||||
|
|
||||||
|
@ -59,50 +59,82 @@ class StopSimulation(Exception):
|
|||||||
""" Basic exception to stop a Simulation """
|
""" Basic exception to stop a Simulation """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class _SuspendSimulation(Exception):
|
class _SuspendSimulation(Exception):
|
||||||
""" Basic exception to suspend a Simulation """
|
""" Basic exception to suspend a Simulation """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
|
|
||||||
def __init__(self, kind, msg="", info=""):
|
def __init__(self, kind, msg="", info=""):
|
||||||
self.kind = kind
|
self.kind = kind
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
self.info = info
|
self.info = info
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
s = "%s%s" % (self.info, self.kind)
|
s = "%s%s" % (self.info, self.kind)
|
||||||
if self.msg:
|
if self.msg:
|
||||||
s += ": %s" % self.msg
|
s += ": %s" % self.msg
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
class AlwaysError(Error):
|
class AlwaysError(Error):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AlwaysCombError(Error):
|
class AlwaysCombError(Error):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class InstanceError(Error):
|
class InstanceError(Error):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class BlockError(Error):
|
class BlockError(Error):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class BlockInstanceError(Error):
|
class BlockInstanceError(Error):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CosimulationError(Error):
|
class CosimulationError(Error):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ExtractHierarchyError(Error):
|
class ExtractHierarchyError(Error):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class SimulationError(Error):
|
class SimulationError(Error):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TraceSignalsError(Error):
|
class TraceSignalsError(Error):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ConversionError(Error):
|
class ConversionError(Error):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ToVerilogError(ConversionError):
|
class ToVerilogError(ConversionError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ToVHDLError(ConversionError):
|
class ToVHDLError(ConversionError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ConversionWarning(UserWarning):
|
class ConversionWarning(UserWarning):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ToVerilogWarning(ConversionWarning):
|
class ToVerilogWarning(ConversionWarning):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ToVHDLWarning(ConversionWarning):
|
class ToVHDLWarning(ConversionWarning):
|
||||||
pass
|
pass
|
||||||
# warnings.filterwarnings('always', r".*", ToVerilogWarning)
|
# warnings.filterwarnings('always', r".*", ToVerilogWarning)
|
||||||
|
@ -32,6 +32,7 @@ from myhdl._Waiter import _Waiter, _SignalWaiter, _SignalTupleWaiter, \
|
|||||||
_DelayWaiter, _EdgeWaiter, _EdgeTupleWaiter
|
_DelayWaiter, _EdgeWaiter, _EdgeTupleWaiter
|
||||||
from myhdl._instance import _Instantiator, _getCallInfo
|
from myhdl._instance import _Instantiator, _getCallInfo
|
||||||
|
|
||||||
|
|
||||||
class _error:
|
class _error:
|
||||||
pass
|
pass
|
||||||
_error.DecArgType = "decorator argument should be a Signal, edge, or delay"
|
_error.DecArgType = "decorator argument should be a Signal, edge, or delay"
|
||||||
@ -39,6 +40,7 @@ _error.ArgType = "decorated object should be a classic (non-generator) function"
|
|||||||
_error.NrOfArgs = "decorated function should not have arguments"
|
_error.NrOfArgs = "decorated function should not have arguments"
|
||||||
_error.DecNrOfArgs = "decorator should have arguments"
|
_error.DecNrOfArgs = "decorator should have arguments"
|
||||||
|
|
||||||
|
|
||||||
def _getSigdict(sigs, symdict):
|
def _getSigdict(sigs, symdict):
|
||||||
"""Lookup signals in caller namespace and return sigdict
|
"""Lookup signals in caller namespace and return sigdict
|
||||||
|
|
||||||
@ -56,6 +58,7 @@ def _getSigdict(sigs, symdict):
|
|||||||
sigdict[n] = s
|
sigdict[n] = s
|
||||||
return sigdict
|
return sigdict
|
||||||
|
|
||||||
|
|
||||||
def always(*args):
|
def always(*args):
|
||||||
callinfo = _getCallInfo()
|
callinfo = _getCallInfo()
|
||||||
sigargs = []
|
sigargs = []
|
||||||
@ -71,6 +74,7 @@ def always(*args):
|
|||||||
elif not isinstance(arg, delay):
|
elif not isinstance(arg, delay):
|
||||||
raise AlwaysError(_error.DecArgType)
|
raise AlwaysError(_error.DecArgType)
|
||||||
sigdict = _getSigdict(sigargs, callinfo.symdict)
|
sigdict = _getSigdict(sigargs, callinfo.symdict)
|
||||||
|
|
||||||
def _always_decorator(func):
|
def _always_decorator(func):
|
||||||
if not isinstance(func, FunctionType):
|
if not isinstance(func, FunctionType):
|
||||||
raise AlwaysError(_error.ArgType)
|
raise AlwaysError(_error.ArgType)
|
||||||
|
@ -28,6 +28,7 @@ from myhdl._util import _isGenFunc
|
|||||||
from myhdl._instance import _getCallInfo
|
from myhdl._instance import _getCallInfo
|
||||||
from myhdl._always import _Always
|
from myhdl._always import _Always
|
||||||
|
|
||||||
|
|
||||||
class _error:
|
class _error:
|
||||||
pass
|
pass
|
||||||
_error.ArgType = "always_comb argument should be a classic function"
|
_error.ArgType = "always_comb argument should be a classic function"
|
||||||
@ -37,6 +38,7 @@ _error.SignalAsInout = "signal (%s) used as inout in always_comb function argume
|
|||||||
_error.EmbeddedFunction = "embedded functions in always_comb function argument not supported"
|
_error.EmbeddedFunction = "embedded functions in always_comb function argument not supported"
|
||||||
_error.EmptySensitivityList = "sensitivity list is empty"
|
_error.EmptySensitivityList = "sensitivity list is empty"
|
||||||
|
|
||||||
|
|
||||||
def always_comb(func):
|
def always_comb(func):
|
||||||
callinfo = _getCallInfo()
|
callinfo = _getCallInfo()
|
||||||
if not isinstance(func, FunctionType):
|
if not isinstance(func, FunctionType):
|
||||||
|
@ -32,6 +32,7 @@ from myhdl._instance import _getCallInfo
|
|||||||
# evacuate this later
|
# evacuate this later
|
||||||
AlwaysSeqError = AlwaysError
|
AlwaysSeqError = AlwaysError
|
||||||
|
|
||||||
|
|
||||||
class _error:
|
class _error:
|
||||||
pass
|
pass
|
||||||
_error.EdgeType = "first argument should be an edge"
|
_error.EdgeType = "first argument should be an edge"
|
||||||
@ -41,7 +42,9 @@ _error.NrOfArgs = "decorated function should not have arguments"
|
|||||||
_error.SigAugAssign = "signal assignment does not support augmented assignment"
|
_error.SigAugAssign = "signal assignment does not support augmented assignment"
|
||||||
_error.EmbeddedFunction = "embedded functions in always_seq function not supported"
|
_error.EmbeddedFunction = "embedded functions in always_seq function not supported"
|
||||||
|
|
||||||
|
|
||||||
class ResetSignal(_Signal):
|
class ResetSignal(_Signal):
|
||||||
|
|
||||||
def __init__(self, val, active, async):
|
def __init__(self, val, active, async):
|
||||||
""" Construct a ResetSignal.
|
""" Construct a ResetSignal.
|
||||||
|
|
||||||
@ -52,6 +55,7 @@ class ResetSignal(_Signal):
|
|||||||
self.active = bool(active)
|
self.active = bool(active)
|
||||||
self.async = async
|
self.async = async
|
||||||
|
|
||||||
|
|
||||||
def always_seq(edge, reset):
|
def always_seq(edge, reset):
|
||||||
callinfo = _getCallInfo()
|
callinfo = _getCallInfo()
|
||||||
sigargs = []
|
sigargs = []
|
||||||
|
@ -54,4 +54,3 @@ def bin(num, width=0):
|
|||||||
pad = '1'
|
pad = '1'
|
||||||
return (width - len(s)) * pad + s
|
return (width - len(s)) * pad + s
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
@ -38,12 +38,15 @@ class _error:
|
|||||||
_error.ArgType = "A block should return block or instantiator objects"
|
_error.ArgType = "A block should return block or instantiator objects"
|
||||||
_error.InstanceError = "%s: subblock %s should be encapsulated in a block decorator"
|
_error.InstanceError = "%s: subblock %s should be encapsulated in a block decorator"
|
||||||
|
|
||||||
|
|
||||||
class _CallInfo(object):
|
class _CallInfo(object):
|
||||||
|
|
||||||
def __init__(self, name, modctxt, symdict):
|
def __init__(self, name, modctxt, symdict):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.modctxt = modctxt
|
self.modctxt = modctxt
|
||||||
self.symdict = symdict
|
self.symdict = symdict
|
||||||
|
|
||||||
|
|
||||||
def _getCallInfo():
|
def _getCallInfo():
|
||||||
"""Get info on the caller of a BlockInstance.
|
"""Get info on the caller of a BlockInstance.
|
||||||
|
|
||||||
@ -76,9 +79,11 @@ def _getCallInfo():
|
|||||||
modctxt = isinstance(f_locals['self'], _Block)
|
modctxt = isinstance(f_locals['self'], _Block)
|
||||||
return _CallInfo(name, modctxt, symdict)
|
return _CallInfo(name, modctxt, symdict)
|
||||||
|
|
||||||
|
|
||||||
def block(func):
|
def block(func):
|
||||||
srcfile = inspect.getsourcefile(func)
|
srcfile = inspect.getsourcefile(func)
|
||||||
srcline = inspect.getsourcelines(func)[0]
|
srcline = inspect.getsourcelines(func)[0]
|
||||||
|
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def deco(*args, **kwargs):
|
def deco(*args, **kwargs):
|
||||||
deco.calls += 1
|
deco.calls += 1
|
||||||
@ -86,6 +91,7 @@ def block(func):
|
|||||||
deco.calls = 0
|
deco.calls = 0
|
||||||
return deco
|
return deco
|
||||||
|
|
||||||
|
|
||||||
class _Block(object):
|
class _Block(object):
|
||||||
|
|
||||||
def __init__(self, func, deco, srcfile, srcline, *args, **kwargs):
|
def __init__(self, func, deco, srcfile, srcline, *args, **kwargs):
|
||||||
|
@ -28,7 +28,6 @@ from myhdl._Signal import _Signal
|
|||||||
from myhdl._compat import long
|
from myhdl._compat import long
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def concat(base, *args):
|
def concat(base, *args):
|
||||||
|
|
||||||
if isinstance(base, intbv):
|
if isinstance(base, intbv):
|
||||||
@ -50,7 +49,7 @@ def concat(base, *args):
|
|||||||
basewidth = len(base)
|
basewidth = len(base)
|
||||||
val = long(base, 2)
|
val = long(base, 2)
|
||||||
else:
|
else:
|
||||||
raise TypeError("concat: inappropriate first argument type: %s" \
|
raise TypeError("concat: inappropriate first argument type: %s"
|
||||||
% type(base))
|
% type(base))
|
||||||
|
|
||||||
width = 0
|
width = 0
|
||||||
@ -71,7 +70,7 @@ def concat(base, *args):
|
|||||||
w = len(arg)
|
w = len(arg)
|
||||||
v = long(arg, 2)
|
v = long(arg, 2)
|
||||||
else:
|
else:
|
||||||
raise TypeError("concat: inappropriate argument type: %s" \
|
raise TypeError("concat: inappropriate argument type: %s"
|
||||||
% type(arg))
|
% type(arg))
|
||||||
if not w:
|
if not w:
|
||||||
raise TypeError("concat: arg on pos %d should have length" % (i + 1))
|
raise TypeError("concat: arg on pos %d should have length" % (i + 1))
|
||||||
@ -82,4 +81,3 @@ def concat(base, *args):
|
|||||||
return intbv(val, _nrbits=basewidth + width)
|
return intbv(val, _nrbits=basewidth + width)
|
||||||
else:
|
else:
|
||||||
return intbv(val)
|
return intbv(val)
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ from myhdl._compat import integer_types
|
|||||||
|
|
||||||
_errmsg = "arg of delay constructor should be a natural integeer"
|
_errmsg = "arg of delay constructor should be a natural integeer"
|
||||||
|
|
||||||
|
|
||||||
class delay(object):
|
class delay(object):
|
||||||
|
|
||||||
""" Class to model delay in yield statements. """
|
""" Class to model delay in yield statements. """
|
||||||
|
@ -27,22 +27,27 @@ from myhdl._bin import bin
|
|||||||
from myhdl._Signal import _Signal
|
from myhdl._Signal import _Signal
|
||||||
from myhdl._compat import string_types
|
from myhdl._compat import string_types
|
||||||
|
|
||||||
|
|
||||||
class EnumType(object):
|
class EnumType(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
raise TypeError("class EnumType is only intended for type checking on subclasses")
|
raise TypeError("class EnumType is only intended for type checking on subclasses")
|
||||||
|
|
||||||
|
|
||||||
class EnumItemType(object):
|
class EnumItemType(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
raise TypeError("class EnumItemType is only intended for type checking on subclasses")
|
raise TypeError("class EnumItemType is only intended for type checking on subclasses")
|
||||||
|
|
||||||
supported_encodings = ("binary", "one_hot", "one_cold")
|
supported_encodings = ("binary", "one_hot", "one_cold")
|
||||||
|
|
||||||
|
|
||||||
def enum(*names, **kwargs):
|
def enum(*names, **kwargs):
|
||||||
|
|
||||||
# args = args
|
# args = args
|
||||||
encoding = kwargs.get('encoding', None)
|
encoding = kwargs.get('encoding', None)
|
||||||
if encoding is not None and encoding not in supported_encodings:
|
if encoding is not None and encoding not in supported_encodings:
|
||||||
raise ValueError("Unsupported enum encoding: %s\n Supported encodings: %s" % \
|
raise ValueError("Unsupported enum encoding: %s\n Supported encodings: %s" %
|
||||||
(encoding, supported_encodings))
|
(encoding, supported_encodings))
|
||||||
if encoding in ("one_hot", "one_cold"):
|
if encoding in ("one_hot", "one_cold"):
|
||||||
nrbits = len(names)
|
nrbits = len(names)
|
||||||
@ -130,8 +135,8 @@ def enum(*names, **kwargs):
|
|||||||
raise TypeError("Type mismatch in enum item comparison")
|
raise TypeError("Type mismatch in enum item comparison")
|
||||||
return self is not other
|
return self is not other
|
||||||
|
|
||||||
|
|
||||||
class Enum(EnumType):
|
class Enum(EnumType):
|
||||||
|
|
||||||
def __init__(self, names, codedict, nrbits, encoding):
|
def __init__(self, names, codedict, nrbits, encoding):
|
||||||
self.__dict__['_names'] = names
|
self.__dict__['_names'] = names
|
||||||
self.__dict__['_nrbits'] = nrbits
|
self.__dict__['_nrbits'] = nrbits
|
||||||
@ -171,8 +176,3 @@ def enum(*names, **kwargs):
|
|||||||
return str
|
return str
|
||||||
|
|
||||||
return Enum(names, codedict, nrbits, encoding)
|
return Enum(names, codedict, nrbits, encoding)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ from myhdl._getcellvars import _getCellVars
|
|||||||
|
|
||||||
_profileFunc = None
|
_profileFunc = None
|
||||||
|
|
||||||
|
|
||||||
class _error:
|
class _error:
|
||||||
pass
|
pass
|
||||||
_error.NoInstances = "No instances found"
|
_error.NoInstances = "No instances found"
|
||||||
@ -47,6 +48,7 @@ _error.InconsistentToplevel = "Inconsistent top level %s for %s - should be 1"
|
|||||||
|
|
||||||
class _Instance(object):
|
class _Instance(object):
|
||||||
__slots__ = ['level', 'obj', 'subs', 'sigdict', 'memdict', 'name']
|
__slots__ = ['level', 'obj', 'subs', 'sigdict', 'memdict', 'name']
|
||||||
|
|
||||||
def __init__(self, level, obj, subs, sigdict, memdict):
|
def __init__(self, level, obj, subs, sigdict, memdict):
|
||||||
self.level = level
|
self.level = level
|
||||||
self.obj = obj
|
self.obj = obj
|
||||||
@ -57,8 +59,10 @@ class _Instance(object):
|
|||||||
|
|
||||||
_memInfoMap = {}
|
_memInfoMap = {}
|
||||||
|
|
||||||
|
|
||||||
class _MemInfo(object):
|
class _MemInfo(object):
|
||||||
__slots__ = ['mem', 'name', 'elObj', 'depth', '_used', '_driven', '_read']
|
__slots__ = ['mem', 'name', 'elObj', 'depth', '_used', '_driven', '_read']
|
||||||
|
|
||||||
def __init__(self, mem):
|
def __init__(self, mem):
|
||||||
self.mem = mem
|
self.mem = mem
|
||||||
self.name = None
|
self.name = None
|
||||||
@ -72,12 +76,14 @@ class _MemInfo(object):
|
|||||||
def _getMemInfo(mem):
|
def _getMemInfo(mem):
|
||||||
return _memInfoMap[id(mem)]
|
return _memInfoMap[id(mem)]
|
||||||
|
|
||||||
|
|
||||||
def _makeMemInfo(mem):
|
def _makeMemInfo(mem):
|
||||||
key = id(mem)
|
key = id(mem)
|
||||||
if key not in _memInfoMap:
|
if key not in _memInfoMap:
|
||||||
_memInfoMap[key] = _MemInfo(mem)
|
_memInfoMap[key] = _MemInfo(mem)
|
||||||
return _memInfoMap[key]
|
return _memInfoMap[key]
|
||||||
|
|
||||||
|
|
||||||
def _isMem(mem):
|
def _isMem(mem):
|
||||||
return id(mem) in _memInfoMap
|
return id(mem) in _memInfoMap
|
||||||
|
|
||||||
@ -85,8 +91,10 @@ _userCodeMap = {'verilog': {},
|
|||||||
'vhdl': {}
|
'vhdl': {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _UserCode(object):
|
class _UserCode(object):
|
||||||
__slots__ = ['code', 'namespace', 'funcname', 'func', 'sourcefile', 'sourceline']
|
__slots__ = ['code', 'namespace', 'funcname', 'func', 'sourcefile', 'sourceline']
|
||||||
|
|
||||||
def __init__(self, code, namespace, funcname, func, sourcefile, sourceline):
|
def __init__(self, code, namespace, funcname, func, sourcefile, sourceline):
|
||||||
self.code = code
|
self.code = code
|
||||||
self.namespace = namespace
|
self.namespace = namespace
|
||||||
@ -110,26 +118,35 @@ class _UserCode(object):
|
|||||||
def _interpolate(self):
|
def _interpolate(self):
|
||||||
return string.Template(self.code).substitute(self.namespace)
|
return string.Template(self.code).substitute(self.namespace)
|
||||||
|
|
||||||
|
|
||||||
class _UserCodeDepr(_UserCode):
|
class _UserCodeDepr(_UserCode):
|
||||||
|
|
||||||
def _interpolate(self):
|
def _interpolate(self):
|
||||||
return self.code % self.namespace
|
return self.code % self.namespace
|
||||||
|
|
||||||
|
|
||||||
class _UserVerilogCode(_UserCode):
|
class _UserVerilogCode(_UserCode):
|
||||||
|
|
||||||
def raiseError(self, msg, info):
|
def raiseError(self, msg, info):
|
||||||
raise ToVerilogError("Error in user defined Verilog code", msg, info)
|
raise ToVerilogError("Error in user defined Verilog code", msg, info)
|
||||||
|
|
||||||
|
|
||||||
class _UserVhdlCode(_UserCode):
|
class _UserVhdlCode(_UserCode):
|
||||||
|
|
||||||
def raiseError(self, msg, info):
|
def raiseError(self, msg, info):
|
||||||
raise ToVHDLError("Error in user defined VHDL code", msg, info)
|
raise ToVHDLError("Error in user defined VHDL code", msg, info)
|
||||||
|
|
||||||
|
|
||||||
class _UserVerilogCodeDepr(_UserVerilogCode, _UserCodeDepr):
|
class _UserVerilogCodeDepr(_UserVerilogCode, _UserCodeDepr):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class _UserVhdlCodeDepr(_UserVhdlCode, _UserCodeDepr):
|
class _UserVhdlCodeDepr(_UserVhdlCode, _UserCodeDepr):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class _UserVerilogInstance(_UserVerilogCode):
|
class _UserVerilogInstance(_UserVerilogCode):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
args = inspect.getargspec(self.func)[0]
|
args = inspect.getargspec(self.func)[0]
|
||||||
s = "%s %s(" % (self.funcname, self.code)
|
s = "%s %s(" % (self.funcname, self.code)
|
||||||
@ -143,7 +160,9 @@ class _UserVerilogInstance(_UserVerilogCode):
|
|||||||
s += "\n);\n\n"
|
s += "\n);\n\n"
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
class _UserVhdlInstance(_UserVhdlCode):
|
class _UserVhdlInstance(_UserVhdlCode):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
args = inspect.getargspec(self.func)[0]
|
args = inspect.getargspec(self.func)[0]
|
||||||
s = "%s: entity work.%s(MyHDL)\n" % (self.code, self.funcname)
|
s = "%s: entity work.%s(MyHDL)\n" % (self.code, self.funcname)
|
||||||
@ -159,7 +178,6 @@ class _UserVhdlInstance(_UserVhdlCode):
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _addUserCode(specs, arg, funcname, func, frame):
|
def _addUserCode(specs, arg, funcname, func, frame):
|
||||||
classMap = {
|
classMap = {
|
||||||
'__verilog__': _UserVerilogCodeDepr,
|
'__verilog__': _UserVerilogCodeDepr,
|
||||||
@ -189,7 +207,8 @@ def _addUserCode(specs, arg, funcname, func, frame):
|
|||||||
if spec:
|
if spec:
|
||||||
assert id(arg) not in _userCodeMap[hdl]
|
assert id(arg) not in _userCodeMap[hdl]
|
||||||
code = specs[spec]
|
code = specs[spec]
|
||||||
_userCodeMap[hdl][id(arg)] = classMap[spec](code, namespace, funcname, func, sourcefile, sourceline)
|
_userCodeMap[hdl][id(arg)] = classMap[spec](
|
||||||
|
code, namespace, funcname, func, sourcefile, sourceline)
|
||||||
|
|
||||||
|
|
||||||
class _CallFuncVisitor(object):
|
class _CallFuncVisitor(object):
|
||||||
@ -207,7 +226,6 @@ class _CallFuncVisitor(object):
|
|||||||
self.lineno = node.lineno
|
self.lineno = node.lineno
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _HierExtr(object):
|
class _HierExtr(object):
|
||||||
|
|
||||||
def __init__(self, name, dut, *args, **kwargs):
|
def __init__(self, name, dut, *args, **kwargs):
|
||||||
@ -216,10 +234,10 @@ class _HierExtr(object):
|
|||||||
_memInfoMap.clear()
|
_memInfoMap.clear()
|
||||||
for hdl in _userCodeMap:
|
for hdl in _userCodeMap:
|
||||||
_userCodeMap[hdl].clear()
|
_userCodeMap[hdl].clear()
|
||||||
self.skipNames = ('always_comb', 'instance', \
|
self.skipNames = ('always_comb', 'instance',
|
||||||
'always_seq', '_always_seq_decorator', \
|
'always_seq', '_always_seq_decorator',
|
||||||
'always', '_always_decorator', \
|
'always', '_always_decorator',
|
||||||
'instances', \
|
'instances',
|
||||||
'processes', 'posedge', 'negedge')
|
'processes', 'posedge', 'negedge')
|
||||||
self.skip = 0
|
self.skip = 0
|
||||||
self.hierarchy = hierarchy = []
|
self.hierarchy = hierarchy = []
|
||||||
@ -260,7 +278,6 @@ class _HierExtr(object):
|
|||||||
names[id(soi)] = sni
|
names[id(soi)] = sni
|
||||||
absnames[id(soi)] = "%s_%s_%s" % (tn, sn, i)
|
absnames[id(soi)] = "%s_%s_%s" % (tn, sn, i)
|
||||||
|
|
||||||
|
|
||||||
def extractor(self, frame, event, arg):
|
def extractor(self, frame, event, arg):
|
||||||
if event == "call":
|
if event == "call":
|
||||||
|
|
||||||
@ -324,8 +341,8 @@ class _HierExtr(object):
|
|||||||
# extract signals and memories
|
# extract signals and memories
|
||||||
# also keep track of whether they are used in generators
|
# also keep track of whether they are used in generators
|
||||||
# only include objects that are used in generators
|
# only include objects that are used in generators
|
||||||
# if not n in cellvars:
|
# if not n in cellvars:
|
||||||
# continue
|
# continue
|
||||||
if isinstance(v, _Signal):
|
if isinstance(v, _Signal):
|
||||||
sigdict[n] = v
|
sigdict[n] = v
|
||||||
if n in cellvars:
|
if n in cellvars:
|
||||||
|
@ -26,7 +26,9 @@ from __future__ import absolute_import
|
|||||||
from myhdl._extractHierarchy import _Instance
|
from myhdl._extractHierarchy import _Instance
|
||||||
from myhdl._block import _Block
|
from myhdl._block import _Block
|
||||||
|
|
||||||
|
|
||||||
class _Hierarchy(object):
|
class _Hierarchy(object):
|
||||||
|
|
||||||
def __init__(self, name, modinst):
|
def __init__(self, name, modinst):
|
||||||
self.top = modinst
|
self.top = modinst
|
||||||
self.hierarchy = hierarchy = []
|
self.hierarchy = hierarchy = []
|
||||||
@ -49,10 +51,12 @@ class _Hierarchy(object):
|
|||||||
# print (names)
|
# print (names)
|
||||||
# print(absnames)
|
# print(absnames)
|
||||||
|
|
||||||
|
|
||||||
def _getHierarchy(name, modinst):
|
def _getHierarchy(name, modinst):
|
||||||
h = _Hierarchy(name, modinst)
|
h = _Hierarchy(name, modinst)
|
||||||
return h
|
return h
|
||||||
|
|
||||||
|
|
||||||
def _getHierarchyHelper(level, modinst, hierarchy):
|
def _getHierarchyHelper(level, modinst, hierarchy):
|
||||||
subs = [(s.name, s) for s in modinst.subs]
|
subs = [(s.name, s) for s in modinst.subs]
|
||||||
inst = _Instance(level, modinst, subs, modinst.sigdict, modinst.memdict)
|
inst = _Instance(level, modinst, subs, modinst.sigdict, modinst.memdict)
|
||||||
|
@ -7,6 +7,7 @@ from myhdl._util import _flatten
|
|||||||
class Data():
|
class Data():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def _getCellVars(symdict, arg):
|
def _getCellVars(symdict, arg):
|
||||||
gens = _flatten(arg)
|
gens = _flatten(arg)
|
||||||
data = Data()
|
data = Data()
|
||||||
@ -16,7 +17,9 @@ def _getCellVars(symdict, arg):
|
|||||||
v.visit(gen.ast)
|
v.visit(gen.ast)
|
||||||
return list(data.objset)
|
return list(data.objset)
|
||||||
|
|
||||||
|
|
||||||
class _GetCellVars(ast.NodeVisitor):
|
class _GetCellVars(ast.NodeVisitor):
|
||||||
|
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
self.data = data
|
self.data = data
|
||||||
self.data.objset = set()
|
self.data.objset = set()
|
||||||
|
@ -30,12 +30,15 @@ from myhdl._Waiter import _inferWaiter
|
|||||||
from myhdl._resolverefs import _AttrRefTransformer
|
from myhdl._resolverefs import _AttrRefTransformer
|
||||||
from myhdl._visitors import _SigNameVisitor
|
from myhdl._visitors import _SigNameVisitor
|
||||||
|
|
||||||
|
|
||||||
class _error:
|
class _error:
|
||||||
pass
|
pass
|
||||||
_error.NrOfArgs = "decorated generator function should not have arguments"
|
_error.NrOfArgs = "decorated generator function should not have arguments"
|
||||||
_error.ArgType = "decorated object should be a generator function"
|
_error.ArgType = "decorated object should be a generator function"
|
||||||
|
|
||||||
|
|
||||||
class _CallInfo(object):
|
class _CallInfo(object):
|
||||||
|
|
||||||
def __init__(self, name, modctxt, symdict):
|
def __init__(self, name, modctxt, symdict):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.modctxt = modctxt
|
self.modctxt = modctxt
|
||||||
@ -77,6 +80,7 @@ def instance(genfunc):
|
|||||||
raise InstanceError(_error.NrOfArgs)
|
raise InstanceError(_error.NrOfArgs)
|
||||||
return _Instantiator(genfunc, callinfo=callinfo)
|
return _Instantiator(genfunc, callinfo=callinfo)
|
||||||
|
|
||||||
|
|
||||||
class _Instantiator(object):
|
class _Instantiator(object):
|
||||||
|
|
||||||
def __init__(self, genfunc, callinfo):
|
def __init__(self, genfunc, callinfo):
|
||||||
|
@ -25,7 +25,6 @@ from myhdl._compat import long, integer_types, string_types, builtins
|
|||||||
from myhdl._bin import bin
|
from myhdl._bin import bin
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class intbv(object):
|
class intbv(object):
|
||||||
#__slots__ = ('_val', '_min', '_max', '_nrbits', '_handleBounds')
|
#__slots__ = ('_val', '_min', '_max', '_nrbits', '_handleBounds')
|
||||||
|
|
||||||
@ -87,7 +86,6 @@ class intbv(object):
|
|||||||
return False
|
return False
|
||||||
return max & max - 1 == 0
|
return max & max - 1 == 0
|
||||||
|
|
||||||
|
|
||||||
# hash
|
# hash
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
raise TypeError("intbv objects are unhashable")
|
raise TypeError("intbv objects are unhashable")
|
||||||
@ -132,13 +130,13 @@ class intbv(object):
|
|||||||
j = 0
|
j = 0
|
||||||
j = int(j)
|
j = int(j)
|
||||||
if j < 0:
|
if j < 0:
|
||||||
raise ValueError("intbv[i:j] requires j >= 0\n" \
|
raise ValueError("intbv[i:j] requires j >= 0\n"
|
||||||
" j == %s" % j)
|
" j == %s" % j)
|
||||||
if i is None: # default
|
if i is None: # default
|
||||||
return intbv(self._val >> j)
|
return intbv(self._val >> j)
|
||||||
i = int(i)
|
i = int(i)
|
||||||
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 & (long(1) << i) - 1) >> j, _nrbits=i - j)
|
res = intbv((self._val & (long(1) << i) - 1) >> j, _nrbits=i - j)
|
||||||
return res
|
return res
|
||||||
@ -147,8 +145,6 @@ class intbv(object):
|
|||||||
res = bool((self._val >> i) & 0x1)
|
res = bool((self._val >> i) & 0x1)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def __setitem__(self, key, val):
|
def __setitem__(self, key, val):
|
||||||
# convert val to int to avoid confusion with intbv or Signals
|
# convert val to int to avoid confusion with intbv or Signals
|
||||||
val = int(val)
|
val = int(val)
|
||||||
@ -158,7 +154,7 @@ class intbv(object):
|
|||||||
j = 0
|
j = 0
|
||||||
j = int(j)
|
j = int(j)
|
||||||
if j < 0:
|
if j < 0:
|
||||||
raise ValueError("intbv[i:j] = v requires j >= 0\n" \
|
raise ValueError("intbv[i:j] = v requires j >= 0\n"
|
||||||
" j == %s" % j)
|
" j == %s" % j)
|
||||||
if i is None: # default
|
if i is None: # default
|
||||||
q = self._val % (long(1) << j)
|
q = self._val % (long(1) << j)
|
||||||
@ -167,11 +163,11 @@ class intbv(object):
|
|||||||
return
|
return
|
||||||
i = int(i)
|
i = int(i)
|
||||||
if i <= j:
|
if i <= j:
|
||||||
raise ValueError("intbv[i:j] = v requires i > j\n" \
|
raise ValueError("intbv[i:j] = v requires i > j\n"
|
||||||
" i, j, v == %s, %s, %s" % (i, j, val))
|
" i, j, v == %s, %s, %s" % (i, j, val))
|
||||||
lim = (long(1) << (i - j))
|
lim = (long(1) << (i - j))
|
||||||
if val >= lim or val < -lim:
|
if val >= lim or val < -lim:
|
||||||
raise ValueError("intbv[i:j] = v abs(v) too large\n" \
|
raise ValueError("intbv[i:j] = v abs(v) too large\n"
|
||||||
" i, j, v == %s, %s, %s" % (i, j, val))
|
" i, j, v == %s, %s, %s" % (i, j, val))
|
||||||
mask = (lim - 1) << j
|
mask = (lim - 1) << j
|
||||||
self._val &= ~mask
|
self._val &= ~mask
|
||||||
@ -184,13 +180,11 @@ class intbv(object):
|
|||||||
elif val == 0:
|
elif val == 0:
|
||||||
self._val &= ~(long(1) << i)
|
self._val &= ~(long(1) << i)
|
||||||
else:
|
else:
|
||||||
raise ValueError("intbv[i] = v requires v in (0, 1)\n" \
|
raise ValueError("intbv[i] = v requires v in (0, 1)\n"
|
||||||
" i == %s " % i)
|
" i == %s " % i)
|
||||||
|
|
||||||
self._handleBounds()
|
self._handleBounds()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# integer-like methods
|
# integer-like methods
|
||||||
|
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
@ -198,6 +192,7 @@ class intbv(object):
|
|||||||
return self._val + other._val
|
return self._val + other._val
|
||||||
else:
|
else:
|
||||||
return self._val + other
|
return self._val + other
|
||||||
|
|
||||||
def __radd__(self, other):
|
def __radd__(self, other):
|
||||||
return other + self._val
|
return other + self._val
|
||||||
|
|
||||||
@ -206,6 +201,7 @@ class intbv(object):
|
|||||||
return self._val - other._val
|
return self._val - other._val
|
||||||
else:
|
else:
|
||||||
return self._val - other
|
return self._val - other
|
||||||
|
|
||||||
def __rsub__(self, other):
|
def __rsub__(self, other):
|
||||||
return other - self._val
|
return other - self._val
|
||||||
|
|
||||||
@ -214,6 +210,7 @@ class intbv(object):
|
|||||||
return self._val * other._val
|
return self._val * other._val
|
||||||
else:
|
else:
|
||||||
return self._val * other
|
return self._val * other
|
||||||
|
|
||||||
def __rmul__(self, other):
|
def __rmul__(self, other):
|
||||||
return other * self._val
|
return other * self._val
|
||||||
|
|
||||||
@ -222,6 +219,7 @@ class intbv(object):
|
|||||||
return self._val / other._val
|
return self._val / other._val
|
||||||
else:
|
else:
|
||||||
return self._val / other
|
return self._val / other
|
||||||
|
|
||||||
def __rtruediv__(self, other):
|
def __rtruediv__(self, other):
|
||||||
return other / self._val
|
return other / self._val
|
||||||
|
|
||||||
@ -230,6 +228,7 @@ class intbv(object):
|
|||||||
return self._val // other._val
|
return self._val // other._val
|
||||||
else:
|
else:
|
||||||
return self._val // other
|
return self._val // other
|
||||||
|
|
||||||
def __rfloordiv__(self, other):
|
def __rfloordiv__(self, other):
|
||||||
return other // self._val
|
return other // self._val
|
||||||
|
|
||||||
@ -238,6 +237,7 @@ class intbv(object):
|
|||||||
return self._val % other._val
|
return self._val % other._val
|
||||||
else:
|
else:
|
||||||
return self._val % other
|
return self._val % other
|
||||||
|
|
||||||
def __rmod__(self, other):
|
def __rmod__(self, other):
|
||||||
return other % self._val
|
return other % self._val
|
||||||
|
|
||||||
@ -248,6 +248,7 @@ class intbv(object):
|
|||||||
return self._val ** other._val
|
return self._val ** other._val
|
||||||
else:
|
else:
|
||||||
return self._val ** other
|
return self._val ** other
|
||||||
|
|
||||||
def __rpow__(self, other):
|
def __rpow__(self, other):
|
||||||
return other ** self._val
|
return other ** self._val
|
||||||
|
|
||||||
@ -256,6 +257,7 @@ class intbv(object):
|
|||||||
return intbv(long(self._val) << other._val)
|
return intbv(long(self._val) << other._val)
|
||||||
else:
|
else:
|
||||||
return intbv(long(self._val) << other)
|
return intbv(long(self._val) << other)
|
||||||
|
|
||||||
def __rlshift__(self, other):
|
def __rlshift__(self, other):
|
||||||
return other << self._val
|
return other << self._val
|
||||||
|
|
||||||
@ -264,6 +266,7 @@ class intbv(object):
|
|||||||
return intbv(self._val >> other._val)
|
return intbv(self._val >> other._val)
|
||||||
else:
|
else:
|
||||||
return intbv(self._val >> other)
|
return intbv(self._val >> other)
|
||||||
|
|
||||||
def __rrshift__(self, other):
|
def __rrshift__(self, other):
|
||||||
return other >> self._val
|
return other >> self._val
|
||||||
|
|
||||||
@ -272,6 +275,7 @@ class intbv(object):
|
|||||||
return intbv(self._val & other._val)
|
return intbv(self._val & other._val)
|
||||||
else:
|
else:
|
||||||
return intbv(self._val & other)
|
return intbv(self._val & other)
|
||||||
|
|
||||||
def __rand__(self, other):
|
def __rand__(self, other):
|
||||||
return intbv(other & self._val)
|
return intbv(other & self._val)
|
||||||
|
|
||||||
@ -280,6 +284,7 @@ class intbv(object):
|
|||||||
return intbv(self._val | other._val)
|
return intbv(self._val | other._val)
|
||||||
else:
|
else:
|
||||||
return intbv(self._val | other)
|
return intbv(self._val | other)
|
||||||
|
|
||||||
def __ror__(self, other):
|
def __ror__(self, other):
|
||||||
return intbv(other | self._val)
|
return intbv(other | self._val)
|
||||||
|
|
||||||
@ -288,6 +293,7 @@ class intbv(object):
|
|||||||
return intbv(self._val ^ other._val)
|
return intbv(self._val ^ other._val)
|
||||||
else:
|
else:
|
||||||
return intbv(self._val ^ other)
|
return intbv(self._val ^ other)
|
||||||
|
|
||||||
def __rxor__(self, other):
|
def __rxor__(self, other):
|
||||||
return intbv(other ^ self._val)
|
return intbv(other ^ self._val)
|
||||||
|
|
||||||
@ -325,6 +331,7 @@ class intbv(object):
|
|||||||
|
|
||||||
def __idiv__(self, other):
|
def __idiv__(self, other):
|
||||||
raise TypeError("intbv: Augmented classic division not supported")
|
raise TypeError("intbv: Augmented classic division not supported")
|
||||||
|
|
||||||
def __itruediv__(self, other):
|
def __itruediv__(self, other):
|
||||||
raise TypeError("intbv: Augmented true division not supported")
|
raise TypeError("intbv: Augmented true division not supported")
|
||||||
|
|
||||||
@ -430,26 +437,31 @@ class intbv(object):
|
|||||||
return self._val == other._val
|
return self._val == other._val
|
||||||
else:
|
else:
|
||||||
return self._val == other
|
return self._val == other
|
||||||
|
|
||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
if isinstance(other, intbv):
|
if isinstance(other, intbv):
|
||||||
return self._val != other._val
|
return self._val != other._val
|
||||||
else:
|
else:
|
||||||
return self._val != other
|
return self._val != other
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
if isinstance(other, intbv):
|
if isinstance(other, intbv):
|
||||||
return self._val < other._val
|
return self._val < other._val
|
||||||
else:
|
else:
|
||||||
return self._val < other
|
return self._val < other
|
||||||
|
|
||||||
def __le__(self, other):
|
def __le__(self, other):
|
||||||
if isinstance(other, intbv):
|
if isinstance(other, intbv):
|
||||||
return self._val <= other._val
|
return self._val <= other._val
|
||||||
else:
|
else:
|
||||||
return self._val <= other
|
return self._val <= other
|
||||||
|
|
||||||
def __gt__(self, other):
|
def __gt__(self, other):
|
||||||
if isinstance(other, intbv):
|
if isinstance(other, intbv):
|
||||||
return self._val > other._val
|
return self._val > other._val
|
||||||
else:
|
else:
|
||||||
return self._val > other
|
return self._val > other
|
||||||
|
|
||||||
def __ge__(self, other):
|
def __ge__(self, other):
|
||||||
if isinstance(other, intbv):
|
if isinstance(other, intbv):
|
||||||
return self._val >= other._val
|
return self._val >= other._val
|
||||||
@ -475,7 +487,6 @@ class intbv(object):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "intbv(" + repr(self._val) + ")"
|
return "intbv(" + repr(self._val) + ")"
|
||||||
|
|
||||||
|
|
||||||
def signed(self):
|
def signed(self):
|
||||||
''' Return new intbv with the values interpreted as signed
|
''' Return new intbv with the values interpreted as signed
|
||||||
|
|
||||||
|
@ -35,4 +35,3 @@ class join(object):
|
|||||||
|
|
||||||
def _generator(self):
|
def _generator(self):
|
||||||
yield join(*self._args)
|
yield join(*self._args)
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ import inspect
|
|||||||
from myhdl._Cosimulation import Cosimulation
|
from myhdl._Cosimulation import Cosimulation
|
||||||
from myhdl._instance import _Instantiator
|
from myhdl._instance import _Instantiator
|
||||||
|
|
||||||
|
|
||||||
def _isGenSeq(obj):
|
def _isGenSeq(obj):
|
||||||
if isinstance(obj, (Cosimulation, _Instantiator)):
|
if isinstance(obj, (Cosimulation, _Instantiator)):
|
||||||
return True
|
return True
|
||||||
@ -54,6 +55,7 @@ def instances():
|
|||||||
l.append(v)
|
l.append(v)
|
||||||
return l
|
return l
|
||||||
|
|
||||||
|
|
||||||
def downrange(start, stop=0, step=1):
|
def downrange(start, stop=0, step=1):
|
||||||
""" Return a downward range. """
|
""" Return a downward range. """
|
||||||
return range(start - 1, stop - 1, -step)
|
return range(start - 1, stop - 1, -step)
|
||||||
|
@ -23,6 +23,7 @@ from __future__ import absolute_import
|
|||||||
from ._intbv import intbv
|
from ._intbv import intbv
|
||||||
from ._compat import long
|
from ._compat import long
|
||||||
|
|
||||||
|
|
||||||
class modbv(intbv):
|
class modbv(intbv):
|
||||||
__slots__ = []
|
__slots__ = []
|
||||||
|
|
||||||
@ -35,7 +36,6 @@ class modbv(intbv):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "modbv(" + repr(self._val) + ")"
|
return "modbv(" + repr(self._val) + ")"
|
||||||
|
|
||||||
|
|
||||||
# indexing and slicing methods
|
# indexing and slicing methods
|
||||||
# dedicated for modbv to support "declaration by slicing"
|
# dedicated for modbv to support "declaration by slicing"
|
||||||
|
|
||||||
@ -46,13 +46,13 @@ class modbv(intbv):
|
|||||||
j = 0
|
j = 0
|
||||||
j = int(j)
|
j = int(j)
|
||||||
if j < 0:
|
if j < 0:
|
||||||
raise ValueError("modbv[i:j] requires j >= 0\n" \
|
raise ValueError("modbv[i:j] requires j >= 0\n"
|
||||||
" j == %s" % j)
|
" j == %s" % j)
|
||||||
if i is None: # default
|
if i is None: # default
|
||||||
return modbv(self._val >> j)
|
return modbv(self._val >> j)
|
||||||
i = int(i)
|
i = int(i)
|
||||||
if i <= j:
|
if i <= j:
|
||||||
raise ValueError("modbv[i:j] requires i > j\n" \
|
raise ValueError("modbv[i:j] requires i > j\n"
|
||||||
" i, j == %s, %s" % (i, j))
|
" i, j == %s, %s" % (i, j))
|
||||||
res = modbv((self._val & (long(1) << i) - 1) >> j, _nrbits=i - j)
|
res = modbv((self._val & (long(1) << i) - 1) >> j, _nrbits=i - j)
|
||||||
return res
|
return res
|
||||||
@ -60,4 +60,3 @@ class modbv(intbv):
|
|||||||
i = int(key)
|
i = int(key)
|
||||||
res = bool((self._val >> i) & 0x1)
|
res = bool((self._val >> i) & 0x1)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ def _resolveRefs(symdict, arg):
|
|||||||
# TODO: Refactor this into two separate nodetransformers, since _resolveRefs
|
# TODO: Refactor this into two separate nodetransformers, since _resolveRefs
|
||||||
# needs only the names, not the objects
|
# needs only the names, not the objects
|
||||||
|
|
||||||
|
|
||||||
def _suffixer(name, used_names):
|
def _suffixer(name, used_names):
|
||||||
suffixed_names = (name + '_renamed{0}'.format(i) for i in itertools.count())
|
suffixed_names = (name + '_renamed{0}'.format(i) for i in itertools.count())
|
||||||
new_names = itertools.chain([name], suffixed_names)
|
new_names = itertools.chain([name], suffixed_names)
|
||||||
@ -31,6 +32,7 @@ def _suffixer(name, used_names):
|
|||||||
|
|
||||||
|
|
||||||
class _AttrRefTransformer(ast.NodeTransformer):
|
class _AttrRefTransformer(ast.NodeTransformer):
|
||||||
|
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
self.data = data
|
self.data = data
|
||||||
self.data.objlist = []
|
self.data.objlist = []
|
||||||
|
@ -25,8 +25,6 @@ now -- function that returns the current simulation time
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_signals = []
|
_signals = []
|
||||||
_siglist = []
|
_siglist = []
|
||||||
_futureEvents = []
|
_futureEvents = []
|
||||||
@ -35,6 +33,7 @@ _cosim = 0
|
|||||||
_tracing = 0
|
_tracing = 0
|
||||||
_tf = None
|
_tf = None
|
||||||
|
|
||||||
|
|
||||||
def now():
|
def now():
|
||||||
""" Return the current simulation time """
|
""" Return the current simulation time """
|
||||||
return _time
|
return _time
|
||||||
|
@ -24,7 +24,6 @@ from __future__ import absolute_import
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
@ -43,6 +42,7 @@ _tracing = 0
|
|||||||
_profileFunc = None
|
_profileFunc = None
|
||||||
vcdpath = ''
|
vcdpath = ''
|
||||||
|
|
||||||
|
|
||||||
class _error:
|
class _error:
|
||||||
pass
|
pass
|
||||||
_error.TopLevelName = "result of traceSignals call should be assigned to a top level name"
|
_error.TopLevelName = "result of traceSignals call should be assigned to a top level name"
|
||||||
@ -110,7 +110,8 @@ class _TraceSignalsClass(object):
|
|||||||
if isinstance(dut, _Block):
|
if isinstance(dut, _Block):
|
||||||
h = _getHierarchy(name, dut)
|
h = _getHierarchy(name, dut)
|
||||||
else:
|
else:
|
||||||
warnings.warn("\n traceSignals(): Deprecated usage: See http://dev.myhdl.org/meps/mep-114.html", stacklevel=2)
|
warnings.warn(
|
||||||
|
"\n traceSignals(): Deprecated usage: See http://dev.myhdl.org/meps/mep-114.html", stacklevel=2)
|
||||||
h = _HierExtr(name, dut, *args, **kwargs)
|
h = _HierExtr(name, dut, *args, **kwargs)
|
||||||
|
|
||||||
if self.filename is None:
|
if self.filename is None:
|
||||||
@ -142,12 +143,14 @@ for i in range(33, 127):
|
|||||||
_codechars += chr(i)
|
_codechars += chr(i)
|
||||||
_mod = len(_codechars)
|
_mod = len(_codechars)
|
||||||
|
|
||||||
|
|
||||||
def _genNameCode():
|
def _genNameCode():
|
||||||
n = 0
|
n = 0
|
||||||
while 1:
|
while 1:
|
||||||
yield _namecode(n)
|
yield _namecode(n)
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
|
|
||||||
def _namecode(n):
|
def _namecode(n):
|
||||||
q, r = divmod(n, _mod)
|
q, r = divmod(n, _mod)
|
||||||
code = _codechars[r]
|
code = _codechars[r]
|
||||||
@ -156,6 +159,7 @@ def _namecode(n):
|
|||||||
code = _codechars[r] + code
|
code = _codechars[r] + code
|
||||||
return code
|
return code
|
||||||
|
|
||||||
|
|
||||||
def _writeVcdHeader(f, timescale):
|
def _writeVcdHeader(f, timescale):
|
||||||
print("$date", file=f)
|
print("$date", file=f)
|
||||||
print(" %s" % time.asctime(), file=f)
|
print(" %s" % time.asctime(), file=f)
|
||||||
@ -168,6 +172,7 @@ def _writeVcdHeader(f, timescale):
|
|||||||
print("$end", file=f)
|
print("$end", file=f)
|
||||||
print(file=f)
|
print(file=f)
|
||||||
|
|
||||||
|
|
||||||
def _getSval(s):
|
def _getSval(s):
|
||||||
if isinstance(s, _TristateSignal):
|
if isinstance(s, _TristateSignal):
|
||||||
sval = s._orival
|
sval = s._orival
|
||||||
@ -177,6 +182,7 @@ def _getSval(s):
|
|||||||
sval = s._val
|
sval = s._val
|
||||||
return sval
|
return sval
|
||||||
|
|
||||||
|
|
||||||
def _writeVcdSigs(f, hierarchy, tracelists):
|
def _writeVcdSigs(f, hierarchy, tracelists):
|
||||||
curlevel = 0
|
curlevel = 0
|
||||||
namegen = _genNameCode()
|
namegen = _genNameCode()
|
||||||
|
@ -4,11 +4,13 @@ import warnings
|
|||||||
from myhdl._Signal import _Signal, _DelayedSignal
|
from myhdl._Signal import _Signal, _DelayedSignal
|
||||||
from myhdl._simulator import _siglist
|
from myhdl._simulator import _siglist
|
||||||
|
|
||||||
|
|
||||||
class BusContentionWarning(UserWarning):
|
class BusContentionWarning(UserWarning):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
warnings.filterwarnings('always', r".*", BusContentionWarning)
|
warnings.filterwarnings('always', r".*", BusContentionWarning)
|
||||||
|
|
||||||
|
|
||||||
def Tristate(val, delay=None):
|
def Tristate(val, delay=None):
|
||||||
""" Return a new Tristate(default or delay 0) or DelayedTristate """
|
""" Return a new Tristate(default or delay 0) or DelayedTristate """
|
||||||
if delay is not None:
|
if delay is not None:
|
||||||
|
@ -5,6 +5,7 @@ from myhdl._Signal import _Signal, _isListOfSigs
|
|||||||
|
|
||||||
|
|
||||||
class _SigNameVisitor(ast.NodeVisitor):
|
class _SigNameVisitor(ast.NodeVisitor):
|
||||||
|
|
||||||
def __init__(self, symdict):
|
def __init__(self, symdict):
|
||||||
self.toplevel = 1
|
self.toplevel = 1
|
||||||
self.symdict = symdict
|
self.symdict = symdict
|
||||||
|
@ -55,11 +55,12 @@ builtinObjects = builtins.__dict__.values()
|
|||||||
|
|
||||||
_enumTypeSet = set()
|
_enumTypeSet = set()
|
||||||
|
|
||||||
|
|
||||||
def _makeName(n, prefixes, namedict):
|
def _makeName(n, prefixes, namedict):
|
||||||
# trim empty prefixes
|
# trim empty prefixes
|
||||||
prefixes = [p for p in prefixes if p]
|
prefixes = [p for p in prefixes if p]
|
||||||
if len(prefixes) > 1:
|
if len(prefixes) > 1:
|
||||||
# name = '_' + '_'.join(prefixes[1:]) + '_' + n
|
# name = '_' + '_'.join(prefixes[1:]) + '_' + n
|
||||||
name = '_'.join(prefixes[1:]) + '_' + n
|
name = '_'.join(prefixes[1:]) + '_' + n
|
||||||
else:
|
else:
|
||||||
name = n
|
name = n
|
||||||
@ -136,7 +137,6 @@ def _analyzeSigs(hierarchy, hdl='Verilog'):
|
|||||||
return siglist, memlist
|
return siglist, memlist
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _analyzeGens(top, absnames):
|
def _analyzeGens(top, absnames):
|
||||||
genlist = []
|
genlist = []
|
||||||
for g in top:
|
for g in top:
|
||||||
@ -238,13 +238,15 @@ class _FirstPassVisitor(ast.NodeVisitor, _ConversionMixin):
|
|||||||
|
|
||||||
def visit_ListComp(self, node):
|
def visit_ListComp(self, node):
|
||||||
if len(node.generators) > 1:
|
if len(node.generators) > 1:
|
||||||
self.raiseError(node, _error.NotSupported, "multiple for statements in list comprehension")
|
self.raiseError(node, _error.NotSupported,
|
||||||
|
"multiple for statements in list comprehension")
|
||||||
if node.generators[0].ifs:
|
if node.generators[0].ifs:
|
||||||
self.raiseError(node, _error.NotSupported, "if statement in list comprehension")
|
self.raiseError(node, _error.NotSupported, "if statement in list comprehension")
|
||||||
self.generic_visit(node)
|
self.generic_visit(node)
|
||||||
|
|
||||||
def visit_List(self, node):
|
def visit_List(self, node):
|
||||||
self.raiseError(node, _error.NotSupported, "list")
|
self.raiseError(node, _error.NotSupported, "list")
|
||||||
|
|
||||||
def visitSliceObj(self, node):
|
def visitSliceObj(self, node):
|
||||||
self.raiseError(node, _error.NotSupported, "slice object")
|
self.raiseError(node, _error.NotSupported, "slice object")
|
||||||
|
|
||||||
@ -255,10 +257,10 @@ class _FirstPassVisitor(ast.NodeVisitor, _ConversionMixin):
|
|||||||
# Legacy try blocks
|
# Legacy try blocks
|
||||||
def visit_TryExcept(self, node):
|
def visit_TryExcept(self, node):
|
||||||
self.raiseError(node, _error.NotSupported, "try-except statement")
|
self.raiseError(node, _error.NotSupported, "try-except statement")
|
||||||
|
|
||||||
def visit_TryFinally(self, node):
|
def visit_TryFinally(self, node):
|
||||||
self.raiseError(node, _error.NotSupported, "try-finally statement")
|
self.raiseError(node, _error.NotSupported, "try-finally statement")
|
||||||
|
|
||||||
|
|
||||||
def visit_Assign(self, node):
|
def visit_Assign(self, node):
|
||||||
if len(node.targets) > 1:
|
if len(node.targets) > 1:
|
||||||
self.raiseError(node, _error.NotSupported, "multiple assignments")
|
self.raiseError(node, _error.NotSupported, "multiple assignments")
|
||||||
@ -331,7 +333,6 @@ class _FirstPassVisitor(ast.NodeVisitor, _ConversionMixin):
|
|||||||
node.tests = tests
|
node.tests = tests
|
||||||
node.else_ = else_
|
node.else_ = else_
|
||||||
|
|
||||||
|
|
||||||
def visit_Print(self, node):
|
def visit_Print(self, node):
|
||||||
if node.dest is not None:
|
if node.dest is not None:
|
||||||
self.raiseError(node, _error.NotSupported, "printing to a file with >> syntax")
|
self.raiseError(node, _error.NotSupported, "printing to a file with >> syntax")
|
||||||
@ -339,14 +340,12 @@ class _FirstPassVisitor(ast.NodeVisitor, _ConversionMixin):
|
|||||||
self.raiseError(node, _error.NotSupported, "printing without newline")
|
self.raiseError(node, _error.NotSupported, "printing without newline")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getNrBits(obj):
|
def getNrBits(obj):
|
||||||
if hasattr(obj, '_nrbits'):
|
if hasattr(obj, '_nrbits'):
|
||||||
return obj._nrbits
|
return obj._nrbits
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def hasType(obj, theType):
|
def hasType(obj, theType):
|
||||||
if isinstance(obj, theType):
|
if isinstance(obj, theType):
|
||||||
return True
|
return True
|
||||||
@ -357,10 +356,13 @@ def hasType(obj, theType):
|
|||||||
|
|
||||||
|
|
||||||
class ReferenceStack(list):
|
class ReferenceStack(list):
|
||||||
|
|
||||||
def push(self):
|
def push(self):
|
||||||
self.append(set())
|
self.append(set())
|
||||||
|
|
||||||
def add(self, item):
|
def add(self, item):
|
||||||
self[-1].add(item)
|
self[-1].add(item)
|
||||||
|
|
||||||
def __contains__(self, item):
|
def __contains__(self, item):
|
||||||
for s in self:
|
for s in self:
|
||||||
if item in s:
|
if item in s:
|
||||||
@ -368,20 +370,22 @@ class ReferenceStack(list):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _Ram(object):
|
class _Ram(object):
|
||||||
__slots__ = ['elObj', 'depth']
|
__slots__ = ['elObj', 'depth']
|
||||||
|
|
||||||
|
|
||||||
class _Rom(object):
|
class _Rom(object):
|
||||||
__slots__ = ['rom']
|
__slots__ = ['rom']
|
||||||
|
|
||||||
def __init__(self, rom):
|
def __init__(self, rom):
|
||||||
self.rom = rom
|
self.rom = rom
|
||||||
|
|
||||||
re_str = re.compile(r"[^%]+")
|
re_str = re.compile(r"[^%]+")
|
||||||
re_ConvSpec = re.compile(r"%(?P<justified>[-]?)(?P<width>[0-9]*)(?P<conv>[sd])")
|
re_ConvSpec = re.compile(r"%(?P<justified>[-]?)(?P<width>[0-9]*)(?P<conv>[sd])")
|
||||||
|
|
||||||
|
|
||||||
class ConvSpec(object):
|
class ConvSpec(object):
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.justified = "RIGHT"
|
self.justified = "RIGHT"
|
||||||
self.width = 0
|
self.width = 0
|
||||||
@ -395,6 +399,7 @@ class ConvSpec(object):
|
|||||||
|
|
||||||
defaultConvSpec = ConvSpec(**re_ConvSpec.match(r"%s").groupdict())
|
defaultConvSpec = ConvSpec(**re_ConvSpec.match(r"%s").groupdict())
|
||||||
|
|
||||||
|
|
||||||
def _getNritems(obj):
|
def _getNritems(obj):
|
||||||
"""Return the number of items in an objects' type"""
|
"""Return the number of items in an objects' type"""
|
||||||
if isinstance(obj, _Signal):
|
if isinstance(obj, _Signal):
|
||||||
@ -439,7 +444,8 @@ class _AnalyzeVisitor(ast.NodeVisitor, _ConversionMixin):
|
|||||||
self.visit(n)
|
self.visit(n)
|
||||||
for n in node.values:
|
for n in node.values:
|
||||||
if not hasType(n.obj, bool):
|
if not hasType(n.obj, bool):
|
||||||
self.raiseError(node, _error.NotSupported, "non-boolean argument in logical operator")
|
self.raiseError(node, _error.NotSupported,
|
||||||
|
"non-boolean argument in logical operator")
|
||||||
node.obj = bool()
|
node.obj = bool()
|
||||||
|
|
||||||
def visit_UnaryOp(self, node):
|
def visit_UnaryOp(self, node):
|
||||||
@ -589,7 +595,8 @@ class _AnalyzeVisitor(ast.NodeVisitor, _ConversionMixin):
|
|||||||
elif f is ord:
|
elif f is ord:
|
||||||
node.obj = int(-1)
|
node.obj = int(-1)
|
||||||
if not (isinstance(node.args[0], ast.Str) and (len(node.args[0].s) == 1)):
|
if not (isinstance(node.args[0], ast.Str) and (len(node.args[0].s) == 1)):
|
||||||
self.raiseError(node, _error.NotSupported, "ord: expect string argument with length 1")
|
self.raiseError(node, _error.NotSupported,
|
||||||
|
"ord: expect string argument with length 1")
|
||||||
elif f is delay:
|
elif f is delay:
|
||||||
node.obj = delay(0)
|
node.obj = delay(0)
|
||||||
# suprize: identity comparison on unbound methods doesn't work in python 2.5??
|
# suprize: identity comparison on unbound methods doesn't work in python 2.5??
|
||||||
@ -1042,7 +1049,6 @@ class _AnalyzeBlockVisitor(_AnalyzeVisitor):
|
|||||||
if isinstance(v, _Signal):
|
if isinstance(v, _Signal):
|
||||||
self.tree.sigdict[n] = v
|
self.tree.sigdict[n] = v
|
||||||
|
|
||||||
|
|
||||||
def visit_FunctionDef(self, node):
|
def visit_FunctionDef(self, node):
|
||||||
self.refStack.push()
|
self.refStack.push()
|
||||||
for n in node.body:
|
for n in node.body:
|
||||||
@ -1058,7 +1064,6 @@ class _AnalyzeBlockVisitor(_AnalyzeVisitor):
|
|||||||
self.tree.kind = _kind.INITIAL
|
self.tree.kind = _kind.INITIAL
|
||||||
self.refStack.pop()
|
self.refStack.pop()
|
||||||
|
|
||||||
|
|
||||||
def visit_Module(self, node):
|
def visit_Module(self, node):
|
||||||
self.generic_visit(node)
|
self.generic_visit(node)
|
||||||
for n in self.tree.outputs:
|
for n in self.tree.outputs:
|
||||||
@ -1070,7 +1075,6 @@ class _AnalyzeBlockVisitor(_AnalyzeVisitor):
|
|||||||
s = self.tree.sigdict[n]
|
s = self.tree.sigdict[n]
|
||||||
s._markRead()
|
s._markRead()
|
||||||
|
|
||||||
|
|
||||||
def visit_Return(self, node):
|
def visit_Return(self, node):
|
||||||
# value should be None
|
# value should be None
|
||||||
if node.value is None:
|
if node.value is None:
|
||||||
@ -1081,15 +1085,12 @@ class _AnalyzeBlockVisitor(_AnalyzeVisitor):
|
|||||||
self.raiseError(node, _error.NotSupported, "return value other than None")
|
self.raiseError(node, _error.NotSupported, "return value other than None")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _AnalyzeAlwaysCombVisitor(_AnalyzeBlockVisitor):
|
class _AnalyzeAlwaysCombVisitor(_AnalyzeBlockVisitor):
|
||||||
|
|
||||||
def __init__(self, tree, senslist):
|
def __init__(self, tree, senslist):
|
||||||
_AnalyzeBlockVisitor.__init__(self, tree)
|
_AnalyzeBlockVisitor.__init__(self, tree)
|
||||||
self.tree.senslist = senslist
|
self.tree.senslist = senslist
|
||||||
|
|
||||||
|
|
||||||
def visit_FunctionDef(self, node):
|
def visit_FunctionDef(self, node):
|
||||||
self.refStack.push()
|
self.refStack.push()
|
||||||
for n in node.body:
|
for n in node.body:
|
||||||
@ -1112,9 +1113,6 @@ class _AnalyzeAlwaysCombVisitor(_AnalyzeBlockVisitor):
|
|||||||
self.tree.kind = _kind.ALWAYS_COMB
|
self.tree.kind = _kind.ALWAYS_COMB
|
||||||
self.refStack.pop()
|
self.refStack.pop()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def visit_Module(self, node):
|
def visit_Module(self, node):
|
||||||
_AnalyzeBlockVisitor.visit_Module(self, node)
|
_AnalyzeBlockVisitor.visit_Module(self, node)
|
||||||
if self.tree.kind == _kind.SIMPLE_ALWAYS_COMB:
|
if self.tree.kind == _kind.SIMPLE_ALWAYS_COMB:
|
||||||
@ -1135,7 +1133,6 @@ class _AnalyzeAlwaysSeqVisitor(_AnalyzeBlockVisitor):
|
|||||||
self.tree.sigregs = sigregs
|
self.tree.sigregs = sigregs
|
||||||
self.tree.varregs = varregs
|
self.tree.varregs = varregs
|
||||||
|
|
||||||
|
|
||||||
def visit_FunctionDef(self, node):
|
def visit_FunctionDef(self, node):
|
||||||
self.refStack.push()
|
self.refStack.push()
|
||||||
for n in node.body:
|
for n in node.body:
|
||||||
@ -1150,7 +1147,6 @@ class _AnalyzeAlwaysDecoVisitor(_AnalyzeBlockVisitor):
|
|||||||
_AnalyzeBlockVisitor.__init__(self, tree)
|
_AnalyzeBlockVisitor.__init__(self, tree)
|
||||||
self.tree.senslist = senslist
|
self.tree.senslist = senslist
|
||||||
|
|
||||||
|
|
||||||
def visit_FunctionDef(self, node):
|
def visit_FunctionDef(self, node):
|
||||||
self.refStack.push()
|
self.refStack.push()
|
||||||
for n in node.body:
|
for n in node.body:
|
||||||
@ -1159,7 +1155,6 @@ class _AnalyzeAlwaysDecoVisitor(_AnalyzeBlockVisitor):
|
|||||||
self.refStack.pop()
|
self.refStack.pop()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _AnalyzeFuncVisitor(_AnalyzeVisitor):
|
class _AnalyzeFuncVisitor(_AnalyzeVisitor):
|
||||||
|
|
||||||
def __init__(self, tree, args, keywords):
|
def __init__(self, tree, args, keywords):
|
||||||
@ -1169,7 +1164,6 @@ class _AnalyzeFuncVisitor(_AnalyzeVisitor):
|
|||||||
self.tree.hasReturn = False
|
self.tree.hasReturn = False
|
||||||
self.tree.returnObj = None
|
self.tree.returnObj = None
|
||||||
|
|
||||||
|
|
||||||
def visit_FunctionDef(self, node):
|
def visit_FunctionDef(self, node):
|
||||||
self.refStack.push()
|
self.refStack.push()
|
||||||
argnames = _get_argnames(node)
|
argnames = _get_argnames(node)
|
||||||
@ -1199,8 +1193,6 @@ class _AnalyzeFuncVisitor(_AnalyzeVisitor):
|
|||||||
self.raiseError(node, _error.NotSupported,
|
self.raiseError(node, _error.NotSupported,
|
||||||
"pure function without return value")
|
"pure function without return value")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def visit_Return(self, node):
|
def visit_Return(self, node):
|
||||||
self.kind = _kind.DECLARATION
|
self.kind = _kind.DECLARATION
|
||||||
if node.value is not None:
|
if node.value is not None:
|
||||||
@ -1233,6 +1225,8 @@ class _AnalyzeFuncVisitor(_AnalyzeVisitor):
|
|||||||
|
|
||||||
ismethod = inspect.ismethod
|
ismethod = inspect.ismethod
|
||||||
# inspect doc is wrong: ismethod checks both bound and unbound methods
|
# inspect doc is wrong: ismethod checks both bound and unbound methods
|
||||||
|
|
||||||
|
|
||||||
def isboundmethod(m):
|
def isboundmethod(m):
|
||||||
return ismethod(m) and m.__self__ is not None
|
return ismethod(m) and m.__self__ is not None
|
||||||
|
|
||||||
@ -1264,6 +1258,7 @@ def _analyzeTopFunc(func, *args, **kwargs):
|
|||||||
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
|
||||||
class _AnalyzeTopFuncVisitor(_AnalyzeVisitor):
|
class _AnalyzeTopFuncVisitor(_AnalyzeVisitor):
|
||||||
|
|
||||||
def __init__(self, func, tree, *args, **kwargs):
|
def __init__(self, func, tree, *args, **kwargs):
|
||||||
|
@ -28,6 +28,7 @@ import ast
|
|||||||
from myhdl import ConversionError
|
from myhdl import ConversionError
|
||||||
from myhdl._compat import PY2
|
from myhdl._compat import PY2
|
||||||
|
|
||||||
|
|
||||||
class _error(object):
|
class _error(object):
|
||||||
FirstArgType = "first argument should be a classic function"
|
FirstArgType = "first argument should be a classic function"
|
||||||
ArgType = "leaf cell type error"
|
ArgType = "leaf cell type error"
|
||||||
@ -75,27 +76,29 @@ class _error(object):
|
|||||||
class _access(object):
|
class _access(object):
|
||||||
INPUT, OUTPUT, INOUT, UNKNOWN = range(4)
|
INPUT, OUTPUT, INOUT, UNKNOWN = range(4)
|
||||||
|
|
||||||
|
|
||||||
class _kind(object):
|
class _kind(object):
|
||||||
NORMAL, DECLARATION, ALWAYS, INITIAL, ALWAYS_DECO, \
|
NORMAL, DECLARATION, ALWAYS, INITIAL, ALWAYS_DECO, \
|
||||||
ALWAYS_COMB, SIMPLE_ALWAYS_COMB, ALWAYS_SEQ, \
|
ALWAYS_COMB, SIMPLE_ALWAYS_COMB, ALWAYS_SEQ, \
|
||||||
TASK, REG \
|
TASK, REG \
|
||||||
= range(10)
|
= range(10)
|
||||||
|
|
||||||
|
|
||||||
class _context(object):
|
class _context(object):
|
||||||
BOOLEAN, YIELD, PRINT, SIGNED, UNKNOWN = range(5)
|
BOOLEAN, YIELD, PRINT, SIGNED, UNKNOWN = range(5)
|
||||||
|
|
||||||
|
|
||||||
class _ConversionMixin(object):
|
class _ConversionMixin(object):
|
||||||
|
|
||||||
# def getLineNo(self, node):
|
# def getLineNo(self, node):
|
||||||
# lineno = node.lineno
|
# lineno = node.lineno
|
||||||
# if lineno is None:
|
# if lineno is None:
|
||||||
# for n in node.getChildNodes():
|
# for n in node.getChildNodes():
|
||||||
# if n.lineno is not None:
|
# if n.lineno is not None:
|
||||||
# lineno = n.lineno
|
# lineno = n.lineno
|
||||||
# break
|
# break
|
||||||
# lineno = lineno or 0
|
# lineno = lineno or 0
|
||||||
# return lineno
|
# return lineno
|
||||||
|
|
||||||
def getLineNo(self, node):
|
def getLineNo(self, node):
|
||||||
lineno = 0
|
lineno = 0
|
||||||
@ -158,7 +161,6 @@ class _ConversionMixin(object):
|
|||||||
self.visit(n)
|
self.visit(n)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _LabelGenerator():
|
def _LabelGenerator():
|
||||||
i = 1
|
i = 1
|
||||||
while 1:
|
while 1:
|
||||||
@ -167,20 +169,28 @@ def _LabelGenerator():
|
|||||||
|
|
||||||
_genLabel = _LabelGenerator()
|
_genLabel = _LabelGenerator()
|
||||||
|
|
||||||
|
|
||||||
class _Label(object):
|
class _Label(object):
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = next(_genLabel) + '_' + name
|
self.name = next(_genLabel) + '_' + name
|
||||||
self.isActive = False
|
self.isActive = False
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.name)
|
return str(self.name)
|
||||||
|
|
||||||
# this can be made more sophisticated to deal with existing suffixes
|
# this can be made more sophisticated to deal with existing suffixes
|
||||||
# also, may require reset facility
|
# also, may require reset facility
|
||||||
|
|
||||||
|
|
||||||
class _UniqueSuffixGenerator(object):
|
class _UniqueSuffixGenerator(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.i = 0
|
self.i = 0
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.i = 0
|
self.i = 0
|
||||||
|
|
||||||
def next(self):
|
def next(self):
|
||||||
self.i += 1
|
self.i += 1
|
||||||
return "_%s" % self.i
|
return "_%s" % self.i
|
||||||
@ -199,6 +209,7 @@ def _isConstant(tree, symdict):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class _namesVisitor(ast.NodeVisitor):
|
class _namesVisitor(ast.NodeVisitor):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -207,6 +218,7 @@ class _namesVisitor(ast.NodeVisitor):
|
|||||||
def visit_Name(self, node):
|
def visit_Name(self, node):
|
||||||
self.names.append(node.id)
|
self.names.append(node.id)
|
||||||
|
|
||||||
|
|
||||||
def _get_argnames(node):
|
def _get_argnames(node):
|
||||||
if PY2:
|
if PY2:
|
||||||
return [arg.id for arg in node.args.args]
|
return [arg.id for arg in node.args.args]
|
||||||
|
@ -65,11 +65,13 @@ _converting = 0
|
|||||||
_profileFunc = None
|
_profileFunc = None
|
||||||
_enumPortTypeSet = set()
|
_enumPortTypeSet = set()
|
||||||
|
|
||||||
|
|
||||||
def _checkArgs(arglist):
|
def _checkArgs(arglist):
|
||||||
for arg in arglist:
|
for arg in arglist:
|
||||||
if not isinstance(arg, (GeneratorType, _Instantiator, _UserVhdlCode)):
|
if not isinstance(arg, (GeneratorType, _Instantiator, _UserVhdlCode)):
|
||||||
raise ToVHDLError(_error.ArgType, arg)
|
raise ToVHDLError(_error.ArgType, arg)
|
||||||
|
|
||||||
|
|
||||||
def _flatten(*args):
|
def _flatten(*args):
|
||||||
arglist = []
|
arglist = []
|
||||||
for arg in args:
|
for arg in args:
|
||||||
@ -88,6 +90,7 @@ def _flatten(*args):
|
|||||||
arglist.append(arg)
|
arglist.append(arg)
|
||||||
return arglist
|
return arglist
|
||||||
|
|
||||||
|
|
||||||
def _makeDoc(doc, indent=''):
|
def _makeDoc(doc, indent=''):
|
||||||
if doc is None:
|
if doc is None:
|
||||||
return ''
|
return ''
|
||||||
@ -152,7 +155,8 @@ class _ToVHDLConvertor(object):
|
|||||||
finally:
|
finally:
|
||||||
_converting = 0
|
_converting = 0
|
||||||
else:
|
else:
|
||||||
warnings.warn("\n toVHDL(): Deprecated usage: See http://dev.myhdl.org/meps/mep-114.html", stacklevel=2)
|
warnings.warn(
|
||||||
|
"\n toVHDL(): Deprecated usage: See http://dev.myhdl.org/meps/mep-114.html", stacklevel=2)
|
||||||
try:
|
try:
|
||||||
h = _HierExtr(name, func, *args, **kwargs)
|
h = _HierExtr(name, func, *args, **kwargs)
|
||||||
finally:
|
finally:
|
||||||
@ -263,7 +267,6 @@ class _ToVHDLConvertor(object):
|
|||||||
self.architecture = "MyHDL"
|
self.architecture = "MyHDL"
|
||||||
self.std_logic_ports = False
|
self.std_logic_ports = False
|
||||||
|
|
||||||
|
|
||||||
def _convert_filter(self, h, intf, siglist, memlist, genlist):
|
def _convert_filter(self, h, intf, siglist, memlist, genlist):
|
||||||
# intended to be a entry point for other uses:
|
# intended to be a entry point for other uses:
|
||||||
# code checking, optimizations, etc
|
# code checking, optimizations, etc
|
||||||
@ -278,6 +281,7 @@ myhdl_header = """\
|
|||||||
-- Date: $date
|
-- Date: $date
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def _writeFileHeader(f, fn):
|
def _writeFileHeader(f, fn):
|
||||||
vars = dict(filename=fn,
|
vars = dict(filename=fn,
|
||||||
version=myhdl.__version__,
|
version=myhdl.__version__,
|
||||||
@ -306,6 +310,7 @@ def _writeCustomPackage(f, intf):
|
|||||||
|
|
||||||
portConversions = []
|
portConversions = []
|
||||||
|
|
||||||
|
|
||||||
def _writeModuleHeader(f, intf, needPck, lib, arch, useClauses, doc, stdLogicPorts):
|
def _writeModuleHeader(f, intf, needPck, lib, arch, useClauses, doc, stdLogicPorts):
|
||||||
print("library IEEE;", file=f)
|
print("library IEEE;", file=f)
|
||||||
print("use IEEE.std_logic_1164.all;", file=f)
|
print("use IEEE.std_logic_1164.all;", file=f)
|
||||||
@ -379,6 +384,7 @@ def _writeFuncDecls(f):
|
|||||||
return
|
return
|
||||||
# print >> f, package
|
# print >> f, package
|
||||||
|
|
||||||
|
|
||||||
def _writeTypeDefs(f):
|
def _writeTypeDefs(f):
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
sortedList = list(_enumTypeSet)
|
sortedList = list(_enumTypeSet)
|
||||||
@ -389,6 +395,7 @@ def _writeTypeDefs(f):
|
|||||||
|
|
||||||
constwires = []
|
constwires = []
|
||||||
|
|
||||||
|
|
||||||
def _writeSigDecls(f, intf, siglist, memlist):
|
def _writeSigDecls(f, intf, siglist, memlist):
|
||||||
del constwires[:]
|
del constwires[:]
|
||||||
for s in siglist:
|
for s in siglist:
|
||||||
@ -433,13 +440,16 @@ def _writeSigDecls(f, intf, siglist, memlist):
|
|||||||
print("signal %s: %s;" % (m.name, t), file=f)
|
print("signal %s: %s;" % (m.name, t), file=f)
|
||||||
print(file=f)
|
print(file=f)
|
||||||
|
|
||||||
|
|
||||||
def _writeCompDecls(f, compDecls):
|
def _writeCompDecls(f, compDecls):
|
||||||
if compDecls is not None:
|
if compDecls is not None:
|
||||||
print(compDecls, file=f)
|
print(compDecls, file=f)
|
||||||
|
|
||||||
|
|
||||||
def _writeModuleFooter(f, arch):
|
def _writeModuleFooter(f, arch):
|
||||||
print("end architecture %s;" % arch, file=f)
|
print("end architecture %s;" % arch, file=f)
|
||||||
|
|
||||||
|
|
||||||
def _getRangeString(s):
|
def _getRangeString(s):
|
||||||
if isinstance(s._val, EnumItemType):
|
if isinstance(s._val, EnumItemType):
|
||||||
return ''
|
return ''
|
||||||
@ -451,6 +461,7 @@ def _getRangeString(s):
|
|||||||
else:
|
else:
|
||||||
raise AssertionError
|
raise AssertionError
|
||||||
|
|
||||||
|
|
||||||
def _getTypeString(s):
|
def _getTypeString(s):
|
||||||
if isinstance(s._val, EnumItemType):
|
if isinstance(s._val, EnumItemType):
|
||||||
return s._val._type._name
|
return s._val._type._name
|
||||||
@ -461,6 +472,7 @@ def _getTypeString(s):
|
|||||||
else:
|
else:
|
||||||
return 'unsigned'
|
return 'unsigned'
|
||||||
|
|
||||||
|
|
||||||
def _convertGens(genlist, siglist, memlist, vfile):
|
def _convertGens(genlist, siglist, memlist, vfile):
|
||||||
blockBuf = StringIO()
|
blockBuf = StringIO()
|
||||||
funcBuf = StringIO()
|
funcBuf = StringIO()
|
||||||
@ -482,7 +494,8 @@ def _convertGens(genlist, siglist, memlist, vfile):
|
|||||||
Visitor = _ConvertAlwaysCombVisitor
|
Visitor = _ConvertAlwaysCombVisitor
|
||||||
v = Visitor(tree, blockBuf, funcBuf)
|
v = Visitor(tree, blockBuf, funcBuf)
|
||||||
v.visit(tree)
|
v.visit(tree)
|
||||||
vfile.write(funcBuf.getvalue()); funcBuf.close()
|
vfile.write(funcBuf.getvalue())
|
||||||
|
funcBuf.close()
|
||||||
print("begin", file=vfile)
|
print("begin", file=vfile)
|
||||||
print(file=vfile)
|
print(file=vfile)
|
||||||
for st in portConversions:
|
for st in portConversions:
|
||||||
@ -523,7 +536,8 @@ def _convertGens(genlist, siglist, memlist, vfile):
|
|||||||
if hasattr(s, 'toVHDL'):
|
if hasattr(s, 'toVHDL'):
|
||||||
print(s.toVHDL(), file=vfile)
|
print(s.toVHDL(), file=vfile)
|
||||||
print(file=vfile)
|
print(file=vfile)
|
||||||
vfile.write(blockBuf.getvalue()); blockBuf.close()
|
vfile.write(blockBuf.getvalue())
|
||||||
|
blockBuf.close()
|
||||||
|
|
||||||
|
|
||||||
opmap = {
|
opmap = {
|
||||||
@ -654,8 +668,10 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin):
|
|||||||
tipe = obj._val._type._name
|
tipe = obj._val._type._name
|
||||||
else:
|
else:
|
||||||
tipe = vhd.toStr(constr)
|
tipe = vhd.toStr(constr)
|
||||||
if kind: kind += " "
|
if kind:
|
||||||
if dir: dir += " "
|
kind += " "
|
||||||
|
if dir:
|
||||||
|
dir += " "
|
||||||
self.write("%s%s: %s%s%s" % (kind, name, dir, tipe, endchar))
|
self.write("%s%s: %s%s%s" % (kind, name, dir, tipe, endchar))
|
||||||
|
|
||||||
def writeDeclarations(self):
|
def writeDeclarations(self):
|
||||||
@ -1629,7 +1645,9 @@ class _ConvertAlwaysCombVisitor(_ConvertVisitor):
|
|||||||
for item in senslist:
|
for item in senslist:
|
||||||
name = item._name.split('(', 1)[0]
|
name = item._name.split('(', 1)[0]
|
||||||
if not name in r:
|
if not name in r:
|
||||||
r.append(name) # note that the list now contains names and not Signals, but we are interested in the strings anyway ...
|
# note that the list now contains names and not Signals, but we are
|
||||||
|
# interested in the strings anyway ...
|
||||||
|
r.append(name)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
self.writeDoc(node)
|
self.writeDoc(node)
|
||||||
@ -1888,21 +1906,24 @@ class _ConvertTaskVisitor(_ConvertVisitor):
|
|||||||
self.writeline(2)
|
self.writeline(2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# type inference
|
# type inference
|
||||||
|
|
||||||
|
|
||||||
class vhd_type(object):
|
class vhd_type(object):
|
||||||
|
|
||||||
def __init__(self, size=0):
|
def __init__(self, size=0):
|
||||||
self.size = size
|
self.size = size
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%s(%s)" % (type(self).__name__, self.size)
|
return "%s(%s)" % (type(self).__name__, self.size)
|
||||||
|
|
||||||
|
|
||||||
class vhd_string(vhd_type):
|
class vhd_string(vhd_type):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class vhd_enum(vhd_type):
|
class vhd_enum(vhd_type):
|
||||||
|
|
||||||
def __init__(self, tipe):
|
def __init__(self, tipe):
|
||||||
self._type = tipe
|
self._type = tipe
|
||||||
|
|
||||||
@ -1911,42 +1932,57 @@ class vhd_enum(vhd_type):
|
|||||||
|
|
||||||
|
|
||||||
class vhd_std_logic(vhd_type):
|
class vhd_std_logic(vhd_type):
|
||||||
|
|
||||||
def __init__(self, size=0):
|
def __init__(self, size=0):
|
||||||
vhd_type.__init__(self)
|
vhd_type.__init__(self)
|
||||||
self.size = 1
|
self.size = 1
|
||||||
|
|
||||||
def toStr(self, constr=True):
|
def toStr(self, constr=True):
|
||||||
return 'std_logic'
|
return 'std_logic'
|
||||||
|
|
||||||
|
|
||||||
class vhd_boolean(vhd_type):
|
class vhd_boolean(vhd_type):
|
||||||
|
|
||||||
def __init__(self, size=0):
|
def __init__(self, size=0):
|
||||||
vhd_type.__init__(self)
|
vhd_type.__init__(self)
|
||||||
self.size = 1
|
self.size = 1
|
||||||
|
|
||||||
def toStr(self, constr=True):
|
def toStr(self, constr=True):
|
||||||
return 'boolean'
|
return 'boolean'
|
||||||
|
|
||||||
|
|
||||||
class vhd_vector(vhd_type):
|
class vhd_vector(vhd_type):
|
||||||
|
|
||||||
def __init__(self, size=0):
|
def __init__(self, size=0):
|
||||||
vhd_type.__init__(self, size)
|
vhd_type.__init__(self, size)
|
||||||
|
|
||||||
|
|
||||||
class vhd_unsigned(vhd_vector):
|
class vhd_unsigned(vhd_vector):
|
||||||
|
|
||||||
def toStr(self, constr=True):
|
def toStr(self, constr=True):
|
||||||
if constr:
|
if constr:
|
||||||
return "unsigned(%s downto 0)" % (self.size - 1)
|
return "unsigned(%s downto 0)" % (self.size - 1)
|
||||||
else:
|
else:
|
||||||
return "unsigned"
|
return "unsigned"
|
||||||
|
|
||||||
|
|
||||||
class vhd_signed(vhd_vector):
|
class vhd_signed(vhd_vector):
|
||||||
|
|
||||||
def toStr(self, constr=True):
|
def toStr(self, constr=True):
|
||||||
if constr:
|
if constr:
|
||||||
return "signed(%s downto 0)" % (self.size - 1)
|
return "signed(%s downto 0)" % (self.size - 1)
|
||||||
else:
|
else:
|
||||||
return "signed"
|
return "signed"
|
||||||
|
|
||||||
|
|
||||||
class vhd_int(vhd_type):
|
class vhd_int(vhd_type):
|
||||||
|
|
||||||
def toStr(self, constr=True):
|
def toStr(self, constr=True):
|
||||||
return "integer"
|
return "integer"
|
||||||
|
|
||||||
|
|
||||||
class vhd_nat(vhd_int):
|
class vhd_nat(vhd_int):
|
||||||
|
|
||||||
def toStr(self, constr=True):
|
def toStr(self, constr=True):
|
||||||
return "natural"
|
return "natural"
|
||||||
|
|
||||||
@ -1954,6 +1990,7 @@ class vhd_nat(vhd_int):
|
|||||||
class _loopInt(int):
|
class _loopInt(int):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def maxType(o1, o2):
|
def maxType(o1, o2):
|
||||||
s1 = s2 = 0
|
s1 = s2 = 0
|
||||||
if isinstance(o1, vhd_type):
|
if isinstance(o1, vhd_type):
|
||||||
@ -1972,6 +2009,7 @@ def maxType(o1, o2):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def inferVhdlObj(obj):
|
def inferVhdlObj(obj):
|
||||||
vhd = None
|
vhd = None
|
||||||
if (isinstance(obj, _Signal) and obj._type is intbv) or \
|
if (isinstance(obj, _Signal) and obj._type is intbv) or \
|
||||||
@ -1998,6 +2036,7 @@ def inferVhdlObj(obj):
|
|||||||
# vhd = vhd_int()
|
# vhd = vhd_int()
|
||||||
return vhd
|
return vhd
|
||||||
|
|
||||||
|
|
||||||
def maybeNegative(vhd):
|
def maybeNegative(vhd):
|
||||||
if isinstance(vhd, vhd_signed):
|
if isinstance(vhd, vhd_signed):
|
||||||
return True
|
return True
|
||||||
@ -2005,6 +2044,7 @@ def maybeNegative(vhd):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class _AnnotateTypesVisitor(ast.NodeVisitor, _ConversionMixin):
|
class _AnnotateTypesVisitor(ast.NodeVisitor, _ConversionMixin):
|
||||||
|
|
||||||
def __init__(self, tree):
|
def __init__(self, tree):
|
||||||
@ -2251,10 +2291,10 @@ class _AnnotateTypesVisitor(ast.NodeVisitor, _ConversionMixin):
|
|||||||
node.vhd = copy(node.operand.vhd)
|
node.vhd = copy(node.operand.vhd)
|
||||||
if isinstance(node.op, ast.Not):
|
if isinstance(node.op, ast.Not):
|
||||||
# postpone this optimization until initial values are written
|
# postpone this optimization until initial values are written
|
||||||
# if isinstance(node.operand.vhd, vhd_std_logic):
|
# if isinstance(node.operand.vhd, vhd_std_logic):
|
||||||
# node.vhd = vhd_std_logic()
|
# node.vhd = vhd_std_logic()
|
||||||
# else:
|
# else:
|
||||||
# node.vhd = node.operand.vhd = vhd_boolean()
|
# node.vhd = node.operand.vhd = vhd_boolean()
|
||||||
node.vhd = node.operand.vhd = vhd_boolean()
|
node.vhd = node.operand.vhd = vhd_boolean()
|
||||||
elif isinstance(node.op, ast.USub):
|
elif isinstance(node.op, ast.USub):
|
||||||
if isinstance(node.vhd, vhd_unsigned):
|
if isinstance(node.vhd, vhd_unsigned):
|
||||||
|
@ -59,11 +59,13 @@ from myhdl._getHierarchy import _getHierarchy
|
|||||||
_converting = 0
|
_converting = 0
|
||||||
_profileFunc = None
|
_profileFunc = None
|
||||||
|
|
||||||
|
|
||||||
def _checkArgs(arglist):
|
def _checkArgs(arglist):
|
||||||
for arg in arglist:
|
for arg in arglist:
|
||||||
if not isinstance(arg, (GeneratorType, _Instantiator, _UserVerilogCode)):
|
if not isinstance(arg, (GeneratorType, _Instantiator, _UserVerilogCode)):
|
||||||
raise ToVerilogError(_error.ArgType, arg)
|
raise ToVerilogError(_error.ArgType, arg)
|
||||||
|
|
||||||
|
|
||||||
def _flatten(*args):
|
def _flatten(*args):
|
||||||
arglist = []
|
arglist = []
|
||||||
for arg in args:
|
for arg in args:
|
||||||
@ -148,7 +150,8 @@ class _ToVerilogConvertor(object):
|
|||||||
finally:
|
finally:
|
||||||
_converting = 0
|
_converting = 0
|
||||||
else:
|
else:
|
||||||
warnings.warn("\n toVerilog(): Deprecated usage: See http://dev.myhdl.org/meps/mep-114.html", stacklevel=2)
|
warnings.warn(
|
||||||
|
"\n toVerilog(): Deprecated usage: See http://dev.myhdl.org/meps/mep-114.html", stacklevel=2)
|
||||||
try:
|
try:
|
||||||
h = _HierExtr(name, func, *args, **kwargs)
|
h = _HierExtr(name, func, *args, **kwargs)
|
||||||
finally:
|
finally:
|
||||||
@ -205,8 +208,10 @@ class _ToVerilogConvertor(object):
|
|||||||
# build portmap for cosimulation
|
# build portmap for cosimulation
|
||||||
portmap = {}
|
portmap = {}
|
||||||
for n, s in intf.argdict.items():
|
for n, s in intf.argdict.items():
|
||||||
if hasattr(s, 'driver'): portmap[n] = s.driver()
|
if hasattr(s, 'driver'):
|
||||||
else: portmap[n] = s
|
portmap[n] = s.driver()
|
||||||
|
else:
|
||||||
|
portmap[n] = s
|
||||||
self.portmap = portmap
|
self.portmap = portmap
|
||||||
|
|
||||||
### clean-up properly ###
|
### clean-up properly ###
|
||||||
@ -232,7 +237,6 @@ class _ToVerilogConvertor(object):
|
|||||||
self.no_testbench = False
|
self.no_testbench = False
|
||||||
self.trace = False
|
self.trace = False
|
||||||
|
|
||||||
|
|
||||||
def _convert_filter(self, h, intf, siglist, memlist, genlist):
|
def _convert_filter(self, h, intf, siglist, memlist, genlist):
|
||||||
# intended to be a entry point for other uses:
|
# intended to be a entry point for other uses:
|
||||||
# code checking, optimizations, etc
|
# code checking, optimizations, etc
|
||||||
@ -247,6 +251,7 @@ myhdl_header = """\
|
|||||||
// Date: $date
|
// Date: $date
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def _writeFileHeader(f, fn, ts):
|
def _writeFileHeader(f, fn, ts):
|
||||||
vars = dict(filename=fn,
|
vars = dict(filename=fn,
|
||||||
version=myhdl.__version__,
|
version=myhdl.__version__,
|
||||||
@ -419,6 +424,7 @@ def _getRangeString(s):
|
|||||||
else:
|
else:
|
||||||
raise AssertionError
|
raise AssertionError
|
||||||
|
|
||||||
|
|
||||||
def _getSignString(s):
|
def _getSignString(s):
|
||||||
if s._min is not None and s._min < 0:
|
if s._min is not None and s._min < 0:
|
||||||
return "signed "
|
return "signed "
|
||||||
@ -447,8 +453,10 @@ def _convertGens(genlist, vfile):
|
|||||||
Visitor = _ConvertAlwaysCombVisitor
|
Visitor = _ConvertAlwaysCombVisitor
|
||||||
v = Visitor(tree, blockBuf, funcBuf)
|
v = Visitor(tree, blockBuf, funcBuf)
|
||||||
v.visit(tree)
|
v.visit(tree)
|
||||||
vfile.write(funcBuf.getvalue()); funcBuf.close()
|
vfile.write(funcBuf.getvalue())
|
||||||
vfile.write(blockBuf.getvalue()); blockBuf.close()
|
funcBuf.close()
|
||||||
|
vfile.write(blockBuf.getvalue())
|
||||||
|
blockBuf.close()
|
||||||
|
|
||||||
|
|
||||||
opmap = {
|
opmap = {
|
||||||
@ -485,7 +493,6 @@ nameconstant_map = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin):
|
class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin):
|
||||||
|
|
||||||
def __init__(self, tree, buf):
|
def __init__(self, tree, buf):
|
||||||
@ -543,7 +550,8 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin):
|
|||||||
return r
|
return r
|
||||||
|
|
||||||
def writeDeclaration(self, obj, name, dir):
|
def writeDeclaration(self, obj, name, dir):
|
||||||
if dir: dir = dir + ' '
|
if dir:
|
||||||
|
dir = dir + ' '
|
||||||
if type(obj) is bool:
|
if type(obj) is bool:
|
||||||
self.write("%s%s" % (dir, name))
|
self.write("%s%s" % (dir, name))
|
||||||
elif isinstance(obj, int):
|
elif isinstance(obj, int):
|
||||||
@ -1287,7 +1295,6 @@ class _ConvertInitialVisitor(_ConvertVisitor):
|
|||||||
self.writeline(2)
|
self.writeline(2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _ConvertAlwaysCombVisitor(_ConvertVisitor):
|
class _ConvertAlwaysCombVisitor(_ConvertVisitor):
|
||||||
|
|
||||||
def __init__(self, tree, blockBuf, funcBuf):
|
def __init__(self, tree, blockBuf, funcBuf):
|
||||||
@ -1307,12 +1314,12 @@ class _ConvertAlwaysCombVisitor(_ConvertVisitor):
|
|||||||
self.writeline(2)
|
self.writeline(2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _ConvertSimpleAlwaysCombVisitor(_ConvertVisitor):
|
class _ConvertSimpleAlwaysCombVisitor(_ConvertVisitor):
|
||||||
|
|
||||||
def __init__(self, tree, blockBuf, funcBuf):
|
def __init__(self, tree, blockBuf, funcBuf):
|
||||||
_ConvertVisitor.__init__(self, tree, blockBuf)
|
_ConvertVisitor.__init__(self, tree, blockBuf)
|
||||||
self.funcBuf = funcBuf
|
self.funcBuf = funcBuf
|
||||||
|
|
||||||
def visit_Attribute(self, node):
|
def visit_Attribute(self, node):
|
||||||
if isinstance(node.ctx, ast.Store):
|
if isinstance(node.ctx, ast.Store):
|
||||||
self.write("assign ")
|
self.write("assign ")
|
||||||
@ -1443,8 +1450,6 @@ class _ConvertFunctionVisitor(_ConvertVisitor):
|
|||||||
self.write("disable %s;" % self.returnLabel)
|
self.write("disable %s;" % self.returnLabel)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _ConvertTaskVisitor(_ConvertVisitor):
|
class _ConvertTaskVisitor(_ConvertVisitor):
|
||||||
|
|
||||||
def __init__(self, tree, funcBuf):
|
def __init__(self, tree, funcBuf):
|
||||||
@ -1486,6 +1491,7 @@ def _maybeNegative(obj):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class _AnnotateTypesVisitor(ast.NodeVisitor, _ConversionMixin):
|
class _AnnotateTypesVisitor(ast.NodeVisitor, _ConversionMixin):
|
||||||
|
|
||||||
def __init__(self, tree):
|
def __init__(self, tree):
|
||||||
@ -1555,7 +1561,6 @@ class _AnnotateTypesVisitor(ast.NodeVisitor, _ConversionMixin):
|
|||||||
return
|
return
|
||||||
self.generic_visit(node)
|
self.generic_visit(node)
|
||||||
|
|
||||||
|
|
||||||
def visit_Num(self, node):
|
def visit_Num(self, node):
|
||||||
node.signed = False
|
node.signed = False
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ registerSimulator(
|
|||||||
analyze="ghdl -a --std=08 --workdir=work pck_myhdl_%(version)s.vhd %(topname)s.vhd",
|
analyze="ghdl -a --std=08 --workdir=work pck_myhdl_%(version)s.vhd %(topname)s.vhd",
|
||||||
elaborate="ghdl -e --std=08 --workdir=work %(unitname)s",
|
elaborate="ghdl -e --std=08 --workdir=work %(unitname)s",
|
||||||
simulate="ghdl -r --workdir=work %(unitname)s"
|
simulate="ghdl -r --workdir=work %(unitname)s"
|
||||||
)
|
)
|
||||||
|
|
||||||
registerSimulator(
|
registerSimulator(
|
||||||
name="nvc",
|
name="nvc",
|
||||||
@ -54,7 +54,7 @@ registerSimulator(
|
|||||||
analyze="nvc --work=work_nvc -a pck_myhdl_%(version)s.vhd %(topname)s.vhd",
|
analyze="nvc --work=work_nvc -a pck_myhdl_%(version)s.vhd %(topname)s.vhd",
|
||||||
elaborate="nvc --work=work_nvc -e %(topname)s",
|
elaborate="nvc --work=work_nvc -e %(topname)s",
|
||||||
simulate="nvc --work=work_nvc -r %(topname)s"
|
simulate="nvc --work=work_nvc -r %(topname)s"
|
||||||
)
|
)
|
||||||
|
|
||||||
registerSimulator(
|
registerSimulator(
|
||||||
name="vlog",
|
name="vlog",
|
||||||
@ -64,7 +64,7 @@ registerSimulator(
|
|||||||
skiplines=6,
|
skiplines=6,
|
||||||
skipchars=2,
|
skipchars=2,
|
||||||
ignore=("# **", "# //", "# run -all")
|
ignore=("# **", "# //", "# run -all")
|
||||||
)
|
)
|
||||||
|
|
||||||
registerSimulator(
|
registerSimulator(
|
||||||
name="vcom",
|
name="vcom",
|
||||||
@ -74,7 +74,7 @@ registerSimulator(
|
|||||||
skiplines=6,
|
skiplines=6,
|
||||||
skipchars=2,
|
skipchars=2,
|
||||||
ignore=("# **", "# //", "# Time:", "# run -all")
|
ignore=("# **", "# //", "# Time:", "# run -all")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
registerSimulator(
|
registerSimulator(
|
||||||
@ -82,7 +82,7 @@ registerSimulator(
|
|||||||
hdl="Verilog",
|
hdl="Verilog",
|
||||||
analyze="iverilog -o %(topname)s.o %(topname)s.v",
|
analyze="iverilog -o %(topname)s.o %(topname)s.v",
|
||||||
simulate="vvp %(topname)s.o"
|
simulate="vvp %(topname)s.o"
|
||||||
)
|
)
|
||||||
|
|
||||||
registerSimulator(
|
registerSimulator(
|
||||||
name="cver",
|
name="cver",
|
||||||
@ -90,7 +90,7 @@ registerSimulator(
|
|||||||
analyze="cver -c -q %(topname)s.v",
|
analyze="cver -c -q %(topname)s.v",
|
||||||
simulate="cver -q %(topname)s.v",
|
simulate="cver -q %(topname)s.v",
|
||||||
skiplines=3
|
skiplines=3
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class _VerificationClass(object):
|
class _VerificationClass(object):
|
||||||
@ -101,7 +101,6 @@ class _VerificationClass(object):
|
|||||||
self.simulator = None
|
self.simulator = None
|
||||||
self._analyzeOnly = analyzeOnly
|
self._analyzeOnly = analyzeOnly
|
||||||
|
|
||||||
|
|
||||||
def __call__(self, func, *args, **kwargs):
|
def __call__(self, func, *args, **kwargs):
|
||||||
|
|
||||||
if not self.simulator:
|
if not self.simulator:
|
||||||
@ -117,7 +116,8 @@ class _VerificationClass(object):
|
|||||||
elif isinstance(func, _Block):
|
elif isinstance(func, _Block):
|
||||||
name = func.func.__name__
|
name = func.func.__name__
|
||||||
else:
|
else:
|
||||||
warnings.warn("\n analyze()/verify(): Deprecated usage: See http://dev.myhdl.org/meps/mep-114.html", stacklevel=2)
|
warnings.warn(
|
||||||
|
"\n analyze()/verify(): Deprecated usage: See http://dev.myhdl.org/meps/mep-114.html", stacklevel=2)
|
||||||
try:
|
try:
|
||||||
name = func.__name__
|
name = func.__name__
|
||||||
except:
|
except:
|
||||||
@ -185,7 +185,6 @@ class _VerificationClass(object):
|
|||||||
print("No MyHDL simulation output - nothing to verify", file=sys.stderr)
|
print("No MyHDL simulation output - nothing to verify", file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
if elaborate is not None:
|
if elaborate is not None:
|
||||||
# print(elaborate)
|
# print(elaborate)
|
||||||
ret = subprocess.call(elaborate, shell=True)
|
ret = subprocess.call(elaborate, shell=True)
|
||||||
|
2
pylintrc
2
pylintrc
@ -164,7 +164,7 @@ bad-functions=map,filter,apply,input
|
|||||||
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
|
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
|
||||||
|
|
||||||
# Regular expression which should only match correct module level names
|
# Regular expression which should only match correct module level names
|
||||||
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
|
const-rgx=(([a-zA-Z_][a-zA-Z0-9_]*)|(__.*__))$
|
||||||
|
|
||||||
# Regular expression which should only match correct class names
|
# Regular expression which should only match correct class names
|
||||||
class-rgx=[A-Z_][a-zA-Z0-9]+$
|
class-rgx=[A-Z_][a-zA-Z0-9]+$
|
||||||
|
Loading…
x
Reference in New Issue
Block a user