hdl-parser 0.6.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 (59) hide show
  1. hdl_parser-0.6.0/LICENSE +21 -0
  2. hdl_parser-0.6.0/PKG-INFO +74 -0
  3. hdl_parser-0.6.0/README.md +51 -0
  4. hdl_parser-0.6.0/pyproject.toml +153 -0
  5. hdl_parser-0.6.0/src/hdl_parser/Templates/__init__.py +23 -0
  6. hdl_parser-0.6.0/src/hdl_parser/Templates/instance_template +10 -0
  7. hdl_parser-0.6.0/src/hdl_parser/Templates/instance_with_param_template +19 -0
  8. hdl_parser-0.6.0/src/hdl_parser/__init__.py +46 -0
  9. hdl_parser-0.6.0/src/hdl_parser/_datamodel.py +72 -0
  10. hdl_parser-0.6.0/src/hdl_parser/_gen_templates.py +94 -0
  11. hdl_parser-0.6.0/src/hdl_parser/_sv/__init__.py +21 -0
  12. hdl_parser-0.6.0/src/hdl_parser/_sv/lexer.py +478 -0
  13. hdl_parser-0.6.0/src/hdl_parser/_sv/parser.py +258 -0
  14. hdl_parser-0.6.0/src/hdl_parser/_sv/token.py +39 -0
  15. hdl_parser-0.6.0/src/hdl_parser/_vhdl/__init__.py +21 -0
  16. hdl_parser-0.6.0/src/hdl_parser/_vhdl/lexer.py +260 -0
  17. hdl_parser-0.6.0/src/hdl_parser/_vhdl/parser.py +168 -0
  18. hdl_parser-0.6.0/src/hdl_parser/_vhdl/token.py +33 -0
  19. hdl_parser-0.6.0/src/hdl_parser/cli.py +192 -0
  20. hdl_parser-0.6.0/src/hdl_parser/datamodel.py +139 -0
  21. hdl_parser-0.6.0/src/hdl_parser/filelistparser.py +103 -0
  22. hdl_parser-0.6.0/src/hdl_parser/parser.py +95 -0
  23. hdl_parser-0.6.0/tests/__init__.py +24 -0
  24. hdl_parser-0.6.0/tests/conftest.py +58 -0
  25. hdl_parser-0.6.0/tests/refdata/tests.test_cli/test_filelist/info/output.txt +144 -0
  26. hdl_parser-0.6.0/tests/refdata/tests.test_cli/test_filelist/json/output.txt +569 -0
  27. hdl_parser-0.6.0/tests/refdata/tests.test_cli/test_gen_sv_instance/adder.sv/output.txt +12 -0
  28. hdl_parser-0.6.0/tests/refdata/tests.test_cli/test_gen_sv_instance/bcd_adder.sv/output.txt +9 -0
  29. hdl_parser-0.6.0/tests/refdata/tests.test_cli/test_gen_sv_instance/param_module.sv/output.txt +22 -0
  30. hdl_parser-0.6.0/tests/refdata/tests.test_cli/test_info/adder.sv-/output.md +24 -0
  31. hdl_parser-0.6.0/tests/refdata/tests.test_cli/test_info/adder.sv---level=4,-s/output.md +30 -0
  32. hdl_parser-0.6.0/tests/refdata/tests.test_cli/test_info/bcd_adder.sv-/output.md +22 -0
  33. hdl_parser-0.6.0/tests/refdata/tests.test_cli/test_info/bcd_adder.sv---level=4,-s/output.md +32 -0
  34. hdl_parser-0.6.0/tests/refdata/tests.test_cli/test_info/param_module.sv-/output.md +46 -0
  35. hdl_parser-0.6.0/tests/refdata/tests.test_cli/test_info/param_module.sv---level=4,-s/output.md +57 -0
  36. hdl_parser-0.6.0/tests/refdata/tests.test_cli/test_json/adder.sv/output.json +116 -0
  37. hdl_parser-0.6.0/tests/refdata/tests.test_cli/test_json/bcd_adder.sv/output.json +64 -0
  38. hdl_parser-0.6.0/tests/refdata/tests.test_cli/test_json/param_module.sv/output.json +169 -0
  39. hdl_parser-0.6.0/tests/refdata/tests.test_cli/test_multiple/info/output.txt +92 -0
  40. hdl_parser-0.6.0/tests/refdata/tests.test_cli/test_multiple/json/output.txt +349 -0
  41. hdl_parser-0.6.0/tests/refdata/tests.test_parser/test_examples/adder.sv/overview.json +116 -0
  42. hdl_parser-0.6.0/tests/refdata/tests.test_parser/test_examples/bcd_adder.sv/overview.json +64 -0
  43. hdl_parser-0.6.0/tests/refdata/tests.test_parser/test_examples/dimensions.vhd/overview.json +55 -0
  44. hdl_parser-0.6.0/tests/refdata/tests.test_parser/test_examples/encoder_using_case.sv/overview.json +36 -0
  45. hdl_parser-0.6.0/tests/refdata/tests.test_parser/test_examples/example_and.vhd/overview.json +25 -0
  46. hdl_parser-0.6.0/tests/refdata/tests.test_parser/test_examples/ifdef-elif-example.sv/overview.json +100 -0
  47. hdl_parser-0.6.0/tests/refdata/tests.test_parser/test_examples/ifdef-example.sv/overview.json +100 -0
  48. hdl_parser-0.6.0/tests/refdata/tests.test_parser/test_examples/instances_example.sv/overview.json +331 -0
  49. hdl_parser-0.6.0/tests/refdata/tests.test_parser/test_examples/jarbitraryCounter.sv/overview.json +24 -0
  50. hdl_parser-0.6.0/tests/refdata/tests.test_parser/test_examples/multi_unpacked_ports.sv/overview.json +139 -0
  51. hdl_parser-0.6.0/tests/refdata/tests.test_parser/test_examples/packed_unpacked.sv/overview.json +58 -0
  52. hdl_parser-0.6.0/tests/refdata/tests.test_parser/test_examples/param_defaults.sv/overview.json +137 -0
  53. hdl_parser-0.6.0/tests/refdata/tests.test_parser/test_examples/param_module.sv/overview.json +169 -0
  54. hdl_parser-0.6.0/tests/refdata/tests.test_parser/test_examples/top_module.vhd/overview.json +77 -0
  55. hdl_parser-0.6.0/tests/refdata/tests.test_parser/test_examples/uart_tx.vhd/overview.json +93 -0
  56. hdl_parser-0.6.0/tests/refdata/tests.test_parser/test_examples/up_down_counter.sv/overview.json +43 -0
  57. hdl_parser-0.6.0/tests/test_cli.py +122 -0
  58. hdl_parser-0.6.0/tests/test_filelistparser.py +57 -0
  59. hdl_parser-0.6.0/tests/test_parser.py +85 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ericsmacedo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,74 @@
