hdl-parser 0.6.0__py3-none-any.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.
@@ -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
+ );
hdl_parser/__init__.py ADDED
@@ -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.