pysvlang 0.1.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.
Files changed (99) hide show
  1. pysvlang-0.1.0/Cargo.lock +282 -0
  2. pysvlang-0.1.0/Cargo.toml +28 -0
  3. pysvlang-0.1.0/PKG-INFO +102 -0
  4. pysvlang-0.1.0/README.md +82 -0
  5. pysvlang-0.1.0/crates/sv-lexer/Cargo.toml +12 -0
  6. pysvlang-0.1.0/crates/sv-lexer/examples/lexstat.rs +73 -0
  7. pysvlang-0.1.0/crates/sv-lexer/src/keywords.rs +478 -0
  8. pysvlang-0.1.0/crates/sv-lexer/src/lib.rs +491 -0
  9. pysvlang-0.1.0/crates/sv-netlist/Cargo.toml +15 -0
  10. pysvlang-0.1.0/crates/sv-netlist/README.md +42 -0
  11. pysvlang-0.1.0/crates/sv-netlist/src/builder.rs +827 -0
  12. pysvlang-0.1.0/crates/sv-netlist/src/drivers.rs +333 -0
  13. pysvlang-0.1.0/crates/sv-netlist/src/dump.rs +439 -0
  14. pysvlang-0.1.0/crates/sv-netlist/src/expr_lower.rs +1101 -0
  15. pysvlang-0.1.0/crates/sv-netlist/src/ir.rs +1407 -0
  16. pysvlang-0.1.0/crates/sv-netlist/src/lib.rs +114 -0
  17. pysvlang-0.1.0/crates/sv-netlist/src/loops_sub.rs +1190 -0
  18. pysvlang-0.1.0/crates/sv-netlist/src/lower.rs +2976 -0
  19. pysvlang-0.1.0/crates/sv-netlist/src/proc.rs +3007 -0
  20. pysvlang-0.1.0/crates/sv-netlist/tests/constructs_and_sva.rs +1333 -0
  21. pysvlang-0.1.0/crates/sv-netlist/tests/known_answers.rs +328 -0
  22. pysvlang-0.1.0/crates/sv-netlist/tests/sim/mod.rs +464 -0
  23. pysvlang-0.1.0/crates/sv-preprocessor/Cargo.toml +13 -0
  24. pysvlang-0.1.0/crates/sv-preprocessor/examples/ppdump.rs +40 -0
  25. pysvlang-0.1.0/crates/sv-preprocessor/src/lib.rs +1338 -0
  26. pysvlang-0.1.0/crates/sv-preprocessor/src/overlay.rs +83 -0
  27. pysvlang-0.1.0/crates/sv-semantic/Cargo.toml +14 -0
  28. pysvlang-0.1.0/crates/sv-semantic/src/bigint.rs +574 -0
  29. pysvlang-0.1.0/crates/sv-semantic/src/bind.rs +638 -0
  30. pysvlang-0.1.0/crates/sv-semantic/src/body.rs +1936 -0
  31. pysvlang-0.1.0/crates/sv-semantic/src/calls.rs +296 -0
  32. pysvlang-0.1.0/crates/sv-semantic/src/checks.rs +968 -0
  33. pysvlang-0.1.0/crates/sv-semantic/src/classes.rs +447 -0
  34. pysvlang-0.1.0/crates/sv-semantic/src/consteval.rs +577 -0
  35. pysvlang-0.1.0/crates/sv-semantic/src/elab.rs +2298 -0
  36. pysvlang-0.1.0/crates/sv-semantic/src/elab_ir.rs +1397 -0
  37. pysvlang-0.1.0/crates/sv-semantic/src/expr.rs +3792 -0
  38. pysvlang-0.1.0/crates/sv-semantic/src/expr_types.rs +204 -0
  39. pysvlang-0.1.0/crates/sv-semantic/src/fx.rs +61 -0
  40. pysvlang-0.1.0/crates/sv-semantic/src/hier.rs +170 -0
  41. pysvlang-0.1.0/crates/sv-semantic/src/iclass.rs +354 -0
  42. pysvlang-0.1.0/crates/sv-semantic/src/lib.rs +2557 -0
  43. pysvlang-0.1.0/crates/sv-semantic/src/library.rs +129 -0
  44. pysvlang-0.1.0/crates/sv-semantic/src/model.rs +412 -0
  45. pysvlang-0.1.0/crates/sv-semantic/src/names.rs +354 -0
  46. pysvlang-0.1.0/crates/sv-semantic/src/oracle.rs +581 -0
  47. pysvlang-0.1.0/crates/sv-semantic/src/order.rs +293 -0
  48. pysvlang-0.1.0/crates/sv-semantic/src/packed.rs +603 -0
  49. pysvlang-0.1.0/crates/sv-semantic/src/scopes.rs +771 -0
  50. pysvlang-0.1.0/crates/sv-semantic/src/sva.rs +661 -0
  51. pysvlang-0.1.0/crates/sv-semantic/src/sva_ir.rs +2323 -0
  52. pysvlang-0.1.0/crates/sv-semantic/src/typed.rs +846 -0
  53. pysvlang-0.1.0/crates/sv-semantic/src/types.rs +2261 -0
  54. pysvlang-0.1.0/crates/sv-semantic/src/udp.rs +489 -0
  55. pysvlang-0.1.0/crates/sv-semantic/tests/bind.rs +84 -0
  56. pysvlang-0.1.0/crates/sv-semantic/tests/calls.rs +233 -0
  57. pysvlang-0.1.0/crates/sv-semantic/tests/corpus.rs +180 -0
  58. pysvlang-0.1.0/crates/sv-semantic/tests/elab.rs +88 -0
  59. pysvlang-0.1.0/crates/sv-semantic/tests/frontend.rs +65 -0
  60. pysvlang-0.1.0/crates/sv-semantic/tests/library.rs +60 -0
  61. pysvlang-0.1.0/crates/sv-semantic/tests/model.rs +127 -0
  62. pysvlang-0.1.0/crates/sv-semantic/tests/rtl_elab_expr.rs +713 -0
  63. pysvlang-0.1.0/crates/sv-semantic/tests/scopes.rs +220 -0
  64. pysvlang-0.1.0/crates/sv-semantic/tests/sva.rs +193 -0
  65. pysvlang-0.1.0/crates/sv-source/Cargo.toml +10 -0
  66. pysvlang-0.1.0/crates/sv-source/src/lib.rs +827 -0
  67. pysvlang-0.1.0/crates/sv-source/src/owners.rs +257 -0
  68. pysvlang-0.1.0/crates/sv-syntax/Cargo.toml +14 -0
  69. pysvlang-0.1.0/crates/sv-syntax/examples/outline.rs +85 -0
  70. pysvlang-0.1.0/crates/sv-syntax/src/assertions.rs +570 -0
  71. pysvlang-0.1.0/crates/sv-syntax/src/blocks.rs +785 -0
  72. pysvlang-0.1.0/crates/sv-syntax/src/checks.rs +129 -0
  73. pysvlang-0.1.0/crates/sv-syntax/src/expr.rs +663 -0
  74. pysvlang-0.1.0/crates/sv-syntax/src/exprs.rs +120 -0
  75. pysvlang-0.1.0/crates/sv-syntax/src/grammar.rs +1536 -0
  76. pysvlang-0.1.0/crates/sv-syntax/src/kinds.rs +333 -0
  77. pysvlang-0.1.0/crates/sv-syntax/src/lib.rs +114 -0
  78. pysvlang-0.1.0/crates/sv-syntax/src/misc.rs +502 -0
  79. pysvlang-0.1.0/crates/sv-syntax/src/outline.rs +48 -0
  80. pysvlang-0.1.0/crates/sv-syntax/src/parser.rs +207 -0
  81. pysvlang-0.1.0/crates/sv-syntax/src/tree.rs +422 -0
  82. pysvlang-0.1.0/crates/sv-syntax/tests/parse.rs +522 -0
  83. pysvlang-0.1.0/crates/svlang/Cargo.toml +19 -0
  84. pysvlang-0.1.0/crates/svlang/README.md +57 -0
  85. pysvlang-0.1.0/crates/svlang/examples/custom_linter.rs +91 -0
  86. pysvlang-0.1.0/crates/svlang/examples/elab_hierarchy.rs +27 -0
  87. pysvlang-0.1.0/crates/svlang/examples/rtl_netlist.rs +63 -0
  88. pysvlang-0.1.0/crates/svlang/src/lib.rs +764 -0
  89. pysvlang-0.1.0/crates/svlang/tests/netlist_api.rs +275 -0
  90. pysvlang-0.1.0/crates/svlang/tests/sdk.rs +36 -0
  91. pysvlang-0.1.0/crates/svlang-py/Cargo.toml +25 -0
  92. pysvlang-0.1.0/crates/svlang-py/README.md +82 -0
  93. pysvlang-0.1.0/crates/svlang-py/build.rs +37 -0
  94. pysvlang-0.1.0/crates/svlang-py/src/lib.rs +743 -0
  95. pysvlang-0.1.0/crates/svlang-py/tests/test_pysvlang.py +152 -0
  96. pysvlang-0.1.0/pyproject.toml +35 -0
  97. pysvlang-0.1.0/python/pysvlang/__init__.py +48 -0
  98. pysvlang-0.1.0/python/pysvlang/_pysvlang.pyi +145 -0
  99. pysvlang-0.1.0/python/pysvlang/py.typed +0 -0
