cocotb 2.0.0rc2__cp311-cp311-macosx_11_0_arm64.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.

Files changed (115) hide show
  1. cocotb/_ANSI.py +65 -0
  2. cocotb/__init__.py +125 -0
  3. cocotb/_base_triggers.py +515 -0
  4. cocotb/_bridge.py +186 -0
  5. cocotb/_decorators.py +515 -0
  6. cocotb/_deprecation.py +36 -0
  7. cocotb/_exceptions.py +7 -0
  8. cocotb/_extended_awaitables.py +419 -0
  9. cocotb/_gpi_triggers.py +385 -0
  10. cocotb/_init.py +301 -0
  11. cocotb/_outcomes.py +54 -0
  12. cocotb/_profiling.py +46 -0
  13. cocotb/_py_compat.py +148 -0
  14. cocotb/_scheduler.py +448 -0
  15. cocotb/_test.py +248 -0
  16. cocotb/_test_factory.py +312 -0
  17. cocotb/_test_functions.py +42 -0
  18. cocotb/_typing.py +7 -0
  19. cocotb/_utils.py +274 -0
  20. cocotb/_version.py +4 -0
  21. cocotb/_xunit_reporter.py +66 -0
  22. cocotb/clock.py +419 -0
  23. cocotb/debug.py +24 -0
  24. cocotb/handle.py +1752 -0
  25. cocotb/libs/libcocotb.so +0 -0
  26. cocotb/libs/libcocotbfli_modelsim.so +0 -0
  27. cocotb/libs/libcocotbutils.so +0 -0
  28. cocotb/libs/libcocotbvhpi_aldec.so +0 -0
  29. cocotb/libs/libcocotbvhpi_ius.so +0 -0
  30. cocotb/libs/libcocotbvhpi_modelsim.so +0 -0
  31. cocotb/libs/libcocotbvhpi_nvc.so +0 -0
  32. cocotb/libs/libcocotbvpi_aldec.so +0 -0
  33. cocotb/libs/libcocotbvpi_dsim.so +0 -0
  34. cocotb/libs/libcocotbvpi_ghdl.so +0 -0
  35. cocotb/libs/libcocotbvpi_icarus.vpl +0 -0
  36. cocotb/libs/libcocotbvpi_ius.so +0 -0
  37. cocotb/libs/libcocotbvpi_modelsim.so +0 -0
  38. cocotb/libs/libcocotbvpi_vcs.so +0 -0
  39. cocotb/libs/libcocotbvpi_verilator.so +0 -0
  40. cocotb/libs/libembed.so +0 -0
  41. cocotb/libs/libgpi.so +0 -0
  42. cocotb/libs/libgpilog.so +0 -0
  43. cocotb/libs/libpygpilog.so +0 -0
  44. cocotb/logging.py +424 -0
  45. cocotb/py.typed +0 -0
  46. cocotb/queue.py +225 -0
  47. cocotb/regression.py +896 -0
  48. cocotb/result.py +38 -0
  49. cocotb/share/def/.gitignore +2 -0
  50. cocotb/share/def/README.md +4 -0
  51. cocotb/share/def/aldec.def +61 -0
  52. cocotb/share/def/ghdl.def +43 -0
  53. cocotb/share/def/icarus.def +43 -0
  54. cocotb/share/def/modelsim.def +138 -0
  55. cocotb/share/include/cocotb_utils.h +70 -0
  56. cocotb/share/include/embed.h +33 -0
  57. cocotb/share/include/exports.h +20 -0
  58. cocotb/share/include/gpi.h +459 -0
  59. cocotb/share/include/gpi_logging.h +291 -0
  60. cocotb/share/include/py_gpi_logging.h +33 -0
  61. cocotb/share/include/vhpi_user_ext.h +26 -0
  62. cocotb/share/include/vpi_user_ext.h +33 -0
  63. cocotb/share/lib/verilator/verilator.cpp +209 -0
  64. cocotb/simtime.py +230 -0
  65. cocotb/simulator.cpython-311-darwin.so +0 -0
  66. cocotb/simulator.pyi +107 -0
  67. cocotb/task.py +590 -0
  68. cocotb/triggers.py +67 -0
  69. cocotb/types/__init__.py +31 -0
  70. cocotb/types/_abstract_array.py +151 -0
  71. cocotb/types/_array.py +295 -0
  72. cocotb/types/_indexing.py +17 -0
  73. cocotb/types/_logic.py +333 -0
  74. cocotb/types/_logic_array.py +868 -0
  75. cocotb/types/_range.py +197 -0
  76. cocotb/types/_resolve.py +76 -0
  77. cocotb/utils.py +110 -0
  78. cocotb-2.0.0rc2.dist-info/METADATA +60 -0
  79. cocotb-2.0.0rc2.dist-info/RECORD +115 -0
  80. cocotb-2.0.0rc2.dist-info/WHEEL +5 -0
  81. cocotb-2.0.0rc2.dist-info/entry_points.txt +2 -0
  82. cocotb-2.0.0rc2.dist-info/licenses/LICENSE +29 -0
  83. cocotb-2.0.0rc2.dist-info/top_level.txt +23 -0
  84. cocotb_tools/__init__.py +0 -0
  85. cocotb_tools/_coverage.py +33 -0
  86. cocotb_tools/_vendor/__init__.py +3 -0
  87. cocotb_tools/_vendor/distutils_version.py +346 -0
  88. cocotb_tools/check_results.py +65 -0
  89. cocotb_tools/combine_results.py +152 -0
  90. cocotb_tools/config.py +241 -0
  91. cocotb_tools/ipython_support.py +99 -0
  92. cocotb_tools/makefiles/Makefile.deprecations +27 -0
  93. cocotb_tools/makefiles/Makefile.inc +198 -0
  94. cocotb_tools/makefiles/Makefile.sim +96 -0
  95. cocotb_tools/makefiles/simulators/Makefile.activehdl +72 -0
  96. cocotb_tools/makefiles/simulators/Makefile.cvc +61 -0
  97. cocotb_tools/makefiles/simulators/Makefile.dsim +39 -0
  98. cocotb_tools/makefiles/simulators/Makefile.ghdl +84 -0
  99. cocotb_tools/makefiles/simulators/Makefile.icarus +80 -0
  100. cocotb_tools/makefiles/simulators/Makefile.ius +93 -0
  101. cocotb_tools/makefiles/simulators/Makefile.modelsim +9 -0
  102. cocotb_tools/makefiles/simulators/Makefile.nvc +60 -0
  103. cocotb_tools/makefiles/simulators/Makefile.questa +29 -0
  104. cocotb_tools/makefiles/simulators/Makefile.questa-compat +143 -0
  105. cocotb_tools/makefiles/simulators/Makefile.questa-qisqrun +149 -0
  106. cocotb_tools/makefiles/simulators/Makefile.riviera +144 -0
  107. cocotb_tools/makefiles/simulators/Makefile.vcs +65 -0
  108. cocotb_tools/makefiles/simulators/Makefile.verilator +79 -0
  109. cocotb_tools/makefiles/simulators/Makefile.xcelium +104 -0
  110. cocotb_tools/py.typed +0 -0
  111. cocotb_tools/runner.py +1868 -0
  112. cocotb_tools/sim_versions.py +140 -0
  113. pygpi/__init__.py +0 -0
  114. pygpi/entry.py +42 -0
  115. pygpi/py.typed +0 -0
