verilator-dspsim 5.30.0__tar.gz
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.
- verilator_dspsim-5.30.0/.github/workflows/build_wheels.yaml +83 -0
- verilator_dspsim-5.30.0/.gitignore +7 -0
- verilator_dspsim-5.30.0/CMakeLists.txt +21 -0
- verilator_dspsim-5.30.0/LICENSE +165 -0
- verilator_dspsim-5.30.0/PKG-INFO +74 -0
- verilator_dspsim-5.30.0/README.md +58 -0
- verilator_dspsim-5.30.0/example/CMakeLists.txt +12 -0
- verilator_dspsim-5.30.0/example/pyproject.toml +16 -0
- verilator_dspsim-5.30.0/example/src/CMakeLists.txt +19 -0
- verilator_dspsim-5.30.0/example/src/_example.cpp +30 -0
- verilator_dspsim-5.30.0/example/src/example/__init__.py +12 -0
- verilator_dspsim-5.30.0/example/src/example.sv +14 -0
- verilator_dspsim-5.30.0/pyproject.toml +75 -0
- verilator_dspsim-5.30.0/scripts/einstall.ps1 +1 -0
- verilator_dspsim-5.30.0/scripts/einstall.sh +1 -0
- verilator_dspsim-5.30.0/scripts/install.ps1 +1 -0
- verilator_dspsim-5.30.0/scripts/install.sh +1 -0
- verilator_dspsim-5.30.0/src/verilator/__init__.py +83 -0
- verilator_dspsim-5.30.0/src/verilator/__main__.py +17 -0
- verilator_dspsim-5.30.0/tests/test_verilator.py +52 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
name: Build
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches:
|
|
7
|
+
- main
|
|
8
|
+
- releases/**
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build_windows_wheels:
|
|
12
|
+
name: Python cibuildwheel windows
|
|
13
|
+
runs-on: ["self-hosted", "Windows", "x64"]
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: actions/setup-python@v5
|
|
18
|
+
with:
|
|
19
|
+
python-version: '3.13'
|
|
20
|
+
cache: 'pip' # caching pip dependencies
|
|
21
|
+
|
|
22
|
+
- name: Build Windows wheels
|
|
23
|
+
run: pipx run cibuildwheel
|
|
24
|
+
|
|
25
|
+
- uses: actions/upload-artifact@v4
|
|
26
|
+
with:
|
|
27
|
+
name: cibw-wheels-windows
|
|
28
|
+
path: ./wheelhouse/*
|
|
29
|
+
|
|
30
|
+
build_linux_wheels:
|
|
31
|
+
name: Python cibuildwheel linux
|
|
32
|
+
runs-on: ["self-hosted", "Linux", "x64"]
|
|
33
|
+
|
|
34
|
+
steps:
|
|
35
|
+
- uses: actions/checkout@v4
|
|
36
|
+
- uses: actions/setup-python@v5
|
|
37
|
+
with:
|
|
38
|
+
python-version: '3.13'
|
|
39
|
+
|
|
40
|
+
- name: Build Linux wheels
|
|
41
|
+
run: pipx run cibuildwheel --platform linux
|
|
42
|
+
|
|
43
|
+
- uses: actions/upload-artifact@v4
|
|
44
|
+
with:
|
|
45
|
+
name: cibw-wheels-linux
|
|
46
|
+
path: ./wheelhouse/*
|
|
47
|
+
|
|
48
|
+
build_sdist:
|
|
49
|
+
name: Build source distribution
|
|
50
|
+
runs-on: ["self-hosted", "Windows", "x64"]
|
|
51
|
+
steps:
|
|
52
|
+
- uses: actions/checkout@v4
|
|
53
|
+
- uses: actions/setup-python@v5
|
|
54
|
+
with:
|
|
55
|
+
python-version: '3.13'
|
|
56
|
+
cache: 'pip' # caching pip dependencies
|
|
57
|
+
|
|
58
|
+
- name: Build sdist
|
|
59
|
+
run: pipx run build --sdist
|
|
60
|
+
|
|
61
|
+
- uses: actions/upload-artifact@v4
|
|
62
|
+
with:
|
|
63
|
+
name: cibw-sdist
|
|
64
|
+
path: ./dist/*
|
|
65
|
+
|
|
66
|
+
# upload_pypi:
|
|
67
|
+
# needs: [build_windows_wheels, build_linux_wheels, build_sdist]
|
|
68
|
+
# runs-on: ubuntu-latest
|
|
69
|
+
# environment: pypi
|
|
70
|
+
# permissions:
|
|
71
|
+
# id-token: write
|
|
72
|
+
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
|
|
73
|
+
# steps:
|
|
74
|
+
# - uses: actions/download-artifact@v4
|
|
75
|
+
# with:
|
|
76
|
+
# # unpacks all CIBW artifacts into dist/
|
|
77
|
+
# pattern: cibw-*
|
|
78
|
+
# path: dist
|
|
79
|
+
# merge-multiple: true
|
|
80
|
+
|
|
81
|
+
# - uses: pypa/gh-action-pypi-publish@release/v1
|
|
82
|
+
# with:
|
|
83
|
+
# repository-url: https://test.pypi.org/legacy/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.26)
|
|
2
|
+
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX VERSION ${SKBUILD_PROJECT_VERSION})
|
|
3
|
+
|
|
4
|
+
# Use fetch content to build verilator as a dependency.
|
|
5
|
+
# scikit-build-core will install all CMake targets into the wheel.
|
|
6
|
+
|
|
7
|
+
# Building Verilator on Windows requires using CMake, so this is the normal process
|
|
8
|
+
# for building Verilator. Before installing, you must install any dependencies.
|
|
9
|
+
# Follow the Verilator user manual to see how to install.
|
|
10
|
+
# TODO: Maybe I can install flex/bison here too?
|
|
11
|
+
|
|
12
|
+
# Alegedly, building verilator with CMake on linux is still experimental.
|
|
13
|
+
# I am using Ubuntu 22.04 on WSL, and it seems to work just fine.
|
|
14
|
+
include(FetchContent)
|
|
15
|
+
FetchContent_Declare(
|
|
16
|
+
verilator
|
|
17
|
+
GIT_REPOSITORY https://github.com/verilator/verilator.git
|
|
18
|
+
GIT_TAG v5.030)
|
|
19
|
+
FetchContent_MakeAvailable(verilator)
|
|
20
|
+
|
|
21
|
+
# No need to do anything else.
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: verilator-dspsim
|
|
3
|
+
Version: 5.30.0
|
|
4
|
+
Summary: A Python wrapper around an installation of Verilator.
|
|
5
|
+
Author: Frank Sodari
|
|
6
|
+
Classifier: Intended Audience :: Developers
|
|
7
|
+
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
|
|
8
|
+
Classifier: Programming Language :: C++
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
11
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
13
|
+
Classifier: Topic :: Utilities
|
|
14
|
+
Project-URL: Homepage, https://github.com/fsodari/verilator-python
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# Verilator Python
|
|
18
|
+
|
|
19
|
+
This python package contains a pre-built installation of verilator, and a python wrapper to run verilator. It should function exactly the same as if you installed verilator through normal means.
|
|
20
|
+
|
|
21
|
+
Installing this python package will install "verilator.exe" into the python environments scripts/bin folder, so it can be ran and can easily be found by CMake.
|
|
22
|
+
|
|
23
|
+
The main goal of this project is to simplify distributing verilator and using it within a python application.
|
|
24
|
+
|
|
25
|
+
# Installation
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Verilator requires that the operating system used to build verilator is the same as the operating system used to run verilator, so wheels built on windows should work well.
|
|
29
|
+
|
|
30
|
+
Otherwise, you can build from source. This requires having a compatible compiler installed, and any dependencies. Read the verilator user manual for more information.
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## Install Options
|
|
34
|
+
|
|
35
|
+
pypi.org
|
|
36
|
+
```
|
|
37
|
+
pip install verilator-dspsim
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
from source
|
|
41
|
+
```
|
|
42
|
+
pip install .
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
cached build directory
|
|
46
|
+
```
|
|
47
|
+
pip install --no-build-isolation -Cbuild-dir=build -v .
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
editable install
|
|
51
|
+
```
|
|
52
|
+
pip install --no-build-isolation -Cbuild-dir=build --config-settings=editable.rebuild=true -v -e .
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Example Project
|
|
56
|
+
|
|
57
|
+
The example project "example" in the root of this repository
|
|
58
|
+
uses scikit-build-core, nanobind, and verilator to build a simple
|
|
59
|
+
verilator simulation wrapped in a python package.
|
|
60
|
+
|
|
61
|
+
You will need to have am appropriate compiler installed.
|
|
62
|
+
Windows: MSVC, Linux: gcc, Mac: clang? (I don't have a Mac)
|
|
63
|
+
|
|
64
|
+
- Install the verilator package from pypi.org, or from source.
|
|
65
|
+
|
|
66
|
+
- Build and install the example python extension
|
|
67
|
+
|
|
68
|
+
- Run the example
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
pip install verilator-dspsim
|
|
72
|
+
pip install ./example
|
|
73
|
+
python -c "import example;example.run_simulation()"
|
|
74
|
+
```
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Verilator Python
|
|
2
|
+
|
|
3
|
+
This python package contains a pre-built installation of verilator, and a python wrapper to run verilator. It should function exactly the same as if you installed verilator through normal means.
|
|
4
|
+
|
|
5
|
+
Installing this python package will install "verilator.exe" into the python environments scripts/bin folder, so it can be ran and can easily be found by CMake.
|
|
6
|
+
|
|
7
|
+
The main goal of this project is to simplify distributing verilator and using it within a python application.
|
|
8
|
+
|
|
9
|
+
# Installation
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
Verilator requires that the operating system used to build verilator is the same as the operating system used to run verilator, so wheels built on windows should work well.
|
|
13
|
+
|
|
14
|
+
Otherwise, you can build from source. This requires having a compatible compiler installed, and any dependencies. Read the verilator user manual for more information.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Install Options
|
|
18
|
+
|
|
19
|
+
pypi.org
|
|
20
|
+
```
|
|
21
|
+
pip install verilator-dspsim
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
from source
|
|
25
|
+
```
|
|
26
|
+
pip install .
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
cached build directory
|
|
30
|
+
```
|
|
31
|
+
pip install --no-build-isolation -Cbuild-dir=build -v .
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
editable install
|
|
35
|
+
```
|
|
36
|
+
pip install --no-build-isolation -Cbuild-dir=build --config-settings=editable.rebuild=true -v -e .
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Example Project
|
|
40
|
+
|
|
41
|
+
The example project "example" in the root of this repository
|
|
42
|
+
uses scikit-build-core, nanobind, and verilator to build a simple
|
|
43
|
+
verilator simulation wrapped in a python package.
|
|
44
|
+
|
|
45
|
+
You will need to have am appropriate compiler installed.
|
|
46
|
+
Windows: MSVC, Linux: gcc, Mac: clang? (I don't have a Mac)
|
|
47
|
+
|
|
48
|
+
- Install the verilator package from pypi.org, or from source.
|
|
49
|
+
|
|
50
|
+
- Build and install the example python extension
|
|
51
|
+
|
|
52
|
+
- Run the example
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
pip install verilator-dspsim
|
|
56
|
+
pip install ./example
|
|
57
|
+
python -c "import example;example.run_simulation()"
|
|
58
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.26)
|
|
2
|
+
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX VERSION ${SKBUILD_PROJECT_VERSION})
|
|
3
|
+
|
|
4
|
+
find_package(Python COMPONENTS Interpreter Development.Module ${SKBUILD_SABI_MODULE} REQUIRED)
|
|
5
|
+
find_package(verilator CONFIG REQUIRED)
|
|
6
|
+
find_package(nanobind CONFIG REQUIRED)
|
|
7
|
+
|
|
8
|
+
message("Found Python: ${Python_EXECUTABLE}")
|
|
9
|
+
message("Found Verilator: ${verilator_DIR}")
|
|
10
|
+
message("Found Nanobind: ${nanobind_DIR}")
|
|
11
|
+
|
|
12
|
+
add_subdirectory(src)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["scikit-build-core>=0.10.6", "nanobind>=2.2.0"]
|
|
3
|
+
build-backend = "scikit_build_core.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "example"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
|
|
9
|
+
[tool.scikit-build]
|
|
10
|
+
cmake.build-type = "Release"
|
|
11
|
+
|
|
12
|
+
# Install the package
|
|
13
|
+
# pip install .
|
|
14
|
+
|
|
15
|
+
# Run the example
|
|
16
|
+
# python -c "import example;example.run_simulation()"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Create nanobind module
|
|
2
|
+
nanobind_add_module(_example _example.cpp)
|
|
3
|
+
|
|
4
|
+
# Verilate the verilog module and link it to the nanobind module.
|
|
5
|
+
verilate(_example SOURCES example.sv)
|
|
6
|
+
|
|
7
|
+
# Generate nanobind type stubs.
|
|
8
|
+
nanobind_add_stub(
|
|
9
|
+
_example_stub
|
|
10
|
+
INSTALL_TIME
|
|
11
|
+
MODULE _example
|
|
12
|
+
OUTPUT example/_example.pyi
|
|
13
|
+
PYTHON_PATH $<TARGET_FILE_DIR:_example>
|
|
14
|
+
DEPENDS _example
|
|
15
|
+
MARKER_FILE example/py.typed)
|
|
16
|
+
|
|
17
|
+
# Install the nanobind wheel.
|
|
18
|
+
install(TARGETS _example LIBRARY DESTINATION example)
|
|
19
|
+
install(FILES _example.cpp DESTINATION ${SKBUILD_HEADERS_DIR})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#include <nanobind/nanobind.h>
|
|
2
|
+
|
|
3
|
+
// Verilated model.
|
|
4
|
+
#include "Vexample.h"
|
|
5
|
+
|
|
6
|
+
// MSVC requires this must be defined.
|
|
7
|
+
double sc_time_stamp() { return 0; }
|
|
8
|
+
|
|
9
|
+
// Instatiate the model, and run it through a simulation.
|
|
10
|
+
void run_simulation()
|
|
11
|
+
{
|
|
12
|
+
Vexample example;
|
|
13
|
+
example.eval();
|
|
14
|
+
|
|
15
|
+
for (int i = 0; i < 10; i++)
|
|
16
|
+
{
|
|
17
|
+
example.clk = 1;
|
|
18
|
+
example.eval();
|
|
19
|
+
example.clk = 0;
|
|
20
|
+
example.eval();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Define the nanobind module.
|
|
25
|
+
NB_MODULE(_example, m)
|
|
26
|
+
{
|
|
27
|
+
m.doc() = "Python Verilator Example";
|
|
28
|
+
|
|
29
|
+
m.def("run_simulation", &run_simulation);
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Imports the contents of the nanobind module _example
|
|
3
|
+
|
|
4
|
+
Test the example by running
|
|
5
|
+
python -c "import example;example.run_simulation()"
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__version__ = "0.0.1"
|
|
10
|
+
|
|
11
|
+
# Import contents from the nanobind module.
|
|
12
|
+
from ._example import run_simulation
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["scikit-build-core>=0.10.6"]
|
|
3
|
+
build-backend = "scikit_build_core.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "verilator-dspsim"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "A Python wrapper around an installation of Verilator."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [{ name = "Frank Sodari" }]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Intended Audience :: Developers",
|
|
13
|
+
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
|
|
14
|
+
"Programming Language :: C++",
|
|
15
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
16
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
17
|
+
"Programming Language :: Python :: Implementation :: PyPy",
|
|
18
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
19
|
+
"Topic :: Utilities",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://github.com/fsodari/verilator-python"
|
|
24
|
+
|
|
25
|
+
# Get the version. Make this automatically match verilator? How? Manually make an update every verilator release?
|
|
26
|
+
[tool.scikit-build.metadata.version]
|
|
27
|
+
provider = "scikit_build_core.metadata.regex"
|
|
28
|
+
input = "src/verilator/__init__.py"
|
|
29
|
+
|
|
30
|
+
[tool.scikit-build]
|
|
31
|
+
cmake.version = ">=3.26.1"
|
|
32
|
+
cmake.build-type = "Release"
|
|
33
|
+
build.verbose = true
|
|
34
|
+
|
|
35
|
+
# Supporting cp312 stable abi.
|
|
36
|
+
wheel.py-api = "cp312"
|
|
37
|
+
|
|
38
|
+
# The installed package.
|
|
39
|
+
wheel.packages = ["src/verilator"]
|
|
40
|
+
|
|
41
|
+
# This needs to be set so that verilator installs at site-packages/verilator
|
|
42
|
+
wheel.install-dir = "verilator"
|
|
43
|
+
|
|
44
|
+
[project.scripts]
|
|
45
|
+
verilator = "verilator:_verilator_cli"
|
|
46
|
+
|
|
47
|
+
[tool.cibuildwheel]
|
|
48
|
+
# Run pytest to ensure that the package was correctly built
|
|
49
|
+
test-command = "pytest {project}/tests"
|
|
50
|
+
test-requires = "pytest"
|
|
51
|
+
|
|
52
|
+
# 64 bit builds
|
|
53
|
+
archs = ["auto64"]
|
|
54
|
+
|
|
55
|
+
build = ["cp312-*", "cp313-*"]
|
|
56
|
+
# Don't build arm. Use only > cp39, no PyPy. Not using musl anywhere so no musl (it works though)
|
|
57
|
+
skip = ["*-win_arm64"]
|
|
58
|
+
|
|
59
|
+
# manylinux builds
|
|
60
|
+
[tool.cibuildwheel.linux]
|
|
61
|
+
before-all = [
|
|
62
|
+
"yum install -y flex",
|
|
63
|
+
"yum install -y bison",
|
|
64
|
+
"yum install -y ccache",
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
# musllinux builds
|
|
68
|
+
[[tool.cibuildwheel.overrides]]
|
|
69
|
+
select = "*-musllinux*"
|
|
70
|
+
before-all = [
|
|
71
|
+
"apk add flex",
|
|
72
|
+
"apk add flex-dev",
|
|
73
|
+
"apk add bison",
|
|
74
|
+
"apk add ccache",
|
|
75
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pip install --no-build-isolation -Cbuild-dir=build --config-settings=editable.rebuild=true -v -e .
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pip install --no-build-isolation -Cbuild-dir=build --config-settings=editable.rebuild=true -v -e .
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pip install --no-build-isolation -Cbuild-dir=build -v .
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pip install --no-build-isolation -Cbuild-dir=build -v .
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Verilator wrapper.
|
|
3
|
+
|
|
4
|
+
Running verilator typically requires having VERILATOR_ROOT set in the environment.
|
|
5
|
+
VERILATOR_ROOT is also used by find_package in CMake.
|
|
6
|
+
|
|
7
|
+
When importing or running this package, this will automatically
|
|
8
|
+
set VERILATOR_ROOT in the environment before running verilator.
|
|
9
|
+
|
|
10
|
+
When using this with scikit-build-core, scikit-build core will add the
|
|
11
|
+
site-packages directory to CMAKE_PREFIX_PATH, so find_package(verilator)
|
|
12
|
+
should work without any extra hints.
|
|
13
|
+
|
|
14
|
+
When using just CMake, you may need to set VERILATOR_ROOT env variable,
|
|
15
|
+
manually or set CMAKE_PREFIX_PATH.
|
|
16
|
+
|
|
17
|
+
run this python command to get verilator_root for convenience
|
|
18
|
+
python -c "import verilator;print(verilator.verilator_root())"
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
# Use same version number as the checked out verilator version.
|
|
22
|
+
__version__ = "5.30.0"
|
|
23
|
+
|
|
24
|
+
import sys
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
import subprocess
|
|
27
|
+
import os
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def verilator_root() -> Path:
|
|
31
|
+
"""
|
|
32
|
+
Get the path to verilator_root.
|
|
33
|
+
This will typically be at site-packages/verilator
|
|
34
|
+
"""
|
|
35
|
+
# Verilator is installed in the same directory as this package.
|
|
36
|
+
return Path(__file__).parent
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def verilator_bin() -> Path:
|
|
40
|
+
"""
|
|
41
|
+
Get the path to verilator_bin
|
|
42
|
+
This will typically be at site-packages/verilator/bin
|
|
43
|
+
"""
|
|
44
|
+
if sys.platform == "win32":
|
|
45
|
+
return verilator_root() / "bin/verilator_bin.exe"
|
|
46
|
+
else:
|
|
47
|
+
return verilator_root() / "bin/verilator"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def verilator(args: list[str], capture_output: bool = False):
|
|
51
|
+
"""
|
|
52
|
+
Run verilator with the given args.
|
|
53
|
+
|
|
54
|
+
Returns the return code of
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
# Set VERILATOR_ROOT in the environment. Verilator usually requires this.
|
|
58
|
+
os.environ["VERILATOR_ROOT"] = str(verilator_root())
|
|
59
|
+
|
|
60
|
+
# Prepend the verilator_exe path to the verilator args.
|
|
61
|
+
command_args = [verilator_bin()] + args
|
|
62
|
+
|
|
63
|
+
# Run using subprocess.
|
|
64
|
+
return subprocess.run(command_args, capture_output=capture_output, check=True)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _verilator_cli() -> int:
|
|
68
|
+
"""
|
|
69
|
+
Run verilator using command line arguments.
|
|
70
|
+
Used by __main__
|
|
71
|
+
|
|
72
|
+
Otherwise it's probably best to use verilator(sys.argv[1:])
|
|
73
|
+
instead of calling this function.
|
|
74
|
+
"""
|
|
75
|
+
result = verilator(sys.argv[1:])
|
|
76
|
+
exit(result.returncode)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
__all__ = [
|
|
80
|
+
"verilator",
|
|
81
|
+
"verilator_root",
|
|
82
|
+
"verilator_bin",
|
|
83
|
+
]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Run the verilator_cli command when running this package as a module.
|
|
3
|
+
|
|
4
|
+
python -m verilator
|
|
5
|
+
|
|
6
|
+
Alternatively, this package will install scripts in the python environment under bin or Scripts
|
|
7
|
+
This directory is on the path so you can just run "verilator" on the command line.
|
|
8
|
+
|
|
9
|
+
I'm not sure what happens if verilator is already on the path elsewhere...
|
|
10
|
+
|
|
11
|
+
Either option is available for use.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from . import _verilator_cli
|
|
15
|
+
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
exit(_verilator_cli())
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Test if the package works.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import verilator
|
|
6
|
+
import subprocess
|
|
7
|
+
from packaging.version import Version
|
|
8
|
+
import site
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _parse_version_stdout(stdout: bytes):
|
|
13
|
+
"""Parse the version from stdout. Used to test if verilator works."""
|
|
14
|
+
return Version(stdout.decode().strip().strip("rev "))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_verilator():
|
|
18
|
+
""""""
|
|
19
|
+
# Print the version
|
|
20
|
+
result = verilator.verilator(["--version"], capture_output=True)
|
|
21
|
+
|
|
22
|
+
# Parse the result
|
|
23
|
+
v = _parse_version_stdout(result.stdout)
|
|
24
|
+
|
|
25
|
+
# Make sure the version run by verilator matches
|
|
26
|
+
assert v == Version(verilator.__version__)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_verilator_cli():
|
|
30
|
+
""""""
|
|
31
|
+
# Run subprocess instead. Print the version.
|
|
32
|
+
result = subprocess.run(["verilator", "--version"], capture_output=True, check=True)
|
|
33
|
+
|
|
34
|
+
# Parse the result
|
|
35
|
+
v = _parse_version_stdout(result.stdout)
|
|
36
|
+
|
|
37
|
+
# Make sure the version run by verilator matches
|
|
38
|
+
assert v == Version(verilator.__version__)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_verilator_root():
|
|
42
|
+
""""""
|
|
43
|
+
# Check the root.
|
|
44
|
+
verilator_root = verilator.verilator_root()
|
|
45
|
+
|
|
46
|
+
# We expect this package to be installed in site-packages.
|
|
47
|
+
assert verilator_root.parent in [Path(p) for p in site.getsitepackages()]
|
|
48
|
+
|
|
49
|
+
# Check for expected files.
|
|
50
|
+
assert verilator_root.exists()
|
|
51
|
+
assert verilator.verilator_bin().exists()
|
|
52
|
+
assert Path(verilator_root / "verilator-config.cmake").exists()
|