@@ -0,0 +1,282 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 3
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "1.1.5"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "dv-build"
16
+ version = "0.1.0"
17
+ dependencies = [
18
+ "svlang",
19
+ ]
20
+
21
+ [[package]]
22
+ name = "dv-filelist"
23
+ version = "0.1.0"
24
+ dependencies = [
25
+ "dv-model",
26
+ "sv-slang",
27
+ "svlang",
28
+ ]
29
+
30
+ [[package]]
31
+ name = "dv-lint"
32
+ version = "0.1.0"
33
+ dependencies = [
34
+ "dv-model",
35
+ "regex",
36
+ "svlang",
37
+ ]
38
+
39
+ [[package]]
40
+ name = "dv-lsp"
41
+ version = "0.1.0"
42
+ dependencies = [
43
+ "dv-lint",
44
+ "svlang",
45
+ ]
46
+
47
+ [[package]]
48
+ name = "dv-map"
49
+ version = "0.1.0"
50
+ dependencies = [
51
+ "dv-model",
52
+ "sv-slang",
53
+ "svlang",
54
+ ]
55
+
56
+ [[package]]
57
+ name = "dv-model"
58
+ version = "0.1.0"
59
+ dependencies = [
60
+ "sv-slang",
61
+ "svlang",
62
+ ]
63
+
64
+ [[package]]
65
+ name = "heck"
66
+ version = "0.5.0"
67
+ source = "registry+https://github.com/rust-lang/crates.io-index"
68
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
69
+
70
+ [[package]]
71
+ name = "libc"
72
+ version = "0.2.191"
73
+ source = "registry+https://github.com/rust-lang/crates.io-index"
74
+ checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
75
+
76
+ [[package]]
77
+ name = "memchr"
78
+ version = "2.8.3"
79
+ source = "registry+https://github.com/rust-lang/crates.io-index"
80
+ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
81
+
82
+ [[package]]
83
+ name = "once_cell"
84
+ version = "1.21.4"
85
+ source = "registry+https://github.com/rust-lang/crates.io-index"
86
+ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
87
+
88
+ [[package]]
89
+ name = "portable-atomic"
90
+ version = "1.15.0"
91
+ source = "registry+https://github.com/rust-lang/crates.io-index"
92
+ checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
93
+
94
+ [[package]]
95
+ name = "proc-macro2"
96
+ version = "1.0.107"
97
+ source = "registry+https://github.com/rust-lang/crates.io-index"
98
+ checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
99
+ dependencies = [
100
+ "unicode-ident",
101
+ ]
102
+
103
+ [[package]]
104
+ name = "pyo3"
105
+ version = "0.30.1"
106
+ source = "registry+https://github.com/rust-lang/crates.io-index"
107
+ checksum = "229ca13b8a15bb0d1487b81ab975bfcd97513416499a8312011b6036e42e0de4"
108
+ dependencies = [
109
+ "libc",
110
+ "once_cell",
111
+ "portable-atomic",
112
+ "pyo3-build-config",
113
+ "pyo3-ffi",
114
+ "pyo3-macros",
115
+ ]
116
+
117
+ [[package]]
118
+ name = "pyo3-build-config"
119
+ version = "0.30.1"
120
+ source = "registry+https://github.com/rust-lang/crates.io-index"
121
+ checksum = "70130e2b6dd1ee589a8788026a429561ca5c40fa7a2fa7914c2282eddae24700"
122
+ dependencies = [
123
+ "target-lexicon",
124
+ ]
125
+
126
+ [[package]]
127
+ name = "pyo3-ffi"
128
+ version = "0.30.1"
129
+ source = "registry+https://github.com/rust-lang/crates.io-index"
130
+ checksum = "5e7ff73c555c286d212d4ce7e5fbda845a973c4f61bd5f160f5f2c3c2a04d1c4"
131
+ dependencies = [
132
+ "libc",
133
+ "pyo3-build-config",
134
+ ]
135
+
136
+ [[package]]
137
+ name = "pyo3-macros"
138
+ version = "0.30.1"
139
+ source = "registry+https://github.com/rust-lang/crates.io-index"
140
+ checksum = "c46d2e5862c7bb8207e3b639f713dda3c499933444784154c11d013c5a691b60"
141
+ dependencies = [
142
+ "proc-macro2",
143
+ "pyo3-macros-backend",
144
+ "quote",
145
+ "syn",
146
+ ]
147
+
148
+ [[package]]
149
+ name = "pyo3-macros-backend"
150
+ version = "0.30.1"
151
+ source = "registry+https://github.com/rust-lang/crates.io-index"
152
+ checksum = "38b89f066f2ae72a2aef52d1537ca2fcd104440ebfadee06e97aa90738a25b9b"
153
+ dependencies = [
154
+ "heck",
155
+ "proc-macro2",
156
+ "quote",
157
+ "syn",
158
+ ]
159
+
160
+ [[package]]
161
+ name = "quote"
162
+ version = "1.0.47"
163
+ source = "registry+https://github.com/rust-lang/crates.io-index"
164
+ checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
165
+ dependencies = [
166
+ "proc-macro2",
167
+ ]
168
+
169
+ [[package]]
170
+ name = "regex"
171
+ version = "1.13.1"
172
+ source = "registry+https://github.com/rust-lang/crates.io-index"
173
+ checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d"
174
+ dependencies = [
175
+ "aho-corasick",
176
+ "memchr",
177
+ "regex-automata",
178
+ "regex-syntax",
179
+ ]
180
+
181
+ [[package]]
182
+ name = "regex-automata"
183
+ version = "0.4.18"
184
+ source = "registry+https://github.com/rust-lang/crates.io-index"
185
+ checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2"
186
+ dependencies = [
187
+ "aho-corasick",
188
+ "memchr",
189
+ "regex-syntax",
190
+ ]
191
+
192
+ [[package]]
193
+ name = "regex-syntax"
194
+ version = "0.8.11"
195
+ source = "registry+https://github.com/rust-lang/crates.io-index"
196
+ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
197
+
198
+ [[package]]
199
+ name = "sv-lexer"
200
+ version = "0.1.0"
201
+
202
+ [[package]]
203
+ name = "sv-netlist"
204
+ version = "0.1.0"
205
+ dependencies = [
206
+ "sv-semantic",
207
+ "sv-syntax",
208
+ ]
209
+
210
+ [[package]]
211
+ name = "sv-preprocessor"
212
+ version = "0.1.0"
213
+ dependencies = [
214
+ "sv-lexer",
215
+ ]
216
+
217
+ [[package]]
218
+ name = "sv-semantic"
219
+ version = "0.1.0"
220
+ dependencies = [
221
+ "sv-source",
222
+ "sv-syntax",
223
+ ]
224
+
225
+ [[package]]
226
+ name = "sv-slang"
227
+ version = "0.1.0"
228
+
229
+ [[package]]
230
+ name = "sv-source"
231
+ version = "0.1.0"
232
+
233
+ [[package]]
234
+ name = "sv-syntax"
235
+ version = "0.1.0"
236
+ dependencies = [
237
+ "sv-lexer",
238
+ "sv-preprocessor",
239
+ ]
240
+
241
+ [[package]]
242
+ name = "svlang"
243
+ version = "0.1.0"
244
+ dependencies = [
245
+ "sv-lexer",
246
+ "sv-netlist",
247
+ "sv-preprocessor",
248
+ "sv-semantic",
249
+ "sv-source",
250
+ "sv-syntax",
251
+ ]
252
+
253
+ [[package]]
254
+ name = "svlang-py"
255
+ version = "0.1.0"
256
+ dependencies = [
257
+ "pyo3",
258
+ "svlang",
259
+ ]
260
+
261
+ [[package]]
262
+ name = "syn"
263
+ version = "3.0.10"
264
+ source = "registry+https://github.com/rust-lang/crates.io-index"
265
+ checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
266
+ dependencies = [
267
+ "proc-macro2",
268
+ "quote",
269
+ "unicode-ident",
270
+ ]
271
+
272
+ [[package]]
273
+ name = "target-lexicon"
274
+ version = "0.13.6"
275
+ source = "registry+https://github.com/rust-lang/crates.io-index"
276
+ checksum = "8c447be3a2abfa84b2d91680c56600bd6b2873866de27b36ec911be705e291da"
277
+
278
+ [[package]]
279
+ name = "unicode-ident"
280
+ version = "1.0.27"
281
+ source = "registry+https://github.com/rust-lang/crates.io-index"
282
+ checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
@@ -0,0 +1,28 @@
1
+ # The Rust workspace: the native SystemVerilog/UVM front end and the DV tools.
2
+ # Crates live in crates/; see docs/architecture/rust.md. Tools depend on dv-model
3
+ # only; sv-slang is the raw binding to libuvmcheck_model (slang behind a C ABI)
4
+ # and is the one crate that changes when the front end does.
5
+ [workspace]
6
+ resolver = "2"
7
+ members = ["crates/*"]
8
+
9
+ [workspace.package]
10
+ version = "0.1.0"
11
+ edition = "2021"
12
+ license = "Apache-2.0"
13
+ rust-version = "1.82"
14
+ repository = "https://github.com/mayurkubavat/svlang"
15
+ keywords = ["systemverilog", "verilog", "eda", "parser", "hdl"]
16
+ categories = ["compilers", "parser-implementations", "development-tools"]
17
+
18
+ [profile.release]
19
+ debug = 1
20
+
21
+ # Release binaries people download (the Release workflow): no debug info,
22
+ # stripped, optimized across crates.
23
+ [profile.dist]
24
+ inherits = "release"
25
+ debug = 0
26
+ strip = true
27
+ lto = "thin"
28
+ codegen-units = 1
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: pysvlang
3
+ Version: 0.1.0
4
+ Classifier: Development Status :: 3 - Alpha
5
+ Classifier: Intended Audience :: Developers
6
+ Classifier: Programming Language :: Rust
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
9
+ Classifier: Topic :: Software Development :: Compilers
10
+ Requires-Dist: pytest>=7 ; extra == 'test'
11
+ Provides-Extra: test
12
+ Summary: Python bindings for svlang, a pure-Rust IEEE 1800-2023 SystemVerilog front end
13
+ Keywords: systemverilog,verilog,eda,parser,hdl,formal
14
+ Author: Mayur Kubavat
15
+ License-Expression: Apache-2.0
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
18
+ Project-URL: Repository, https://github.com/mayurkubavat/svlang
19
+
20
+ # pysvlang
21
+
22
+ Python bindings for [svlang](https://github.com/mayurkubavat/svlang), a
23
+ pure-Rust IEEE 1800-2023 SystemVerilog front end: filelists, preprocessor,
24
+ a lossless concrete syntax tree, elaboration, compiler checks and a
25
+ word-level RTL netlist.
26
+
27
+ The wheels are self-contained native extensions built with
28
+ [PyO3](https://pyo3.rs) and [maturin](https://www.maturin.rs). There is no
29
+ C++ build and nothing else to install; one abi3 wheel per platform works on
30
+ every Python from 3.9 on.
31
+
32
+ > Status: alpha. The API below is the first slice (parse, diagnostics,
33
+ > tree walking, hierarchy, netlist summary) and may change before 1.0.
34
+
35
+ ## Use
36
+
37
+ ```python
38
+ import pysvlang
39
+
40
+ comp = pysvlang.Compilation(
41
+ ["rtl/top.sv", "rtl/fifo.sv"],
42
+ include_dirs=["rtl/include"],
43
+ defines={"SYNTHESIS": None, "DEPTH": 16},
44
+ top=["top"],
45
+ params={"WIDTH": 32},
46
+ )
47
+ # Or simulator-style arguments, -f filelists included:
48
+ # comp = pysvlang.Compilation.from_args(["-f", "files.f", "-top", "top"])
49
+
50
+ for d in comp.diagnostics():
51
+ print(d) # rtl/top.sv:12:5: error: ...
52
+
53
+ for tree in comp.trees:
54
+ for mod in tree.root.find_all("ModuleDecl"):
55
+ print(mod.child("Name").bare_text, mod.location)
56
+
57
+ print("\n".join(comp.hierarchy()))
58
+
59
+ nl = comp.lower_netlist(top="top")
60
+ print(nl.top, len(nl.inputs), len(nl.states))
61
+ print(nl.dump())
62
+ ```
63
+
64
+ The syntax tree is lossless: `tree.file_text()` rebuilds the source
65
+ byte for byte, and every `Token` carries its `leading_trivia` (whitespace,
66
+ comments, directives). Node kinds are strings such as `"ModuleDecl"` or
67
+ `"ProceduralBlock"`; `pysvlang.SYNTAX_KINDS` and `pysvlang.TOKEN_KINDS` list
68
+ them all, and asking for a kind that does not exist raises `ValueError`.
69
+
70
+ `lower_netlist()` raises `pysvlang.LowerError` when the design has errors or
71
+ uses constructs outside the synthesizable/formal subset. The exception's
72
+ `diagnostics` list says why, and `unsupported` tells the two cases apart.
73
+
74
+ Parsing, checking and lowering release the GIL, so several compilations
75
+ can run in threads at once.
76
+
77
+ ## Build from source
78
+
79
+ Needs Rust 1.85 or later and Python 3.9 or later.
80
+
81
+ ```sh
82
+ cd crates/svlang-py
83
+ python -m venv .venv && . .venv/bin/activate
84
+ pip install maturin pytest
85
+ maturin develop --release
86
+ pytest tests
87
+ ```
88
+
89
+ `maturin build --release` writes a wheel to `target/wheels/`.
90
+
91
+ ## Releasing
92
+
93
+ The Python workflow builds and tests the wheels on every change. Pushing a
94
+ tag `pysvlang-vX.Y.Z`, where `X.Y.Z` is the workspace version in the root
95
+ `Cargo.toml`, also publishes the wheels and sdist to PyPI through trusted
96
+ publishing (repository `mayurkubavat/svlang`, workflow `python.yml`,
97
+ environment `pypi`).
98
+
99
+ ## License
100
+
101
+ Apache-2.0, like svlang.
102
+
@@ -0,0 +1,82 @@
1
+ # pysvlang
2
+
3
+ Python bindings for [svlang](https://github.com/mayurkubavat/svlang), a
4
+ pure-Rust IEEE 1800-2023 SystemVerilog front end: filelists, preprocessor,
5
+ a lossless concrete syntax tree, elaboration, compiler checks and a
6
+ word-level RTL netlist.
7
+
8
+ The wheels are self-contained native extensions built with
9
+ [PyO3](https://pyo3.rs) and [maturin](https://www.maturin.rs). There is no
10
+ C++ build and nothing else to install; one abi3 wheel per platform works on
11
+ every Python from 3.9 on.
12
+
13
+ > Status: alpha. The API below is the first slice (parse, diagnostics,
14
+ > tree walking, hierarchy, netlist summary) and may change before 1.0.
15
+
16
+ ## Use
17
+
18
+ ```python
19
+ import pysvlang
20
+
21
+ comp = pysvlang.Compilation(
22
+ ["rtl/top.sv", "rtl/fifo.sv"],
23
+ include_dirs=["rtl/include"],
24
+ defines={"SYNTHESIS": None, "DEPTH": 16},
25
+ top=["top"],
26
+ params={"WIDTH": 32},
27
+ )
28
+ # Or simulator-style arguments, -f filelists included:
29
+ # comp = pysvlang.Compilation.from_args(["-f", "files.f", "-top", "top"])
30
+
31
+ for d in comp.diagnostics():
32
+ print(d) # rtl/top.sv:12:5: error: ...
33
+
34
+ for tree in comp.trees:
35
+ for mod in tree.root.find_all("ModuleDecl"):
36
+ print(mod.child("Name").bare_text, mod.location)
37
+
38
+ print("\n".join(comp.hierarchy()))
39
+
40
+ nl = comp.lower_netlist(top="top")
41
+ print(nl.top, len(nl.inputs), len(nl.states))
42
+ print(nl.dump())
43
+ ```
44
+
45
+ The syntax tree is lossless: `tree.file_text()` rebuilds the source
46
+ byte for byte, and every `Token` carries its `leading_trivia` (whitespace,
47
+ comments, directives). Node kinds are strings such as `"ModuleDecl"` or
48
+ `"ProceduralBlock"`; `pysvlang.SYNTAX_KINDS` and `pysvlang.TOKEN_KINDS` list
49
+ them all, and asking for a kind that does not exist raises `ValueError`.
50
+
51
+ `lower_netlist()` raises `pysvlang.LowerError` when the design has errors or
52
+ uses constructs outside the synthesizable/formal subset. The exception's
53
+ `diagnostics` list says why, and `unsupported` tells the two cases apart.
54
+
55
+ Parsing, checking and lowering release the GIL, so several compilations
56
+ can run in threads at once.
57
+
58
+ ## Build from source
59
+
60
+ Needs Rust 1.85 or later and Python 3.9 or later.
61
+
62
+ ```sh
63
+ cd crates/svlang-py
64
+ python -m venv .venv && . .venv/bin/activate
65
+ pip install maturin pytest
66
+ maturin develop --release
67
+ pytest tests
68
+ ```
69
+
70
+ `maturin build --release` writes a wheel to `target/wheels/`.
71
+
72
+ ## Releasing
73
+
74
+ The Python workflow builds and tests the wheels on every change. Pushing a
75
+ tag `pysvlang-vX.Y.Z`, where `X.Y.Z` is the workspace version in the root
76
+ `Cargo.toml`, also publishes the wheels and sdist to PyPI through trusted
77
+ publishing (repository `mayurkubavat/svlang`, workflow `python.yml`,
78
+ environment `pypi`).
79
+
80
+ ## License
81
+
82
+ Apache-2.0, like svlang.
@@ -0,0 +1,12 @@
1
+ [package]
2
+ name = "sv-lexer"
3
+ description = "Lossless SystemVerilog lexer (IEEE 1800-2023): every byte of the input is in exactly one token"
4
+ version.workspace = true
5
+ edition.workspace = true
6
+ license.workspace = true
7
+ rust-version.workspace = true
8
+ repository.workspace = true
9
+ keywords.workspace = true
10
+ categories.workspace = true
11
+
12
+ [dependencies]
@@ -0,0 +1,73 @@
1
+ //! Lexes every .sv/.svh/.v/.vh file under the given paths and checks that
2
+ //! the tokens give the file back byte for byte.
3
+ //!
4
+ //! cargo run --release -p sv-lexer --example lexstat -- <dir-or-file>...
5
+ //!
6
+ //! Prints files, bytes, tokens, Unknown tokens (by file) and throughput;
7
+ //! exits 1 if any file does not round-trip.
8
+ use std::path::{Path, PathBuf};
9
+ use std::time::Instant;
10
+
11
+ fn collect(p: &Path, out: &mut Vec<PathBuf>) {
12
+ if p.is_dir() {
13
+ let mut entries: Vec<_> = std::fs::read_dir(p).into_iter().flatten().flatten().map(|e| e.path()).collect();
14
+ entries.sort();
15
+ for e in entries {
16
+ collect(&e, out);
17
+ }
18
+ } else if matches!(p.extension().and_then(|e| e.to_str()), Some("sv" | "svh" | "v" | "vh")) {
19
+ out.push(p.to_path_buf());
20
+ }
21
+ }
22
+
23
+ fn main() {
24
+ let mut files = Vec::new();
25
+ for a in std::env::args().skip(1) {
26
+ collect(Path::new(&a), &mut files);
27
+ }
28
+ let (mut bytes, mut tokens, mut unknown, mut not_utf8, mut broken) = (0usize, 0usize, 0usize, 0usize, 0usize);
29
+ let mut lex_time = 0f64;
30
+ let mut worst: Vec<(usize, String, String)> = Vec::new();
31
+ for f in &files {
32
+ let raw = std::fs::read(f).unwrap_or_default();
33
+ let src = match String::from_utf8(raw) {
34
+ Ok(s) => s,
35
+ Err(e) => {
36
+ not_utf8 += 1;
37
+ String::from_utf8_lossy(e.as_bytes()).into_owned()
38
+ }
39
+ };
40
+ let t = Instant::now();
41
+ let toks = sv_lexer::lex(&src);
42
+ lex_time += t.elapsed().as_secs_f64();
43
+ bytes += src.len();
44
+ tokens += toks.len();
45
+ if toks.iter().map(|t| t.text(&src)).collect::<String>() != src {
46
+ broken += 1;
47
+ eprintln!("NOT LOSSLESS: {}", f.display());
48
+ }
49
+ let unk: Vec<_> = toks.iter().filter(|t| t.kind == sv_lexer::Kind::Unknown).collect();
50
+ if !unk.is_empty() {
51
+ unknown += unk.len();
52
+ let first = unk[0].text(&src).chars().take(30).collect::<String>();
53
+ worst.push((unk.len(), f.display().to_string(), first));
54
+ }
55
+ }
56
+ worst.sort_by_key(|w| std::cmp::Reverse(w.0));
57
+ for (n, f, first) in worst.iter().take(15) {
58
+ println!(" {n:5} unknown {f} first: {first:?}");
59
+ }
60
+ println!(
61
+ "files={} bytes={} tokens={} unknown={} files_with_unknown={} not_utf8={} not_lossless={} lex={:.1}ms ({:.0} MB/s)",
62
+ files.len(),
63
+ bytes,
64
+ tokens,
65
+ unknown,
66
+ worst.len(),
67
+ not_utf8,
68
+ broken,
69
+ lex_time * 1e3,
70
+ bytes as f64 / 1e6 / lex_time.max(1e-9)
71
+ );
72
+ std::process::exit(if broken == 0 { 0 } else { 1 });
73
+ }