1
+ Metadata-Version: 2.1
2
+ Name: hdl-parser
3
+ Version: 0.6.0
4
+ Summary: Easy-To-Use SystemVerilog Parser
5
+ Keywords: SystemVerilog,Verilog,Parser
6
+ Author-Email: Eric Macedo <ericsmacedo@gmail.com>, Daniel Jakschik <iccode17@gmail.com>
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Classifier: Operating System :: OS Independent
13
+ Project-URL: Homepage, https://github.com/ericsmacedo/hdl-parser
14
+ Project-URL: Documentation, https://hdl-parser.readthedocs.io/en/stable/
15
+ Project-URL: Bug Tracker, https://github.com/ericsmacedo/hdl-parser/issues
16
+ Requires-Python: <4.0,>=3.10.0
17
+ Requires-Dist: click>=8.2.1
18
+ Requires-Dist: pygments>=2.19.1
19
+ Requires-Dist: jinja2>=3.1.6
20
+ Requires-Dist: pydantic>=2.11.5
21
+ Requires-Dist: rich>=14.0.0
22
+ Description-Content-Type: text/markdown
23
+
24
+ [![PyPI Version](https://badge.fury.io/py/hdl-parser.svg)](https://badge.fury.io/py/hdl-parser)
25
+ [![Python Build](https://github.com/ericsmacedo/hdl-parser/actions/workflows/main.yml/badge.svg)](https://github.com/ericsmacedo/hdl-parser/actions/workflows/main.yml)
26
+ [![Documentation](https://readthedocs.org/projects/hdl-parser/badge/?version=stable)](https://hdl-parser.readthedocs.io/en/stable/)
27
+ [![Coverage Status](https://coveralls.io/repos/github/ericsmacedo/hdl-parser/badge.svg?branch=main)](https://coveralls.io/github/ericsmacedo/hdl-parser?branch=main)
28
+ [![python-versions](https://img.shields.io/pypi/pyversions/hdl-parser.svg)](https://pypi.python.org/pypi/hdl-parser)
29
+ [![semantic-versioning](https://img.shields.io/badge/semver-2.0.0-green)](https://semver.org/)
30
+
31
+ [![Downloads](https://img.shields.io/pypi/dm/hdl-parser.svg?label=pypi%20downloads)](https://pypi.python.org/pypi/hdl-parser)
32
+ [![Contributors](https://img.shields.io/github/contributors/ericsmacedo/hdl-parser.svg)](https://github.com/ericsmacedo/hdl-parser/graphs/contributors/)
33
+ [![PRs welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)
34
+ [![Issues](https://img.shields.io/github/issues/ericsmacedo/hdl-parser)](https://github.com/ericsmacedo/hdl-parser/issues)
35
+ [![PRs open](https://img.shields.io/github/issues-pr/ericsmacedo/hdl-parser.svg)](https://github.com/ericsmacedo/hdl-parser/pulls)
36
+ [![PRs done](https://img.shields.io/github/issues-pr-closed/ericsmacedo/hdl-parser.svg)](https://github.com/ericsmacedo/hdl-parser/pulls?q=is%3Apr+is%3Aclosed)
37
+
38
+
39
+ # Easy-To-Use SystemVerilog Parser
40
+
41
+ * [Documentation](https://hdl-parser.readthedocs.io/en/stable/)
42
+ * [PyPI](https://pypi.org/project/hdl-parser/)
43
+ * [Sources](https://github.com/ericsmacedo/hdl-parser)
44
+ * [Issues](https://github.com/ericsmacedo/hdl-parser/issues)
45
+
46
+ ## Features
47
+
48
+ * Extract Port Lists
49
+ * Extract Parameters
50
+ * Extract Submodule Instances and their connections
51
+ * `ifdef` support
52
+ * Standards: `IEEE 1800-2009 SystemVerilog`
53
+
54
+ ## Limitations
55
+
56
+ * **No Syntax Checks** - Source Code files must be syntactically correct
57
+ * **No Full Parser** - This parser intends to be simple and just extract some information from the source code. **Fast and Simple.**
58
+
59
+ ## Installation
60
+
61
+ Installing it is pretty easy:
62
+
63
+ ```bash
64
+ pip install hdl-parser
65
+ ```
66
+
67
+ ## Authors
68
+
69
+ * [Eric Macedo](mailto:ericsmacedo@gmail.com)
70
+ * [Daniel Jakschik](mailto:iccode17@gmail.com)
71
+
72
+ ## Usage
73
+
74
+ See [Usage Documentation](https://hdl-parser.readthedocs.io/en/stable/usage/)
@@ -0,0 +1,51 @@
1
+ [![PyPI Version](https://badge.fury.io/py/hdl-parser.svg)](https://badge.fury.io/py/hdl-parser)
2
+ [![Python Build](https://github.com/ericsmacedo/hdl-parser/actions/workflows/main.yml/badge.svg)](https://github.com/ericsmacedo/hdl-parser/actions/workflows/main.yml)
3
+ [![Documentation](https://readthedocs.org/projects/hdl-parser/badge/?version=stable)](https://hdl-parser.readthedocs.io/en/stable/)
4
+ [![Coverage Status](https://coveralls.io/repos/github/ericsmacedo/hdl-parser/badge.svg?branch=main)](https://coveralls.io/github/ericsmacedo/hdl-parser?branch=main)
5
+ [![python-versions](https://img.shields.io/pypi/pyversions/hdl-parser.svg)](https://pypi.python.org/pypi/hdl-parser)
6
+ [![semantic-versioning](https://img.shields.io/badge/semver-2.0.0-green)](https://semver.org/)
7
+
8
+ [![Downloads](https://img.shields.io/pypi/dm/hdl-parser.svg?label=pypi%20downloads)](https://pypi.python.org/pypi/hdl-parser)
9
+ [![Contributors](https://img.shields.io/github/contributors/ericsmacedo/hdl-parser.svg)](https://github.com/ericsmacedo/hdl-parser/graphs/contributors/)
10
+ [![PRs welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)
11
+ [![Issues](https://img.shields.io/github/issues/ericsmacedo/hdl-parser)](https://github.com/ericsmacedo/hdl-parser/issues)
12
+ [![PRs open](https://img.shields.io/github/issues-pr/ericsmacedo/hdl-parser.svg)](https://github.com/ericsmacedo/hdl-parser/pulls)
13
+ [![PRs done](https://img.shields.io/github/issues-pr-closed/ericsmacedo/hdl-parser.svg)](https://github.com/ericsmacedo/hdl-parser/pulls?q=is%3Apr+is%3Aclosed)
14
+
15
+
16
+ # Easy-To-Use SystemVerilog Parser
17
+
18
+ * [Documentation](https://hdl-parser.readthedocs.io/en/stable/)
19
+ * [PyPI](https://pypi.org/project/hdl-parser/)
20
+ * [Sources](https://github.com/ericsmacedo/hdl-parser)
21
+ * [Issues](https://github.com/ericsmacedo/hdl-parser/issues)
22
+
23
+ ## Features
24
+
25
+ * Extract Port Lists
26
+ * Extract Parameters
27
+ * Extract Submodule Instances and their connections
28
+ * `ifdef` support
29
+ * Standards: `IEEE 1800-2009 SystemVerilog`
30
+
31
+ ## Limitations
32
+
33
+ * **No Syntax Checks** - Source Code files must be syntactically correct
34
+ * **No Full Parser** - This parser intends to be simple and just extract some information from the source code. **Fast and Simple.**
35
+
36
+ ## Installation
37
+
38
+ Installing it is pretty easy:
39
+
40
+ ```bash
41
+ pip install hdl-parser
42
+ ```
43
+
44
+ ## Authors
45
+
46
+ * [Eric Macedo](mailto:ericsmacedo@gmail.com)
47
+ * [Daniel Jakschik](mailto:iccode17@gmail.com)
48
+
49
+ ## Usage
50
+
51
+ See [Usage Documentation](https://hdl-parser.readthedocs.io/en/stable/usage/)
@@ -0,0 +1,153 @@
1
+ [project]
2
+ name = "hdl-parser"
3
+ dynamic = []
4
+ description = "Easy-To-Use SystemVerilog Parser"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Eric Macedo", email = "ericsmacedo@gmail.com" },
8
+ { name = "Daniel Jakschik", email = "iccode17@gmail.com" },
9
+ ]
10
+ classifiers = [
11
+ "Programming Language :: Python :: 3",
12
+ "Programming Language :: Python :: 3.10",
13
+ "Programming Language :: Python :: 3.11",
14
+ "Programming Language :: Python :: 3.12",
15
+ "Programming Language :: Python :: 3.13",
16
+ "Operating System :: OS Independent",
17
+ ]
18
+ requires-python = ">=3.10.0,<4.0"
19
+ dependencies = [
20
+ "click>=8.2.1",
21
+ "pygments>=2.19.1",
22
+ "jinja2>=3.1.6",
23
+ "pydantic>=2.11.5",
24
+ "rich>=14.0.0",
25
+ ]
26
+ keywords = [
27
+ "SystemVerilog",
28
+ "Verilog",
29
+ "Parser",
30
+ ]
31
+ version = "0.6.0"
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/ericsmacedo/hdl-parser"
35
+ Documentation = "https://hdl-parser.readthedocs.io/en/stable/"
36
+ "Bug Tracker" = "https://github.com/ericsmacedo/hdl-parser/issues"
37
+
38
+ [project.scripts]
39
+ hdl-parser = "hdl_parser.cli:cli"
40
+
41
+ [dependency-groups]
42
+ dev = [
43
+ "contextlib-chdir>=1.0.2",
44
+ "coveralls>=3.3.1",
45
+ "mkdocs-click>=0.8.1",
46
+ "mkdocs-include-markdown-plugin>=6.0.5",
47
+ "mkdocs-literate-nav>=0.6.1",
48
+ "mkdocs-material>=9.5.18",
49
+ "mkdocstrings-python>=1.9.2",
50
+ "mypy>=1.9.0",
51
+ "pre-commit>=4.1.0",
52
+ "pytest-cov>=5.0.0",
53
+ "ruff>=0.11.2",
54
+ "test2ref>=0.4.2",
55
+ ]
56
+
57
+ [build-system]
58
+ requires = [
59
+ "pdm-backend",
60
+ ]
61
+ build-backend = "pdm.backend"
62
+
63
+ [tool.pdm.build]
64
+ includes = [
65
+ "src/hdl_parser",
66
+ ]
67
+
68
+ [tool.pdm.version]
69
+ source = "scm"
70
+ fallback_version = "0.0.0"
71
+
72
+ [tool.ruff]
73
+ line-length = 120
74
+ fix = true
75
+ target-version = "py310"
76
+
77
+ [tool.ruff.lint]
78
+ select = [
79
+ "I",
80
+ "F",
81
+ "E",
82
+ "W",
83
+ "D",
84
+ "N",
85
+ "YTT",
86
+ "B",
87
+ "Q",
88
+ "T10",
89
+ "INT",
90
+ "PL",
91
+ "PIE",
92
+ "PYI",
93
+ "TID",
94
+ "ISC",
95
+ "TC",
96
+ "C",
97
+ "C4",
98
+ "PGH",
99
+ "RUF",
100
+ "S102",
101
+ "NPY002",
102
+ "PERF",
103
+ "FLY",
104
+ "G",
105
+ "UP",
106
+ "ARG",
107
+ "PTH",
108
+ "RET",
109
+ "RSE",
110
+ ]
111
+ ignore = [
112
+ "RUF012",
113
+ "G004",
114
+ "D107",
115
+ "D105",
116
+ ]
117
+
118
+ [tool.ruff.lint.per-file-ignores]
119
+ "tests/*" = [
120
+ "PLR2004",
121
+ "ARG001",
122
+ "S101",
123
+ "PTH123",
124
+ ]
125
+
126
+ [tool.ruff.lint.pydocstyle]
127
+ convention = "google"
128
+
129
+ [tool.pytest.ini_options]
130
+ addopts = " --cov src/hdl_parser\n --cov-report term\n --cov-report html\n --doctest-glob=docs/*\n --doctest-modules\n --ignore-glob=tests/testdata/*\n --log-level=INFO\n --junitxml=report.xml\n"
131
+ filterwarnings = [
132
+ "error",
133
+ ]
134
+
135
+ [tool.coverage.run]
136
+ omit = [
137
+ "src/hdl_parser/Templates/*",
138
+ ]
139
+
140
+ [tool.coverage.report]
141
+ exclude_lines = [
142
+ "return NotImplemented",
143
+ "raise NotImplementedError()",
144
+ "pragma: no cover",
145
+ "assert False",
146
+ ]
147
+
148
+ [tool.mypy]
149
+ disable_error_code = "misc"
150
+ ignore_missing_imports = true
151
+ overrides = [
152
+ { module = "tests.*", allow_untyped_defs = true },
153
+ ]
@@ -0,0 +1,23 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2025 ericsmacedo
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ """Templates."""
@@ -0,0 +1,10 @@
1
+ {{ module_name }} u_{{ module_name }} (
2
+ {%- for index in range(port_list|length) %}
3
+ {%- set port_name = port_list[index] %}
4
+ {%- if loop.last %}
5
+ .{{ port_name }} ({{ port_name }})
6
+ {%- else %}
7
+ .{{ port_name }} ({{ port_name }}),
8
+ {%- endif %}
9
+ {%- endfor %}
10
+ );
@@ -0,0 +1,19 @@
1
+ {{ module_name }} #(
2
+ {%- for index in range(param_list|length) %}
3
+ {%- set param_name = param_list[index] %}
4
+ {%- if loop.last %}
5
+ .{{ param_name }} ({{ param_name }})
6
+ {%- else %}
7
+ .{{ param_name }} ({{ param_name }}),
8
+ {%- endif %}
9
+ {%- endfor %}
10
+ ) u_{{ module_name }} (
11
+ {%- for index in range(port_list|length) %}
12
+ {%- set port_name = port_list[index] %}
13
+ {%- if loop.last %}
14
+ .{{ port_name }} ({{ port_name }})
15
+ {%- else %}
16
+ .{{ port_name }} ({{ port_name }}),
17
+ {%- endif %}
18
+ {%- endfor %}
19
+ );
@@ -0,0 +1,46 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2025 ericsmacedo
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ """Easy-To-Use SystemVerilog Parser.
24
+
25
+ Usage is simple. Parse your input with one of these methods:
26
+
27
+ * [hdl_parser.parse_file][]
28
+ * [hdl_parser.parse_text][]
29
+
30
+ You receive a [hdl_parser.File][] object holding all information.
31
+ """
32
+
33
+ from .datamodel import File, Module, ModuleInstance, Param, Port
34
+ from .filelistparser import parse_filelist
35
+ from .parser import parse_file, parse_text
36
+
37
+ __all__ = [
38
+ "File",
39
+ "Module",
40
+ "ModuleInstance",
41
+ "Param",
42
+ "Port",
43
+ "parse_file",
44
+ "parse_filelist",
45
+ "parse_text",
46
+ ]
@@ -0,0 +1,72 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2025 ericsmacedo
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ import pydantic as pyd
24
+
25
+
26
+ class _BaseModel(pyd.BaseModel):
27
+ model_config = pyd.ConfigDict(extra="forbid")
28
+
29
+
30
+ class ConDecl(_BaseModel):
31
+ port: str = ""
32
+ con: str = ""
33
+ comment: list[str] | None = None
34
+ ifdefs: list[str] | None = None
35
+
36
+
37
+ class InstDecl(_BaseModel):
38
+ name: str | None = None
39
+ module: str | None = None
40
+ connections: list[ConDecl] | None = None
41
+ ifdefs: list[str] | None = None
42
+
43
+
44
+ class PortDecl(_BaseModel):
45
+ direction: str | None = None
46
+ ptype: str | None = None
47
+ dtype: str | None = None
48
+ name: list[str] | None = None
49
+ dim: str | None = None
50
+ dim_unpacked: str | None = None
51
+ comment: list[str] | None = None
52
+ ifdefs: list[str] | None = None
53
+ default: str = ""
54
+
55
+
56
+ class ParamDecl(_BaseModel):
57
+ ptype: str | None = None
58
+ dtype: str | None = None
59
+ name: list[str] | None = None
60
+ dim: str | None = None
61
+ dim_unpacked: str | None = None
62
+ comment: list[str] | None = None
63
+ ifdefs: list[str] | None = None
64
+ default: str = ""
65
+
66
+
67
+ class Module(_BaseModel):
68
+ name: str = ""
69
+ port_decl: list[PortDecl] = []
70
+ param_decl: list[ParamDecl] = []
71
+ inst_decl: list[InstDecl] = []
72
+ ifdefs: list[str] = []
@@ -0,0 +1,94 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2025 ericsmacedo
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ from importlib.resources import files
24
+
25
+ from jinja2 import Environment, FileSystemLoader
26
+ from rich.table import Table, box
27
+
28
+ from .datamodel import Module
29
+
30
+ template_path = files("hdl_parser.Templates")
31
+
32
+
33
+ def gen_instance(mod):
34
+ port_lst = [port.name for port in mod.ports]
35
+ param_lst = [param.name for param in mod.params]
36
+
37
+ environment = Environment(loader=FileSystemLoader(template_path))
38
+
39
+ if param_lst:
40
+ inst_temp = environment.get_template("instance_with_param_template")
41
+
42
+ instance_file = inst_temp.render(module_name=mod.name, param_list=param_lst, port_list=port_lst)
43
+ else:
44
+ inst_temp = environment.get_template("instance_template")
45
+
46
+ instance_file = inst_temp.render(module_name=mod.name, port_list=port_lst)
47
+
48
+ return instance_file
49
+
50
+
51
+ def gen_markdown_table(module: Module, width: int | None = None) -> tuple[Table | None, Table | None, Table | None]:
52
+ if module.params:
53
+ params = Table(box=box.MARKDOWN, width=width)
54
+
55
+ params.add_column("Name", no_wrap=True)
56
+ params.add_column("Dimension", no_wrap=True)
57
+ params.add_column("Default", no_wrap=True)
58
+ params.add_column("Functional Description")
59
+
60
+ for param in module.params:
61
+ param_name = f"{param.name} {param.dim_unpacked}" if param.dim_unpacked else param.name
62
+ dim = f"`{param.dim}`" if param.dim else ""
63
+ default = f"`{param.default}`" if param.default else ""
64
+ params.add_row(f"`{param_name}`", dim, default, "\n".join(param.comment or ()))
65
+ else:
66
+ params = None
67
+
68
+ if module.ports:
69
+ ports = Table(box=box.MARKDOWN, width=width)
70
+
71
+ ports.add_column("Name", no_wrap=True)
72
+ ports.add_column("Dimension", no_wrap=True)
73
+ ports.add_column("I/O", no_wrap=True)
74
+ ports.add_column("Functional Description")
75
+
76
+ for port in module.ports:
77
+ dim = port.dim or "1"
78
+ port_name = f"{port.name} {port.dim_unpacked}" if port.dim_unpacked else port.name
79
+ ports.add_row(f"`{port_name}`", f"`{dim}`", f"`{port.direction}`", "\n".join(port.comment or ()))
80
+ else:
81
+ ports = None
82
+
83
+ if module.insts:
84
+ insts = Table(box=box.MARKDOWN, width=width)
85
+
86
+ insts.add_column("Name", no_wrap=True)
87
+ insts.add_column("Module", no_wrap=True)
88
+
89
+ for inst in module.insts:
90
+ insts.add_row(f"`{inst.name}`", f"`{inst.module}`")
91
+ else:
92
+ insts = None
93
+
94
+ return params, ports, insts
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2025 ericsmacedo
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.