cocotb 1.9.1__cp37-cp37m-win32.whl → 2.0.0__cp37-cp37m-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cocotb might be problematic. Click here for more details.
- cocotb/_ANSI.py +65 -0
- cocotb/__init__.py +81 -310
- cocotb/_base_triggers.py +515 -0
- cocotb/_bridge.py +186 -0
- cocotb/_decorators.py +515 -0
- cocotb/_deprecation.py +3 -3
- cocotb/_exceptions.py +7 -0
- cocotb/_extended_awaitables.py +419 -0
- cocotb/_gpi_triggers.py +385 -0
- cocotb/_init.py +301 -0
- cocotb/_outcomes.py +54 -0
- cocotb/_profiling.py +46 -0
- cocotb/_py_compat.py +114 -29
- cocotb/_scheduler.py +448 -0
- cocotb/_test.py +248 -0
- cocotb/_test_factory.py +312 -0
- cocotb/_test_functions.py +42 -0
- cocotb/_typing.py +7 -0
- cocotb/_utils.py +274 -0
- cocotb/_version.py +3 -7
- cocotb/_xunit_reporter.py +66 -0
- cocotb/clock.py +353 -108
- cocotb/debug.py +24 -0
- cocotb/handle.py +1370 -793
- cocotb/libs/cocotb.dll +0 -0
- cocotb/libs/cocotb.exp +0 -0
- cocotb/libs/cocotb.lib +0 -0
- cocotb/libs/cocotbfli_modelsim.dll +0 -0
- cocotb/libs/cocotbfli_modelsim.exp +0 -0
- cocotb/libs/cocotbfli_modelsim.lib +0 -0
- cocotb/libs/cocotbutils.dll +0 -0
- cocotb/libs/cocotbutils.exp +0 -0
- cocotb/libs/cocotbutils.lib +0 -0
- cocotb/libs/cocotbvhpi_aldec.dll +0 -0
- cocotb/libs/cocotbvhpi_aldec.exp +0 -0
- cocotb/libs/cocotbvhpi_aldec.lib +0 -0
- cocotb/libs/cocotbvhpi_modelsim.dll +0 -0
- cocotb/libs/cocotbvhpi_modelsim.exp +0 -0
- cocotb/libs/cocotbvhpi_modelsim.lib +0 -0
- cocotb/libs/cocotbvpi_aldec.dll +0 -0
- cocotb/libs/cocotbvpi_aldec.exp +0 -0
- cocotb/libs/cocotbvpi_aldec.lib +0 -0
- cocotb/libs/cocotbvpi_ghdl.dll +0 -0
- cocotb/libs/cocotbvpi_ghdl.exp +0 -0
- cocotb/libs/cocotbvpi_ghdl.lib +0 -0
- cocotb/libs/cocotbvpi_icarus.exp +0 -0
- cocotb/libs/cocotbvpi_icarus.lib +0 -0
- cocotb/libs/cocotbvpi_icarus.vpl +0 -0
- cocotb/libs/cocotbvpi_modelsim.dll +0 -0
- cocotb/libs/cocotbvpi_modelsim.exp +0 -0
- cocotb/libs/cocotbvpi_modelsim.lib +0 -0
- cocotb/libs/embed.dll +0 -0
- cocotb/libs/embed.exp +0 -0
- cocotb/libs/embed.lib +0 -0
- cocotb/libs/gpi.dll +0 -0
- cocotb/libs/gpi.exp +0 -0
- cocotb/libs/gpi.lib +0 -0
- cocotb/libs/gpilog.dll +0 -0
- cocotb/libs/gpilog.exp +0 -0
- cocotb/libs/gpilog.lib +0 -0
- cocotb/libs/pygpilog.dll +0 -0
- cocotb/libs/pygpilog.exp +0 -0
- cocotb/libs/pygpilog.lib +0 -0
- cocotb/logging.py +424 -0
- cocotb/queue.py +103 -57
- cocotb/regression.py +680 -721
- cocotb/result.py +17 -188
- cocotb/share/def/aldec.exp +0 -0
- cocotb/share/def/aldec.lib +0 -0
- cocotb/share/def/ghdl.exp +0 -0
- cocotb/share/def/ghdl.lib +0 -0
- cocotb/share/def/icarus.exp +0 -0
- cocotb/share/def/icarus.lib +0 -0
- cocotb/share/def/modelsim.def +1 -0
- cocotb/share/def/modelsim.exp +0 -0
- cocotb/share/def/modelsim.lib +0 -0
- cocotb/share/include/cocotb_utils.h +9 -32
- cocotb/share/include/embed.h +7 -30
- cocotb/share/include/gpi.h +331 -137
- cocotb/share/include/gpi_logging.h +221 -142
- cocotb/share/include/py_gpi_logging.h +8 -5
- cocotb/share/include/vpi_user_ext.h +4 -26
- cocotb/share/lib/verilator/verilator.cpp +80 -67
- cocotb/simtime.py +230 -0
- cocotb/simulator.cp37-win32.exp +0 -0
- cocotb/simulator.cp37-win32.lib +0 -0
- cocotb/simulator.cp37-win32.pyd +0 -0
- cocotb/task.py +478 -213
- cocotb/triggers.py +55 -1092
- cocotb/types/__init__.py +28 -47
- cocotb/types/_abstract_array.py +151 -0
- cocotb/types/_array.py +295 -0
- cocotb/types/_indexing.py +17 -0
- cocotb/types/_logic.py +333 -0
- cocotb/types/_logic_array.py +868 -0
- cocotb/types/{range.py → _range.py} +47 -48
- cocotb/types/_resolve.py +76 -0
- cocotb/utils.py +58 -646
- {cocotb-1.9.1.dist-info → cocotb-2.0.0.dist-info}/LICENSE +1 -0
- cocotb-2.0.0.dist-info/METADATA +46 -0
- cocotb-2.0.0.dist-info/RECORD +142 -0
- cocotb-2.0.0.dist-info/entry_points.txt +2 -0
- {cocotb-1.9.1.dist-info → cocotb-2.0.0.dist-info}/top_level.txt +1 -0
- cocotb_tools/_coverage.py +33 -0
- cocotb_tools/_vendor/__init__.py +3 -0
- cocotb_tools/check_results.py +65 -0
- cocotb_tools/combine_results.py +152 -0
- cocotb_tools/config.py +241 -0
- {cocotb → cocotb_tools}/ipython_support.py +29 -22
- cocotb_tools/makefiles/Makefile.deprecations +27 -0
- {cocotb/share → cocotb_tools}/makefiles/Makefile.inc +77 -55
- {cocotb/share → cocotb_tools}/makefiles/Makefile.sim +16 -33
- {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.activehdl +18 -18
- cocotb_tools/makefiles/simulators/Makefile.cvc +61 -0
- cocotb_tools/makefiles/simulators/Makefile.dsim +39 -0
- {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.ghdl +13 -42
- cocotb_tools/makefiles/simulators/Makefile.icarus +80 -0
- cocotb_tools/makefiles/simulators/Makefile.ius +93 -0
- cocotb_tools/makefiles/simulators/Makefile.modelsim +9 -0
- cocotb_tools/makefiles/simulators/Makefile.nvc +60 -0
- cocotb_tools/makefiles/simulators/Makefile.questa +29 -0
- cocotb_tools/makefiles/simulators/Makefile.questa-compat +143 -0
- cocotb_tools/makefiles/simulators/Makefile.questa-qisqrun +149 -0
- cocotb_tools/makefiles/simulators/Makefile.riviera +144 -0
- cocotb_tools/makefiles/simulators/Makefile.vcs +65 -0
- {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.verilator +15 -22
- {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.xcelium +20 -52
- cocotb_tools/runner.py +1868 -0
- cocotb/_sim_versions.py → cocotb_tools/sim_versions.py +16 -21
- pygpi/entry.py +34 -18
- cocotb/ANSI.py +0 -92
- cocotb/binary.py +0 -858
- cocotb/config.py +0 -289
- cocotb/decorators.py +0 -332
- cocotb/log.py +0 -303
- cocotb/memdebug.py +0 -35
- cocotb/outcomes.py +0 -56
- cocotb/runner.py +0 -1400
- cocotb/scheduler.py +0 -1099
- cocotb/share/makefiles/Makefile.deprecations +0 -12
- cocotb/share/makefiles/simulators/Makefile.cvc +0 -94
- cocotb/share/makefiles/simulators/Makefile.icarus +0 -111
- cocotb/share/makefiles/simulators/Makefile.ius +0 -125
- cocotb/share/makefiles/simulators/Makefile.modelsim +0 -32
- cocotb/share/makefiles/simulators/Makefile.nvc +0 -64
- cocotb/share/makefiles/simulators/Makefile.questa +0 -168
- cocotb/share/makefiles/simulators/Makefile.riviera +0 -177
- cocotb/share/makefiles/simulators/Makefile.vcs +0 -98
- cocotb/types/array.py +0 -309
- cocotb/types/logic.py +0 -292
- cocotb/types/logic_array.py +0 -298
- cocotb/wavedrom.py +0 -199
- cocotb/xunit_reporter.py +0 -80
- cocotb-1.9.1.dist-info/METADATA +0 -166
- cocotb-1.9.1.dist-info/RECORD +0 -121
- cocotb-1.9.1.dist-info/entry_points.txt +0 -2
- {cocotb-1.9.1.dist-info → cocotb-2.0.0.dist-info}/WHEEL +0 -0
- {cocotb/_vendor → cocotb_tools}/__init__.py +0 -0
- {cocotb → cocotb_tools}/_vendor/distutils_version.py +0 -0
cocotb/types/logic.py
DELETED
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
# Copyright cocotb contributors
|
|
2
|
-
# Licensed under the Revised BSD License, see LICENSE for details.
|
|
3
|
-
# SPDX-License-Identifier: BSD-3-Clause
|
|
4
|
-
import typing
|
|
5
|
-
from functools import lru_cache
|
|
6
|
-
|
|
7
|
-
LogicT = typing.TypeVar("LogicT", bound="Logic")
|
|
8
|
-
LogicLiteralT = typing.Union[str, int, bool]
|
|
9
|
-
LogicConstructibleT = typing.Union[LogicLiteralT, "Logic"]
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
_0 = 0
|
|
13
|
-
_1 = 1
|
|
14
|
-
_X = 2
|
|
15
|
-
_Z = 3
|
|
16
|
-
|
|
17
|
-
_literal_repr: typing.Dict[LogicLiteralT, int] = {
|
|
18
|
-
# 0 and weak 0
|
|
19
|
-
False: _0,
|
|
20
|
-
0: _0,
|
|
21
|
-
"0": _0,
|
|
22
|
-
"L": _0,
|
|
23
|
-
"l": _0,
|
|
24
|
-
# 1 and weak 1
|
|
25
|
-
True: _1,
|
|
26
|
-
1: _1,
|
|
27
|
-
"1": _1,
|
|
28
|
-
"H": _1,
|
|
29
|
-
"h": _1,
|
|
30
|
-
# unknown, unassigned, and weak unknown
|
|
31
|
-
"X": _X,
|
|
32
|
-
"x": _X,
|
|
33
|
-
"U": _X,
|
|
34
|
-
"u": _X,
|
|
35
|
-
"W": _X,
|
|
36
|
-
"w": _X,
|
|
37
|
-
"-": _X,
|
|
38
|
-
# high impedance
|
|
39
|
-
"Z": _Z,
|
|
40
|
-
"z": _Z,
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
class Logic:
|
|
45
|
-
r"""
|
|
46
|
-
Model of a 4-value (``0``, ``1``, ``X``, ``Z``) datatype commonly seen in HDLs.
|
|
47
|
-
|
|
48
|
-
.. currentmodule:: cocotb.types
|
|
49
|
-
|
|
50
|
-
This is modeled after (System)Verilog's 4-value ``logic`` type.
|
|
51
|
-
VHDL's 9-value ``std_ulogic`` type maps to this type by treating weak values as full strength values
|
|
52
|
-
and treating "uninitialized" (``U``) and "don't care" (``-``) as "unknown" (``X``).
|
|
53
|
-
|
|
54
|
-
:class:`Logic` can be converted to and from :class:`int`, :class:`str`, :class:`bool`, and :class:`Bit`
|
|
55
|
-
by using the appropriate constructor syntax.
|
|
56
|
-
The list of values convertable to :class:`Logic` includes
|
|
57
|
-
``0``, ``1``, ``True``, ``False``, ``"0"``, ``"1"``, ``"X"``, ``"Z"``, ``Bit('0')``, and ``Bit('1')``.
|
|
58
|
-
For a comprehensive list of values that can be converted into :class:`Logic` see :file:`tests/pytest/test_logic.py`.
|
|
59
|
-
|
|
60
|
-
.. code-block:: python3
|
|
61
|
-
|
|
62
|
-
>>> Logic("X")
|
|
63
|
-
Logic('X')
|
|
64
|
-
>>> Logic(True)
|
|
65
|
-
Logic('1')
|
|
66
|
-
>>> Logic(1)
|
|
67
|
-
Logic('1')
|
|
68
|
-
>>> Logic(Bit(0))
|
|
69
|
-
Logic('0')
|
|
70
|
-
|
|
71
|
-
>>> Logic() # default value
|
|
72
|
-
Logic('X')
|
|
73
|
-
|
|
74
|
-
>>> str(Logic("Z"))
|
|
75
|
-
'Z'
|
|
76
|
-
>>> bool(Logic(0))
|
|
77
|
-
False
|
|
78
|
-
>>> int(Logic(1))
|
|
79
|
-
1
|
|
80
|
-
>>> Bit(Logic("1"))
|
|
81
|
-
Bit('1')
|
|
82
|
-
|
|
83
|
-
.. note::
|
|
84
|
-
|
|
85
|
-
The :class:`int` and :class:`bool` conversions will raise :exc:`ValueError` if the value is not ``0`` or ``1``.
|
|
86
|
-
|
|
87
|
-
:class:`Logic` values are immutable and therefore hashable and can be placed in :class:`set`\ s and used as keys in :class:`dict`\ s.
|
|
88
|
-
|
|
89
|
-
:class:`Logic` supports the common logic operations ``&``, ``|``, ``^``, and ``~``.
|
|
90
|
-
|
|
91
|
-
.. code-block:: python3
|
|
92
|
-
|
|
93
|
-
>>> def full_adder(a: Logic, b: Logic, carry: Logic) -> typing.Tuple[Logic, Logic]:
|
|
94
|
-
... res = a ^ b ^ carry
|
|
95
|
-
... carry_out = (a & b) | (b & carry) | (a & carry)
|
|
96
|
-
... return res, carry_out
|
|
97
|
-
|
|
98
|
-
>>> full_adder(a=Logic('0'), b=Logic('1'), carry=Logic('1'))
|
|
99
|
-
(Logic('0'), Logic('1'))
|
|
100
|
-
|
|
101
|
-
Args:
|
|
102
|
-
value: value to construct into a :class:`Logic`.
|
|
103
|
-
|
|
104
|
-
Raises:
|
|
105
|
-
ValueError: if the value cannot be constructed into a :class:`Logic`.
|
|
106
|
-
"""
|
|
107
|
-
__slots__ = ("_repr",)
|
|
108
|
-
_repr: int
|
|
109
|
-
|
|
110
|
-
_default = _X
|
|
111
|
-
_valid = {_X, _0, _1, _Z}
|
|
112
|
-
|
|
113
|
-
@classmethod
|
|
114
|
-
@lru_cache(maxsize=None)
|
|
115
|
-
def _make(cls: typing.Type[LogicT], _repr: int) -> LogicT:
|
|
116
|
-
"""enforce singleton"""
|
|
117
|
-
self = object.__new__(cls)
|
|
118
|
-
self._repr = _repr
|
|
119
|
-
return typing.cast(LogicT, self)
|
|
120
|
-
|
|
121
|
-
def __new__(
|
|
122
|
-
cls: typing.Type[LogicT],
|
|
123
|
-
value: typing.Optional[LogicConstructibleT] = None,
|
|
124
|
-
) -> LogicT:
|
|
125
|
-
if isinstance(value, Logic):
|
|
126
|
-
# convert Logic
|
|
127
|
-
_repr = value._repr
|
|
128
|
-
elif value is None:
|
|
129
|
-
_repr = cls._default
|
|
130
|
-
else:
|
|
131
|
-
# convert literal
|
|
132
|
-
try:
|
|
133
|
-
_repr = _literal_repr[value]
|
|
134
|
-
except KeyError:
|
|
135
|
-
raise ValueError(
|
|
136
|
-
"{!r} is not convertible to a {}".format(value, cls.__qualname__)
|
|
137
|
-
) from None
|
|
138
|
-
if _repr not in cls._valid:
|
|
139
|
-
raise ValueError("{!r} is not a valid {}".format(value, cls.__qualname__))
|
|
140
|
-
obj = cls._make(_repr)
|
|
141
|
-
return obj
|
|
142
|
-
|
|
143
|
-
if not typing.TYPE_CHECKING: # pragma: no cover
|
|
144
|
-
# mypy currently does not support lru_cache on __new__
|
|
145
|
-
__new__ = lru_cache(maxsize=None)(__new__)
|
|
146
|
-
|
|
147
|
-
def __and__(self: LogicT, other: LogicT) -> LogicT:
|
|
148
|
-
if not isinstance(other, type(self)):
|
|
149
|
-
return NotImplemented
|
|
150
|
-
return type(self)(
|
|
151
|
-
(
|
|
152
|
-
("0", "0", "0", "0"),
|
|
153
|
-
("0", "1", "X", "X"),
|
|
154
|
-
("0", "X", "X", "X"),
|
|
155
|
-
("0", "X", "X", "X"),
|
|
156
|
-
)[self._repr][other._repr]
|
|
157
|
-
)
|
|
158
|
-
|
|
159
|
-
def __rand__(self: LogicT, other: LogicT) -> LogicT:
|
|
160
|
-
return self & other
|
|
161
|
-
|
|
162
|
-
def __or__(self: LogicT, other: LogicT) -> LogicT:
|
|
163
|
-
if not isinstance(other, type(self)):
|
|
164
|
-
return NotImplemented
|
|
165
|
-
return type(self)(
|
|
166
|
-
(
|
|
167
|
-
("0", "1", "X", "X"),
|
|
168
|
-
("1", "1", "1", "1"),
|
|
169
|
-
("X", "1", "X", "X"),
|
|
170
|
-
("X", "1", "X", "X"),
|
|
171
|
-
)[self._repr][other._repr]
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
def __ror__(self: LogicT, other: LogicT) -> LogicT:
|
|
175
|
-
return self | other
|
|
176
|
-
|
|
177
|
-
def __xor__(self: LogicT, other: LogicT) -> LogicT:
|
|
178
|
-
if not isinstance(other, type(self)):
|
|
179
|
-
return NotImplemented
|
|
180
|
-
return type(self)(
|
|
181
|
-
(
|
|
182
|
-
("0", "1", "X", "X"),
|
|
183
|
-
("1", "0", "X", "X"),
|
|
184
|
-
("X", "X", "X", "X"),
|
|
185
|
-
("X", "X", "X", "X"),
|
|
186
|
-
)[self._repr][other._repr]
|
|
187
|
-
)
|
|
188
|
-
|
|
189
|
-
def __rxor__(self: LogicT, other: LogicT) -> LogicT:
|
|
190
|
-
return self ^ other
|
|
191
|
-
|
|
192
|
-
def __invert__(self: LogicT) -> LogicT:
|
|
193
|
-
return type(self)(("1", "0", "X", "X")[self._repr])
|
|
194
|
-
|
|
195
|
-
def __eq__(self, other: object) -> bool:
|
|
196
|
-
if not isinstance(other, type(self)):
|
|
197
|
-
return NotImplemented
|
|
198
|
-
return self._repr == other._repr
|
|
199
|
-
|
|
200
|
-
def __hash__(self) -> int:
|
|
201
|
-
return self._repr
|
|
202
|
-
|
|
203
|
-
def __repr__(self) -> str:
|
|
204
|
-
return "{}({!r})".format(type(self).__qualname__, str(self))
|
|
205
|
-
|
|
206
|
-
def __str__(self) -> str:
|
|
207
|
-
return ("0", "1", "X", "Z")[self._repr]
|
|
208
|
-
|
|
209
|
-
def __bool__(self) -> bool:
|
|
210
|
-
if self._repr in {_0, _1}:
|
|
211
|
-
return bool(self._repr)
|
|
212
|
-
raise ValueError(f"Cannot convert {self!r} to bool")
|
|
213
|
-
|
|
214
|
-
def __int__(self) -> int:
|
|
215
|
-
if self._repr in {_0, _1}:
|
|
216
|
-
return int(self._repr)
|
|
217
|
-
raise ValueError(f"Cannot convert {self!r} to int")
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
class Bit(Logic):
|
|
221
|
-
r"""
|
|
222
|
-
Model of a 2-value (``0``, ``1``) datatype commonly seen in HDLs.
|
|
223
|
-
|
|
224
|
-
.. currentmodule:: cocotb.types
|
|
225
|
-
|
|
226
|
-
This is modeled after (System)Verilog's 2-value ``bit`` type.
|
|
227
|
-
VHDL's ``bit`` type maps to this type perfectly.
|
|
228
|
-
|
|
229
|
-
:class:`Bit` is a proper subtype of :class:`Logic`, meaning a use of :class:`Logic` can be substituted with a :class:`Bit`.
|
|
230
|
-
Some behavior may surprise you if you do not expect it.
|
|
231
|
-
|
|
232
|
-
.. code-block:: python3
|
|
233
|
-
|
|
234
|
-
>>> Bit(0) == Logic(0)
|
|
235
|
-
True
|
|
236
|
-
>>> Bit(0) in {Logic(0)}
|
|
237
|
-
True
|
|
238
|
-
|
|
239
|
-
:class:`Bit` can be converted to and from :class:`int`, :class:`str`, :class:`bool`, and :class:`Logic`
|
|
240
|
-
by using the appropriate constructor syntax.
|
|
241
|
-
The list of values convertable to :class:`Bit` includes
|
|
242
|
-
``0``, ``1``, ``True``, ``False``, ``"0"``, ``"1"``, ``Logic('0')``, and ``Logic('1')``.
|
|
243
|
-
For a comprehensive list of values that can be converted into :class:`Bit` see :file:`tests/pytest/test_logic.py`.
|
|
244
|
-
|
|
245
|
-
.. code-block:: python3
|
|
246
|
-
|
|
247
|
-
>>> Bit("0")
|
|
248
|
-
Bit('0')
|
|
249
|
-
>>> Bit(True)
|
|
250
|
-
Bit('1')
|
|
251
|
-
>>> Bit(1)
|
|
252
|
-
Bit('1')
|
|
253
|
-
>>> Bit(Logic(0))
|
|
254
|
-
Bit('0')
|
|
255
|
-
|
|
256
|
-
>>> Bit() # default value
|
|
257
|
-
Bit('0')
|
|
258
|
-
|
|
259
|
-
>>> str(Bit("0"))
|
|
260
|
-
'0'
|
|
261
|
-
>>> bool(Bit(False))
|
|
262
|
-
False
|
|
263
|
-
>>> int(Bit(1))
|
|
264
|
-
1
|
|
265
|
-
>>> Logic(Bit("1"))
|
|
266
|
-
Logic('1')
|
|
267
|
-
|
|
268
|
-
:class:`Bit` values are hashable and can be placed in :class:`set`\ s and used as keys in :class:`dict`\ s.
|
|
269
|
-
|
|
270
|
-
:class:`Bit` supports the common logic operations ``&``, ``|``, ``^``, and ``~``.
|
|
271
|
-
|
|
272
|
-
.. code-block:: py3
|
|
273
|
-
|
|
274
|
-
>>> def mux(a: Bit, b: Bit, s: Bit) -> Bit:
|
|
275
|
-
... return (a & ~s) | (b & s)
|
|
276
|
-
|
|
277
|
-
>>> a = Bit(0)
|
|
278
|
-
>>> b = Bit(1)
|
|
279
|
-
>>> sel = Bit(1) # choose second argument
|
|
280
|
-
>>> mux(a, b, sel)
|
|
281
|
-
Bit('1')
|
|
282
|
-
|
|
283
|
-
Args:
|
|
284
|
-
value: value to construct into a :class:`Bit`.
|
|
285
|
-
|
|
286
|
-
Raises:
|
|
287
|
-
ValueError: if the value cannot be constructed into a :class:`Bit`.
|
|
288
|
-
"""
|
|
289
|
-
__slots__ = ()
|
|
290
|
-
|
|
291
|
-
_default = _0
|
|
292
|
-
_valid = {_0, _1}
|
cocotb/types/logic_array.py
DELETED
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
# Copyright cocotb contributors
|
|
2
|
-
# Licensed under the Revised BSD License, see LICENSE for details.
|
|
3
|
-
# SPDX-License-Identifier: BSD-3-Clause
|
|
4
|
-
import typing
|
|
5
|
-
|
|
6
|
-
from cocotb.binary import BinaryRepresentation, BinaryValue
|
|
7
|
-
from cocotb.types.array import Array
|
|
8
|
-
from cocotb.types.logic import Logic, LogicConstructibleT
|
|
9
|
-
from cocotb.types.range import Range
|
|
10
|
-
|
|
11
|
-
LogicT = typing.TypeVar("LogicT", bound=Logic)
|
|
12
|
-
S = typing.TypeVar("S")
|
|
13
|
-
Self = typing.TypeVar("Self", bound="LogicArray")
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class LogicArray(Array[Logic]):
|
|
17
|
-
r"""
|
|
18
|
-
Fixed-sized, arbitrarily-indexed, array of :class:`cocotb.types.Logic`.
|
|
19
|
-
|
|
20
|
-
.. currentmodule:: cocotb.types
|
|
21
|
-
|
|
22
|
-
:class:`LogicArray`\ s can be constructed from either iterables of values
|
|
23
|
-
constructible into :class:`Logic`: like :class:`bool`, :class:`str`, :class:`int`;
|
|
24
|
-
or from integers.
|
|
25
|
-
If constructed from a positive integer, an unsigned bit representation is used to
|
|
26
|
-
construct the :class:`LogicArray`.
|
|
27
|
-
If constructed from a negative integer, a two's complement bit representation is
|
|
28
|
-
used.
|
|
29
|
-
Like :class:`Array`, if no *range* argument is given, it is deduced from the length
|
|
30
|
-
of the iterable or bit string used to initialize the variable.
|
|
31
|
-
If a *range* argument is given, but no value,
|
|
32
|
-
the array is filled with the default value of Logic().
|
|
33
|
-
|
|
34
|
-
.. code-block:: python3
|
|
35
|
-
|
|
36
|
-
>>> LogicArray("01XZ")
|
|
37
|
-
LogicArray('01XZ', Range(3, 'downto', 0))
|
|
38
|
-
|
|
39
|
-
>>> LogicArray([0, True, "X"])
|
|
40
|
-
LogicArray('01X', Range(2, 'downto', 0))
|
|
41
|
-
|
|
42
|
-
>>> LogicArray(0xA) # picks smallest range that can fit the value
|
|
43
|
-
LogicArray('1010', Range(3, 'downto', 0))
|
|
44
|
-
|
|
45
|
-
>>> LogicArray(-4, Range(0, "to", 3)) # will sign-extend
|
|
46
|
-
LogicArray('1100', Range(0, 'to', 3))
|
|
47
|
-
|
|
48
|
-
>>> LogicArray(range=Range(0, "to", 3)) # default values
|
|
49
|
-
LogicArray('XXXX', Range(0, 'to', 3))
|
|
50
|
-
|
|
51
|
-
:class:`LogicArray`\ s support the same operations as :class:`Array`;
|
|
52
|
-
however, it enforces the condition that all elements must be a :class:`Logic`.
|
|
53
|
-
|
|
54
|
-
.. code-block:: python3
|
|
55
|
-
|
|
56
|
-
>>> la = LogicArray("1010")
|
|
57
|
-
>>> la[0] # is indexable
|
|
58
|
-
Logic('0')
|
|
59
|
-
|
|
60
|
-
>>> la[1:] # is slice-able
|
|
61
|
-
LogicArray('10', Range(1, 'downto', 0))
|
|
62
|
-
|
|
63
|
-
>>> Logic("0") in la # is a collection
|
|
64
|
-
True
|
|
65
|
-
|
|
66
|
-
>>> list(la) # is an iterable
|
|
67
|
-
[Logic('1'), Logic('0'), Logic('1'), Logic('0')]
|
|
68
|
-
|
|
69
|
-
When setting an element or slice, the *value* is first constructed into a
|
|
70
|
-
:class:`Logic`.
|
|
71
|
-
|
|
72
|
-
.. code-block:: python3
|
|
73
|
-
|
|
74
|
-
>>> la = LogicArray("1010")
|
|
75
|
-
>>> la[3] = "Z"
|
|
76
|
-
>>> la[3]
|
|
77
|
-
Logic('Z')
|
|
78
|
-
|
|
79
|
-
>>> la[2:] = ['X', True, 0]
|
|
80
|
-
>>> la
|
|
81
|
-
LogicArray('ZX10', Range(3, 'downto', 0))
|
|
82
|
-
|
|
83
|
-
:class:`LogicArray`\ s can be converted into :class:`str`\ s or :class:`int`\ s.
|
|
84
|
-
|
|
85
|
-
.. code-block:: python3
|
|
86
|
-
|
|
87
|
-
>>> la = LogicArray("1010")
|
|
88
|
-
>>> la.binstr
|
|
89
|
-
'1010'
|
|
90
|
-
|
|
91
|
-
>>> la.integer # uses unsigned representation
|
|
92
|
-
10
|
|
93
|
-
|
|
94
|
-
>>> la.signed_integer # uses two's complement representation
|
|
95
|
-
-6
|
|
96
|
-
|
|
97
|
-
:class:`LogicArray`\ s also support element-wise logical operations: ``&``, ``|``,
|
|
98
|
-
``^``, and ``~``.
|
|
99
|
-
|
|
100
|
-
.. code-block:: python3
|
|
101
|
-
|
|
102
|
-
>>> def big_mux(a: LogicArray, b: LogicArray, sel: Logic) -> LogicArray:
|
|
103
|
-
... s = LogicArray([sel] * len(a))
|
|
104
|
-
... return (a & ~s) | (b & s)
|
|
105
|
-
|
|
106
|
-
>>> la = LogicArray("0110")
|
|
107
|
-
>>> p = LogicArray("1110")
|
|
108
|
-
>>> sel = Logic('1') # choose second option
|
|
109
|
-
>>> big_mux(la, p, sel)
|
|
110
|
-
LogicArray('1110', Range(3, 'downto', 0))
|
|
111
|
-
|
|
112
|
-
Args:
|
|
113
|
-
value: Initial value for the array.
|
|
114
|
-
range: Indexing scheme of the array.
|
|
115
|
-
|
|
116
|
-
Raises:
|
|
117
|
-
ValueError: When argument values cannot be used to construct an array.
|
|
118
|
-
TypeError: When invalid argument types are used.
|
|
119
|
-
"""
|
|
120
|
-
|
|
121
|
-
__slots__ = ()
|
|
122
|
-
|
|
123
|
-
@typing.overload
|
|
124
|
-
def __init__(
|
|
125
|
-
self,
|
|
126
|
-
value: typing.Union[int, typing.Iterable[LogicConstructibleT], BinaryValue],
|
|
127
|
-
range: typing.Optional[Range],
|
|
128
|
-
):
|
|
129
|
-
...
|
|
130
|
-
|
|
131
|
-
@typing.overload
|
|
132
|
-
def __init__(
|
|
133
|
-
self,
|
|
134
|
-
value: typing.Union[
|
|
135
|
-
int, typing.Iterable[LogicConstructibleT], BinaryValue, None
|
|
136
|
-
],
|
|
137
|
-
range: Range,
|
|
138
|
-
):
|
|
139
|
-
...
|
|
140
|
-
|
|
141
|
-
def __init__(
|
|
142
|
-
self,
|
|
143
|
-
value: typing.Union[
|
|
144
|
-
int, typing.Iterable[LogicConstructibleT], BinaryValue, None
|
|
145
|
-
] = None,
|
|
146
|
-
range: typing.Optional[Range] = None,
|
|
147
|
-
) -> None:
|
|
148
|
-
if value is None and range is None:
|
|
149
|
-
raise ValueError(
|
|
150
|
-
"at least one of the value and range input parameters must be given"
|
|
151
|
-
)
|
|
152
|
-
if value is None:
|
|
153
|
-
self._value = [Logic() for _ in range]
|
|
154
|
-
elif isinstance(value, int):
|
|
155
|
-
if value < 0:
|
|
156
|
-
bitlen = int.bit_length(value + 1) + 1
|
|
157
|
-
else:
|
|
158
|
-
bitlen = max(1, int.bit_length(value))
|
|
159
|
-
if range is None:
|
|
160
|
-
self._value = [Logic(v) for v in _int_to_bitstr(value, bitlen)]
|
|
161
|
-
else:
|
|
162
|
-
if bitlen > len(range):
|
|
163
|
-
raise ValueError(f"{value} will not fit in {range}")
|
|
164
|
-
self._value = [Logic(v) for v in _int_to_bitstr(value, len(range))]
|
|
165
|
-
elif isinstance(value, typing.Iterable):
|
|
166
|
-
self._value = [Logic(v) for v in value]
|
|
167
|
-
elif isinstance(value, BinaryValue):
|
|
168
|
-
self._value = [Logic(v) for v in value.binstr]
|
|
169
|
-
else:
|
|
170
|
-
raise TypeError(
|
|
171
|
-
f"cannot construct {type(self).__qualname__} from value of type {type(value).__qualname__}"
|
|
172
|
-
)
|
|
173
|
-
if range is None:
|
|
174
|
-
self._range = Range(len(self._value) - 1, "downto", 0)
|
|
175
|
-
else:
|
|
176
|
-
self._range = range
|
|
177
|
-
if len(self._value) != len(self._range):
|
|
178
|
-
raise ValueError(
|
|
179
|
-
f"value of length {len(self._value)} will not fit in {self._range}"
|
|
180
|
-
)
|
|
181
|
-
|
|
182
|
-
@property
|
|
183
|
-
def binstr(self) -> str:
|
|
184
|
-
return "".join(str(bit) for bit in self)
|
|
185
|
-
|
|
186
|
-
@property
|
|
187
|
-
def is_resolvable(self) -> bool:
|
|
188
|
-
return all(bit in (Logic(0), Logic(1)) for bit in self)
|
|
189
|
-
|
|
190
|
-
@property
|
|
191
|
-
def integer(self) -> int:
|
|
192
|
-
value = 0
|
|
193
|
-
for bit in self:
|
|
194
|
-
value = value << 1 | int(bit)
|
|
195
|
-
return value
|
|
196
|
-
|
|
197
|
-
@property
|
|
198
|
-
def signed_integer(self) -> int:
|
|
199
|
-
value = self.integer
|
|
200
|
-
if value >= (1 << (len(self) - 1)):
|
|
201
|
-
value -= 1 << len(self)
|
|
202
|
-
return value
|
|
203
|
-
|
|
204
|
-
@typing.overload
|
|
205
|
-
def __setitem__(self, item: int, value: LogicConstructibleT) -> None:
|
|
206
|
-
...
|
|
207
|
-
|
|
208
|
-
@typing.overload
|
|
209
|
-
def __setitem__(
|
|
210
|
-
self, item: slice, value: typing.Iterable[LogicConstructibleT]
|
|
211
|
-
) -> None:
|
|
212
|
-
...
|
|
213
|
-
|
|
214
|
-
def __setitem__(
|
|
215
|
-
self,
|
|
216
|
-
item: typing.Union[int, slice],
|
|
217
|
-
value: typing.Union[LogicConstructibleT, typing.Iterable[LogicConstructibleT]],
|
|
218
|
-
) -> None:
|
|
219
|
-
if isinstance(item, int):
|
|
220
|
-
super().__setitem__(item, Logic(typing.cast(LogicConstructibleT, value)))
|
|
221
|
-
elif isinstance(item, slice):
|
|
222
|
-
super().__setitem__(
|
|
223
|
-
item,
|
|
224
|
-
(
|
|
225
|
-
Logic(v)
|
|
226
|
-
for v in typing.cast(typing.Iterable[LogicConstructibleT], value)
|
|
227
|
-
),
|
|
228
|
-
)
|
|
229
|
-
else:
|
|
230
|
-
raise TypeError(
|
|
231
|
-
f"indexes must be ints or slices, not {type(item).__name__}"
|
|
232
|
-
)
|
|
233
|
-
|
|
234
|
-
def __repr__(self) -> str:
|
|
235
|
-
return "{}({!r}, {!r})".format(type(self).__qualname__, self.binstr, self.range)
|
|
236
|
-
|
|
237
|
-
def __and__(self: Self, other: Self) -> Self:
|
|
238
|
-
if isinstance(other, type(self)):
|
|
239
|
-
if len(self) != len(other):
|
|
240
|
-
raise ValueError(
|
|
241
|
-
f"cannot perform bitwise & "
|
|
242
|
-
f"between {type(self).__qualname__} of length {len(self)} "
|
|
243
|
-
f"and {type(other).__qualname__} of length {len(other)}"
|
|
244
|
-
)
|
|
245
|
-
return type(self)(a & b for a, b in zip(self, other)) # type: ignore
|
|
246
|
-
return NotImplemented
|
|
247
|
-
|
|
248
|
-
def __rand__(self: Self, other: Self) -> Self:
|
|
249
|
-
return self & other
|
|
250
|
-
|
|
251
|
-
def __or__(self: Self, other: Self) -> Self:
|
|
252
|
-
if isinstance(other, type(self)):
|
|
253
|
-
if len(self) != len(other):
|
|
254
|
-
raise ValueError(
|
|
255
|
-
f"cannot perform bitwise | "
|
|
256
|
-
f"between {type(self).__qualname__} of length {len(self)} "
|
|
257
|
-
f"and {type(other).__qualname__} of length {len(other)}"
|
|
258
|
-
)
|
|
259
|
-
return type(self)(a | b for a, b in zip(self, other)) # type: ignore
|
|
260
|
-
return NotImplemented
|
|
261
|
-
|
|
262
|
-
def __ror__(self: Self, other: Self) -> Self:
|
|
263
|
-
return self | other
|
|
264
|
-
|
|
265
|
-
def __xor__(self: Self, other: Self) -> Self:
|
|
266
|
-
if isinstance(other, type(self)):
|
|
267
|
-
if len(self) != len(other):
|
|
268
|
-
raise ValueError(
|
|
269
|
-
f"cannot perform bitwise ^ "
|
|
270
|
-
f"between {type(self).__qualname__} of length {len(self)} "
|
|
271
|
-
f"and {type(other).__qualname__} of length {len(other)}"
|
|
272
|
-
)
|
|
273
|
-
return type(self)(a ^ b for a, b in zip(self, other)) # type: ignore
|
|
274
|
-
return NotImplemented
|
|
275
|
-
|
|
276
|
-
def __rxor__(self: Self, other: Self) -> Self:
|
|
277
|
-
return self ^ other
|
|
278
|
-
|
|
279
|
-
def __invert__(self: Self) -> Self:
|
|
280
|
-
return type(self)(~v for v in self)
|
|
281
|
-
|
|
282
|
-
def to_BinaryValue(
|
|
283
|
-
self,
|
|
284
|
-
bigEndian: bool = True,
|
|
285
|
-
binaryRepresentation: BinaryRepresentation = BinaryRepresentation.UNSIGNED,
|
|
286
|
-
) -> BinaryValue:
|
|
287
|
-
return BinaryValue(
|
|
288
|
-
value=self.binstr,
|
|
289
|
-
n_bits=len(self),
|
|
290
|
-
bigEndian=bigEndian,
|
|
291
|
-
binaryRepresentation=binaryRepresentation,
|
|
292
|
-
)
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
def _int_to_bitstr(value: int, n_bits: int) -> str:
|
|
296
|
-
if value < 0:
|
|
297
|
-
value += 1 << n_bits
|
|
298
|
-
return format(value, f"0{n_bits}b")
|