cocotb_tools/config.py ADDED
@@ -0,0 +1,241 @@
1
+ #!/usr/bin/env python
2
+ # Copyright cocotb contributors
3
+ # Copyright (c) 2013 Potential Ventures Ltd
4
+ # Copyright (c) 2013 SolarFlare Communications Inc
5
+ # Licensed under the Revised BSD License, see LICENSE for details.
6
+ # SPDX-License-Identifier: BSD-3-Clause
7
+
8
+ """
9
+ Module for querying the cocotb configuration
10
+
11
+ This module provides information in module global variables and through a
12
+ ``main()`` function that is used in the cocotb-config script.
13
+
14
+ Global variables:
15
+ share_dir: str, path where the cocotb data is stored
16
+ makefiles_dir: str, path where the cocotb makefiles are installed
17
+ libs_dir: str, path where the cocotb interface libraries are located
18
+ """
19
+
20
+ import argparse
21
+ import os
22
+ import sys
23
+ import textwrap
24
+ from pathlib import Path
25
+
26
+ import find_libpython
27
+
28
+ import cocotb_tools
29
+
30
+ base_tools_dir = Path(cocotb_tools.__file__).parent.resolve()
31
+ base_cocotb_dir = (base_tools_dir.parent / "cocotb").resolve()
32
+ if not (base_cocotb_dir.exists() and (base_cocotb_dir / "libs").exists()):
33
+ import cocotb
34
+
35
+ base_cocotb_dir = Path(cocotb.__file__).parent.resolve()
36
+
37
+ share_dir = base_cocotb_dir.joinpath("share")
38
+ libs_dir = base_cocotb_dir.joinpath("libs")
39
+ makefiles_dir = base_tools_dir.joinpath("makefiles")
40
+
41
+
42
+ def _get_version() -> str:
43
+ import cocotb # noqa: PLC0415
44
+
45
+ return cocotb.__version__
46
+
47
+
48
+ def _help_vars_text() -> str:
49
+ if "dev" in _get_version():
50
+ doclink = "https://docs.cocotb.org/en/development/library_reference.html"
51
+ else:
52
+ doclink = f"https://docs.cocotb.org/en/v{_get_version()}/library_reference.html"
53
+
54
+ # NOTE: make sure to keep "helpmsg" aligned with docs/source/library_reference.rst
55
+ helpmsg = textwrap.dedent(
56
+ """\
57
+ The following variables are environment variables:
58
+
59
+ cocotb
60
+ ------
61
+ COCOTB_TOPLEVEL Instance in the hierarchy to use as the DUT
62
+ COCOTB_RANDOM_SEED Random seed, to recreate a previous test stimulus
63
+ COCOTB_ANSI_OUTPUT Force cocotb to print or not print in color
64
+ COCOTB_REDUCED_LOG_FMT Display log lines shorter
65
+ COCOTB_ATTACH Pause time value in seconds before the simulator start
66
+ COCOTB_ENABLE_PROFILING Performance analysis of the Python portion of cocotb
67
+ COCOTB_LOG_LEVEL Default logging level (default INFO)
68
+ COCOTB_RESOLVE_X How to resolve X, Z, U, W, - on integer conversion
69
+ LIBPYTHON_LOC Absolute path to libpython
70
+
71
+ Regression Manager
72
+ ------------------
73
+ COCOTB_PDB_ON_EXCEPTION Drop into the Python debugger (pdb) on exception
74
+ COCOTB_TEST_MODULES Module(s) to search for test functions (comma-separated)
75
+ COCOTB_TESTCASE Test function(s) to run (comma-separated list)
76
+ COCOTB_RESULTS_FILE File name for xUnit XML tests results
77
+ COCOTB_USER_COVERAGE Collect Python user coverage (HDL for some simulators)
78
+ COVERAGE_RCFILE Configuration for user code coverage
79
+
80
+ GPI
81
+ ---
82
+ GPI_EXTRA Extra libraries to load at runtime (comma-separated)
83
+
84
+ Scheduler
85
+ ---------
86
+ COCOTB_SCHEDULER_DEBUG Enable additional output of coroutine scheduler
87
+ COCOTB_TRUST_INERTIAL_WRITES Trust inertial writes rather than mock them using scheduler
88
+
89
+ For details, see {}"""
90
+ ).format(doclink)
91
+ return helpmsg
92
+
93
+
94
+ def lib_name(interface: str, simulator: str) -> str:
95
+ """
96
+ Return the name of interface library for given interface (VPI/VHPI/FLI) and simulator.
97
+ """
98
+
99
+ interface_name = interface.lower()
100
+ supported_interfaces = ["vpi", "vhpi", "fli"]
101
+ if interface_name not in supported_interfaces:
102
+ raise ValueError(
103
+ "Wrong interface used. Supported: " + ", ".join(supported_interfaces)
104
+ )
105
+
106
+ simulator_name = simulator.lower()
107
+ supported_sims = [
108
+ "icarus",
109
+ "questa",
110
+ "modelsim",
111
+ "ius",
112
+ "xcelium",
113
+ "vcs",
114
+ "ghdl",
115
+ "riviera",
116
+ "activehdl",
117
+ "cvc",
118
+ "nvc",
119
+ "dsim",
120
+ ]
121
+ if simulator not in supported_sims:
122
+ raise ValueError(
123
+ "Wrong simulator name. Supported: " + ", ".join(supported_sims)
124
+ )
125
+
126
+ if simulator_name in ["questa", "cvc"]:
127
+ library_name = "modelsim"
128
+ elif simulator_name == "xcelium":
129
+ library_name = "ius"
130
+ elif simulator_name in ["riviera", "activehdl"]:
131
+ library_name = "aldec"
132
+ else:
133
+ library_name = simulator_name
134
+
135
+ if library_name == "icarus":
136
+ lib_ext = ""
137
+ elif os.name == "nt":
138
+ lib_ext = ".dll"
139
+ else:
140
+ lib_ext = ".so"
141
+
142
+ # check if compiled with msvc
143
+ if (libs_dir / "cocotb.dll").is_file():
144
+ lib_prefix = ""
145
+ else:
146
+ lib_prefix = "lib"
147
+
148
+ return lib_prefix + "cocotb" + interface_name + "_" + library_name + lib_ext
149
+
150
+
151
+ def lib_name_path(interface: str, simulator: str) -> Path:
152
+ """
153
+ Return the absolute path of interface library for given interface (VPI/VHPI/FLI) and simulator
154
+ """
155
+ return libs_dir / lib_name(interface, simulator)
156
+
157
+
158
+ def _get_parser() -> argparse.ArgumentParser:
159
+ parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
160
+
161
+ group = parser.add_mutually_exclusive_group()
162
+ group.add_argument(
163
+ "--share",
164
+ action="store_true",
165
+ help="Print the path to cocotb's share directory",
166
+ )
167
+ group.add_argument(
168
+ "--makefiles",
169
+ action="store_true",
170
+ help="Print the path to cocotb's makefile directory",
171
+ )
172
+ group.add_argument(
173
+ "--python-bin",
174
+ action="store_true",
175
+ help="Print the path to the Python executable associated with the environment that cocotb is installed in.",
176
+ )
177
+ group.add_argument(
178
+ "--help-vars",
179
+ action="store_true",
180
+ help="Print help about supported Makefile variables",
181
+ )
182
+ group.add_argument(
183
+ "--libpython",
184
+ action="store_true",
185
+ help="Print the absolute path to the libpython associated with the current Python installation",
186
+ )
187
+ group.add_argument(
188
+ "--lib-dir",
189
+ action="store_true",
190
+ help="Print the absolute path to the interface libraries location",
191
+ )
192
+ group.add_argument(
193
+ "--lib-name",
194
+ help="Print the name of interface library for given interface (VPI/VHPI/FLI) and simulator",
195
+ nargs=2,
196
+ metavar=("INTERFACE", "SIMULATOR"),
197
+ )
198
+ group.add_argument(
199
+ "--lib-name-path",
200
+ help="Print the absolute path of interface library for given interface (VPI/VHPI/FLI) and simulator",
201
+ nargs=2,
202
+ metavar=("INTERFACE", "SIMULATOR"),
203
+ )
204
+ group.add_argument(
205
+ "--version",
206
+ action="store_true",
207
+ help="Print the version of cocotb",
208
+ )
209
+
210
+ return parser
211
+
212
+
213
+ def main() -> None:
214
+ parser = _get_parser()
215
+ args = parser.parse_args()
216
+
217
+ if args.share:
218
+ print(share_dir.as_posix())
219
+ elif args.makefiles:
220
+ print(makefiles_dir.as_posix())
221
+ elif args.python_bin:
222
+ print(Path(sys.executable).as_posix())
223
+ elif args.help_vars:
224
+ print(_help_vars_text())
225
+ elif args.libpython:
226
+ libpython_path = find_libpython.find_libpython()
227
+ if libpython_path is None:
228
+ sys.exit(1)
229
+ print(Path(libpython_path).as_posix())
230
+ elif args.lib_dir:
231
+ print(libs_dir.as_posix())
232
+ elif args.lib_name:
233
+ print(lib_name(*args.lib_name))
234
+ elif args.lib_name_path:
235
+ print(lib_name_path(*args.lib_name_path).as_posix())
236
+ elif args.version:
237
+ print(_get_version())
238
+
239
+
240
+ if __name__ == "__main__":
241
+ main()
@@ -0,0 +1,99 @@
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+ from typing import Any, Dict, TypeVar
5
+
6
+ import IPython
7
+ from IPython.terminal.ipapp import load_default_config
8
+ from IPython.terminal.prompts import Prompts
9
+ from pygments.token import Token
10
+
11
+ import cocotb
12
+ from cocotb.task import bridge
13
+ from cocotb.utils import get_sim_time
14
+
15
+ T = TypeVar("T")
16
+
17
+
18
+ class SimTimePrompt(Prompts):
19
+ """custom prompt that shows the sim time after a trigger fires"""
20
+
21
+ _show_time = 1
22
+
23
+ def in_prompt_tokens(self):
24
+ tokens = super().in_prompt_tokens()
25
+ if self._show_time == self.shell.execution_count:
26
+ tokens = [
27
+ (Token.Comment, f"sim time: {get_sim_time()}"),
28
+ (Token.Text, "\n"),
29
+ *tokens,
30
+ ]
31
+ return tokens
32
+
33
+
34
+ async def embed(user_ns: Dict[str, Any] = {}) -> None:
35
+ """
36
+ Start an IPython shell in the current coroutine.
37
+
38
+ Unlike using :func:`IPython.embed` directly, the :keyword:`await` keyword
39
+ can be used directly from the shell to wait for triggers.
40
+ The :keyword:`yield` keyword from the legacy :ref:`yield-syntax` is not supported.
41
+
42
+ This coroutine will complete only when the user exits the interactive session.
43
+
44
+ Args:
45
+ user_ns:
46
+ The variables to have made available in the shell.
47
+ Passing ``locals()`` is often a good idea.
48
+ ``cocotb`` will automatically be included.
49
+
50
+ .. note::
51
+ If your simulator does not provide an appropriate ``stdin``, you may
52
+ find you cannot type in the resulting shell. Using simulators in batch
53
+ or non-GUI mode may resolve this. This feature is experimental, and
54
+ not all simulators are supported.
55
+ """
56
+ # ensure cocotb is in the namespace, for convenience
57
+ default_ns = {"cocotb": cocotb}
58
+ default_ns.update(user_ns)
59
+
60
+ def _runner(x):
61
+ """Handler for async functions"""
62
+ nonlocal shell
63
+ ret = cocotb._scheduler_inst._queue_function(x)
64
+ shell.prompts._show_time = shell.execution_count
65
+ return ret
66
+
67
+ # build the config to enable `await`
68
+ c = load_default_config()
69
+ c.TerminalInteractiveShell.loop_runner = _runner
70
+ c.TerminalInteractiveShell.autoawait = True
71
+ # Python3 checks SQLite DB accesses to ensure process ID matches the one that opened the DB and is not propagated
72
+ # because we launch IPython in a different process, this will cause unnecessary warnings, so disable the PID check
73
+ c.HistoryAccessor.connection_options = {"check_same_thread": False}
74
+ # create a shell with access to the dut, and cocotb pre-imported
75
+ shell = IPython.terminal.embed.InteractiveShellEmbed(
76
+ user_ns=default_ns,
77
+ config=c,
78
+ )
79
+
80
+ # add our custom prompts
81
+ shell.prompts = SimTimePrompt(shell)
82
+
83
+ # start the shell in a background thread
84
+ @bridge
85
+ def run_shell() -> None:
86
+ shell()
87
+
88
+ await run_shell()
89
+
90
+
91
+ @cocotb.test()
92
+ async def run_ipython(dut: Any) -> None:
93
+ """A test that launches an interactive Python shell.
94
+
95
+ Do not call this directly - use this as ``make COCOTB_TEST_MODULES=cocotb.ipython_support``.
96
+
97
+ Within the shell, a global ``dut`` variable pointing to the design will be present.
98
+ """
99
+ await embed(user_ns={"dut": dut})
@@ -0,0 +1,27 @@
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ ifdef VERILATOR_TRACE
6
+ $(warning VERILATOR_TRACE is deprecated, see the "Simulator Support" section in the documentation.)
7
+ endif
8
+
9
+ ifeq ($(SIM_LOWERCASE),aldec)
10
+ $(warning Using SIM=aldec is deprecated, please use SIM=riviera instead.)
11
+ SIM_LOWERCASE := riviera
12
+ endif
13
+
14
+ # Use this function to warn users about deprecated environment variables
15
+ deprecate = $(if $($(1)),$(if $(filter $($(2)),$($(1))),$($(2)),$(warning Using $(1) is deprecated, please use $(2) instead.)$($(1))),$($(2)))
16
+
17
+ ifneq ($(COCOTB_TOPLEVEL),$(TOPLEVEL))
18
+ ifneq ($(TOPLEVEL),)
19
+ COCOTB_TOPLEVEL := $(TOPLEVEL)
20
+ endif
21
+ endif
22
+
23
+ ifneq ($(COCOTB_USER_COVERAGE),$(COVERAGE))
24
+ ifneq ($(COVERAGE),)
25
+ COCOTB_USER_COVERAGE := $(COVERAGE)
26
+ endif
27
+ endif
@@ -0,0 +1,198 @@
1
+ # Copyright cocotb contributors
2
+ # Copyright (c) 2013 Potential Ventures Ltd
3
+ # Copyright (c) 2013 SolarFlare Communications Inc
4
+ # Licensed under the Revised BSD License, see LICENSE for details.
5
+ # SPDX-License-Identifier: BSD-3-Clause
6
+
7
+ # Common makefile included by everything
8
+
9
+ ifndef COCOTB_MAKEFILE_INC_INCLUDED # Protect against multiple includes
10
+ COCOTB_MAKEFILE_INC_INCLUDED = 1
11
+
12
+ # Default sim rule will force a re-run of the simulation (though the cocotb library
13
+ # and RTL compilation phases are still evaluated by makefile dependencies)
14
+ .PHONY: sim
15
+ sim:
16
+ $(RM) $(COCOTB_RESULTS_FILE)
17
+ "$(MAKE)" -f $(firstword $(MAKEFILE_LIST)) $(COCOTB_RESULTS_FILE)
18
+
19
+ # Make sure to use bash for the pipefail option used in many simulator Makefiles
20
+ SHELL := bash
21
+
22
+ OS=$(shell uname)
23
+ ifneq (, $(findstring MINGW, $(OS)))
24
+ OS := Msys
25
+ else ifneq (, $(findstring MSYS, $(OS)))
26
+ OS := Msys
27
+ endif
28
+ export OS
29
+
30
+ export PYGPI_PYTHON_BIN := $(shell $(PYTHON_BIN) -m cocotb_tools.config --python-bin)
31
+
32
+ # Directory containing the cocotb Makefiles
33
+ COCOTB_MAKEFILES_DIR := $(shell $(PYTHON_BIN) -m cocotb_tools.config --makefiles)
34
+
35
+ include $(COCOTB_MAKEFILES_DIR)/Makefile.deprecations
36
+
37
+ PYTHON_ARCH := $(shell $(PYTHON_BIN) -c 'from platform import architecture; print(architecture()[0])')
38
+ ifeq ($(filter $(PYTHON_ARCH),64bit 32bit),)
39
+ $(error Unknown Python architecture: $(PYTHON_ARCH))
40
+ endif
41
+
42
+ ifeq ($(OS),Msys)
43
+ to_tcl_path = $(shell cygpath -m $(1) )
44
+ else
45
+ to_tcl_path = $(1)
46
+ endif
47
+
48
+ # Check that the COCOTB_RESULTS_FILE was created, since we can't set an exit code from cocotb.
49
+ define check_for_results_file
50
+ @test -f $(COCOTB_RESULTS_FILE) || (echo "ERROR: $(COCOTB_RESULTS_FILE) was not written by the simulation!" >&2 && exit 1)
51
+ endef
52
+
53
+ # Check that the COCOTB_RESULTS_FILE was created and has no failures
54
+ define check_results
55
+ @$(PYTHON_BIN) -m cocotb_tools.check_results $(COCOTB_RESULTS_FILE)
56
+ endef
57
+
58
+ SIM_BUILD ?= sim_build
59
+ export SIM_BUILD
60
+
61
+ COCOTB_RESULTS_FILE ?= results.xml
62
+ COCOTB_HDL_TIMEUNIT ?= 1ns
63
+ COCOTB_HDL_TIMEPRECISION ?= 1ps
64
+
65
+ export COCOTB_RESULTS_FILE
66
+
67
+
68
+ $(SIM_BUILD):
69
+ mkdir -p $@
70
+
71
+ # Regression rule uses Make dependencies to determine whether to run the simulation
72
+ .PHONY: regression
73
+ regression: $(COCOTB_RESULTS_FILE)
74
+
75
+ # Attempt to detect TOPLEVEL_LANG based on available sources if not set
76
+ ifeq ($(TOPLEVEL_LANG),)
77
+
78
+ ifneq ($(VHDL_SOURCES),)
79
+ ifeq ($(VERILOG_SOURCES),)
80
+ TOPLEVEL_LANG := vhdl
81
+ endif
82
+ else ifneq ($(VERILOG_SOURCES),)
83
+ ifeq ($(VHDL_SOURCES),)
84
+ TOPLEVEL_LANG := verilog
85
+ endif
86
+ endif
87
+
88
+ endif
89
+
90
+ define find_libpython_errmsg =
91
+
92
+
93
+ find_libpython was not able to find a libpython in the current Python environment. Ensure
94
+ the Python development packages are installed. If they are installed and find_libpython
95
+ is not finding the path to libpython, file an upstream bug in find_libpython; then
96
+ manually override the LIBPYTHON_LOC make variable with the absolute path to libpython.so
97
+ (or python.dll on Windows).
98
+
99
+ endef
100
+
101
+ ifndef LIBPYTHON_LOC
102
+
103
+ # get the path to libpython and the return code from the script
104
+ # adapted from https://stackoverflow.com/a/24658961/6614127
105
+ FIND_LIBPYTHON_RES := $(shell $(PYTHON_BIN) -m cocotb_tools.config --libpython; echo $$?)
106
+ FIND_LIBPYTHON_RC := $(lastword $(FIND_LIBPYTHON_RES))
107
+ LIBPYTHON_LOC := $(strip $(subst $(FIND_LIBPYTHON_RC)QQQQ,,$(FIND_LIBPYTHON_RES)QQQQ))
108
+
109
+ # complain if libpython isn't found, and export otherwise
110
+ ifneq ($(FIND_LIBPYTHON_RC),0)
111
+ $(error $(find_libpython_errmsg))
112
+ endif
113
+
114
+ endif
115
+
116
+ export LIBPYTHON_LOC
117
+
118
+ define check_vhdl_sources
119
+ if [ "$(VHDL_SOURCES_$(LIB))" == "" ]; then \
120
+ >&2 echo "ERROR: VHDL_SOURCES_$(LIB) is empty or undefined, but '$(LIB)' is present in VHDL_LIB_ORDER."; \
121
+ exit 1; \
122
+ fi;
123
+ endef
124
+
125
+ define check_lib_order
126
+ if [ "$(filter $(SOURCES_VAR:VHDL_SOURCES_%=%), $(VHDL_LIB_ORDER))" == "" ]; then \
127
+ >&2 echo "ERROR: $(SOURCES_VAR) defined, but library $(SOURCES_VAR:VHDL_SOURCES_%=%) not present in VHDL_LIB_ORDER."; \
128
+ exit 1; \
129
+ fi;
130
+ endef
131
+
132
+ # NOTE: if the following simulator list is modified, update the sentence
133
+ # "This flag is enabled by default for the GHDL, NVC and Verilator simulators."
134
+ # in docs/source/building.rst accordingly.
135
+ ifneq ($(filter $(SIM),nvc ghdl verilator),)
136
+ COCOTB_TRUST_INERTIAL_WRITES ?= 1
137
+ else
138
+ COCOTB_TRUST_INERTIAL_WRITES ?= 0
139
+ endif
140
+
141
+ export COCOTB_TRUST_INERTIAL_WRITES
142
+
143
+
144
+ # Universal
145
+ clean::
146
+ @$(RM) -rf $(SIM_BUILD)
147
+ @$(RM) -f $(COCOTB_RESULTS_FILE)
148
+
149
+
150
+ # Active-HDL
151
+ clean::
152
+ @$(RM) -rf work
153
+ @$(RM) -rf wave.asdb
154
+
155
+ # IUS
156
+ clean::
157
+ @$(RM) -rf irun.*
158
+ @$(RM) -rf ncsim.*
159
+ @$(RM) -rf gdb_cmd_ncsim
160
+
161
+ # VCS
162
+ clean::
163
+ @$(RM) -rf simv.daidir
164
+ @$(RM) -rf cm.log
165
+ @$(RM) -rf ucli.key
166
+
167
+ # Riviera
168
+ clean::
169
+ @$(RM) -rf compile
170
+ @$(RM) -rf library.cfg
171
+ @$(RM) -rf dataset.asdb
172
+
173
+ # Verilator
174
+ clean::
175
+ @$(RM) -f dump.vcd
176
+ @$(RM) -f dump.fst
177
+
178
+ # Xcelium
179
+ clean::
180
+ @$(RM) -rf xrun.*
181
+ @$(RM) -rf xmsim.*
182
+ @$(RM) -rf gdb_cmd_xmsim
183
+ @$(RM) -f qrun*
184
+ @$(RM) -f visualizer.log
185
+ @$(RM) -f design.bin
186
+ @$(RM) -f qwave.db
187
+ @$(RM) -f transcript
188
+
189
+
190
+ # DSim
191
+ clean::
192
+ @$(RM) -rf dsim.*
193
+ @$(RM) -rf metrics.db
194
+ @$(RM) -rf file.vcd
195
+
196
+ else
197
+ $(warning Including Makefile.inc from a user makefile is a no-op and deprecated. Remove the Makefile.inc inclusion from your makefile, and only leave the Makefile.sim include.)
198
+ endif # COCOTB_MAKEFILE_INC_INCLUDED
@@ -0,0 +1,96 @@
1
+ # Copyright cocotb contributors
2
+ # Copyright (c) 2013, 2018 Potential Ventures Ltd
3
+ # Copyright (c) 2013 SolarFlare Communications Inc
4
+ # Licensed under the Revised BSD License, see LICENSE for details.
5
+ # SPDX-License-Identifier: BSD-3-Clause
6
+
7
+ # This file includes an appropriate makefile depending on the SIM variable.
8
+
9
+ .PHONY: all
10
+ all: sim
11
+
12
+ # NOTE: keep this at 80 chars.
13
+ define help_targets =
14
+ Targets
15
+ =======
16
+ sim Unconditionally re-run the simulator (default)
17
+ regression Run simulator when dependencies have changes
18
+ clean Remove build and simulation artefacts
19
+ help This help text
20
+
21
+ endef
22
+
23
+ # NOTE: keep this at 80 chars.
24
+ define help_makevars =
25
+ Variables
26
+ =========
27
+
28
+ The following variables are makefile variables:
29
+
30
+ Makefile-based Test Scripts
31
+ ---------------------------
32
+ GUI Set this to 1 to enable the GUI mode in the simulator
33
+ SIM Selects which simulator Makefile to use
34
+ WAVES Enable wave traces dump for Riviera-PRO and Questa
35
+ VERILOG_SOURCES A list of the Verilog source files to include
36
+ VHDL_SOURCES A list of the VHDL source files to include
37
+ VHDL_SOURCES_<lib> VHDL source files to include in *lib* (GHDL/NVC/ModelSim/Questa/Xcelium/Incisive/Riviera-PRO only)
38
+ VHDL_LIB_ORDER Compilation order of VHDL libraries (needed for NVC/ModelSim/Questa/Xcelium/Incisive/Riviera-PRO)
39
+ SIM_CMD_PREFIX Prefix for simulation command invocations
40
+ COMPILE_ARGS Arguments to pass to compile (analysis) stage of simulation
41
+ SIM_ARGS Arguments to pass to execution of compiled simulation
42
+ EXTRA_ARGS Arguments for compile and execute phases
43
+ COCOTB_PLUSARGS Plusargs to pass to the simulator
44
+ COCOTB_HDL_TIMEUNIT Default time unit for simulation
45
+ COCOTB_HDL_TIMEPRECISION Default time precision for simulation
46
+ CUSTOM_COMPILE_DEPS Add additional dependencies to the compilation target
47
+ CUSTOM_SIM_DEPS Add additional dependencies to the simulation target
48
+ SIM_BUILD Define a scratch directory for use by the simulator
49
+ SCRIPT_FILE Simulator script to run (for e.g. wave traces)
50
+
51
+ endef
52
+
53
+
54
+ # NOTE: keep *two* empty lines between "define" and "endef":
55
+ define newline
56
+
57
+
58
+ endef
59
+
60
+ # this ensures we use the same python as the one cocotb was installed into
61
+ # attempts to use cocotb_config entry script to get that info, falls back to "python"
62
+ PYTHON_BIN_RES := $(shell cocotb-config --python-bin 2>>/dev/null; echo $$?)
63
+ PYTHON_BIN_RC := $(lastword $(PYTHON_BIN_RES))
64
+ PYTHON_BIN := $(strip $(subst $(PYTHON_BIN_RC)QQQQ,,$(PYTHON_BIN_RES)QQQQ))
65
+ ifneq ($(PYTHON_BIN_RC),0)
66
+ PYTHON_BIN := python3
67
+ endif
68
+
69
+ # this cannot be a regular target because of the way Makefile.$(SIM) is included
70
+ ifeq ($(MAKECMDGOALS),help)
71
+ $(info $(help_targets))
72
+ $(info $(help_makevars))
73
+ # hack to get newlines in output, see https://stackoverflow.com/a/54539610
74
+ # NOTE: the output of the command must not include a '%' sign, otherwise the formatting will break
75
+ help_envvars := $(subst %,${newline},$(shell $(PYTHON_BIN) -m cocotb.config --help-vars | tr \\n %))
76
+ $(info ${help_envvars})
77
+ # is there a cleaner way to exit here?
78
+ $(error Stopping after printing help)
79
+ endif
80
+
81
+ include $(shell $(PYTHON_BIN) -m cocotb_tools.config --makefiles)/Makefile.inc
82
+
83
+ # Default to Icarus if no simulator is defined
84
+ SIM ?= icarus
85
+
86
+ # Maintain backwards compatibility by supporting upper and lower case SIM variable
87
+ SIM_LOWERCASE := $(shell echo $(SIM) | tr A-Z a-z)
88
+
89
+ HAVE_SIMULATOR = $(shell if [ -f $(COCOTB_MAKEFILES_DIR)/simulators/Makefile.$(SIM_LOWERCASE) ]; then echo 1; else echo 0; fi;)
90
+ AVAILABLE_SIMULATORS = $(patsubst .%,%,$(suffix $(wildcard $(COCOTB_MAKEFILES_DIR)/simulators/Makefile.*)))
91
+
92
+ ifeq ($(HAVE_SIMULATOR),0)
93
+ $(error Couldn't find makefile for simulator: "$(SIM_LOWERCASE)"! Available simulators: $(AVAILABLE_SIMULATORS))
94
+ endif
95
+
96
+ include $(COCOTB_MAKEFILES_DIR)/simulators/Makefile.$(SIM_LOWERCASE)