ipxact-compiler 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 (33) hide show
  1. ipxact_compiler-0.1.0/LICENSE +164 -0
  2. ipxact_compiler-0.1.0/PKG-INFO +133 -0
  3. ipxact_compiler-0.1.0/README.md +106 -0
  4. ipxact_compiler-0.1.0/pyproject.toml +51 -0
  5. ipxact_compiler-0.1.0/setup.cfg +4 -0
  6. ipxact_compiler-0.1.0/src/ipxact/__init__.py +7 -0
  7. ipxact_compiler-0.1.0/src/ipxact/parser/__init__.py +3 -0
  8. ipxact_compiler-0.1.0/src/ipxact/parser/abstractiondefinition_parser.py +159 -0
  9. ipxact_compiler-0.1.0/src/ipxact/parser/busdefinition_parser.py +39 -0
  10. ipxact_compiler-0.1.0/src/ipxact/parser/common_parser.py +443 -0
  11. ipxact_compiler-0.1.0/src/ipxact/parser/component_parser.py +1022 -0
  12. ipxact_compiler-0.1.0/src/ipxact/parser/design_parser.py +183 -0
  13. ipxact_compiler-0.1.0/src/ipxact/parser/designconfig_parser.py +94 -0
  14. ipxact_compiler-0.1.0/src/ipxact/parser/main_parser.py +44 -0
  15. ipxact_compiler-0.1.0/src/ipxact/py.typed +0 -0
  16. ipxact_compiler-0.1.0/src/ipxact/schema/__init__.py +276 -0
  17. ipxact_compiler-0.1.0/src/ipxact/schema/abstractiondefinition.py +129 -0
  18. ipxact_compiler-0.1.0/src/ipxact/schema/busdefinition.py +28 -0
  19. ipxact_compiler-0.1.0/src/ipxact/schema/businterface.py +184 -0
  20. ipxact_compiler-0.1.0/src/ipxact/schema/common.py +176 -0
  21. ipxact_compiler-0.1.0/src/ipxact/schema/component.py +58 -0
  22. ipxact_compiler-0.1.0/src/ipxact/schema/component_sections.py +146 -0
  23. ipxact_compiler-0.1.0/src/ipxact/schema/design.py +147 -0
  24. ipxact_compiler-0.1.0/src/ipxact/schema/designconfig.py +74 -0
  25. ipxact_compiler-0.1.0/src/ipxact/schema/memorymap.py +332 -0
  26. ipxact_compiler-0.1.0/src/ipxact/schema/model.py +83 -0
  27. ipxact_compiler-0.1.0/src/ipxact/schema/ports.py +267 -0
  28. ipxact_compiler-0.1.0/src/ipxact/schema/vlnv.py +43 -0
  29. ipxact_compiler-0.1.0/src/ipxact_compiler.egg-info/PKG-INFO +133 -0
  30. ipxact_compiler-0.1.0/src/ipxact_compiler.egg-info/SOURCES.txt +31 -0
  31. ipxact_compiler-0.1.0/src/ipxact_compiler.egg-info/dependency_links.txt +1 -0
  32. ipxact_compiler-0.1.0/src/ipxact_compiler.egg-info/requires.txt +4 -0
  33. ipxact_compiler-0.1.0/src/ipxact_compiler.egg-info/top_level.txt +1 -0
@@ -0,0 +1,164 @@
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
+ This version of the GNU Lesser General Public License incorporates
9
+ the terms and conditions of version 3 of the GNU General Public
10
+ License, supplemented by the additional permissions listed below.
11
+
12
+ 0. Additional Definitions.
13
+
14
+ As used herein, "this License" refers to version 3 of the GNU Lesser
15
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
16
+ General Public License.
17
+
18
+ "The Library" refers to a covered work governed by this License,
19
+ other than an Application or a Combined Work as defined below.
20
+
21
+ An "Application" is any work that makes use of an interface provided
22
+ by the Library, but which is not otherwise based on the Library.
23
+ Defining a subclass of a class defined by the Library is deemed a mode
24
+ of using an interface provided by the Library.
25
+
26
+ A "Combined Work" is a work produced by combining or linking an
27
+ Application with the Library. The particular version of the Library
28
+ with which the Combined Work was made is also called the "Linked
29
+ Version".
30
+
31
+ The "Minimal Corresponding Source" for a Combined Work means the
32
+ Corresponding Source for the Combined Work, excluding any source code
33
+ for portions of the Combined Work that, considered in isolation, are
34
+ based on the Application, and not on the Linked Version.
35
+
36
+ The "Corresponding Application Code" for a Combined Work means the
37
+ object code and/or source code for the Application, including any data
38
+ and utility programs needed for reproducing the Combined Work from the
39
+ Application, but excluding the System Libraries of the Combined Work.
40
+
41
+ 1. Exception to Section 3 of the GNU GPL.
42
+
43
+ You may convey a covered work under sections 3 and 4 of this License
44
+ without being bound by section 3 of the GNU GPL.
45
+
46
+ 2. Conveying Modified Versions.
47
+
48
+ If you modify a copy of the Library, and, in your modifications, a
49
+ facility refers to a function or data to be supplied by an Application
50
+ that uses the facility (other than as an argument passed when the
51
+ facility is invoked), then you may convey a copy of the modified
52
+ version:
53
+
54
+ a) under this License, provided that you make a good faith effort to
55
+ ensure that, in the event an Application does not supply the
56
+ function or data, the facility still operates, and performs
57
+ whatever part of its purpose remains meaningful, or
58
+
59
+ b) under the GNU GPL, with none of the additional permissions of
60
+ this License applicable to that copy.
61
+
62
+ 3. Object Code Incorporating Material from Library Header Files.
63
+
64
+ The object code form of an Application may incorporate material from
65
+ a header file that is part of the Library. You may convey such object
66
+ code under terms of your choice, provided that, if the incorporated
67
+ material is not limited to numerical parameters, data structure
68
+ layouts and accessors, or small macros, inline functions and templates
69
+ (ten or fewer lines in length), you do both of the following:
70
+
71
+ a) Give prominent notice with each copy of the object code that the
72
+ Library is used in it and that the Library and its use are
73
+ covered by this License.
74
+
75
+ b) Accompany the object code with a copy of the GNU GPL and this license
76
+ document.
77
+
78
+ 4. Combined Works.
79
+
80
+ You may convey a Combined Work under terms of your choice that,
81
+ taken together, effectively do not restrict modification of the
82
+ portions of the Library contained in the Combined Work and reverse
83
+ engineering for debugging such modifications, if you also do each of
84
+ the following:
85
+
86
+ a) Give prominent notice with each copy of the Combined Work that
87
+ the Library is used in it and that the Library and its use are
88
+ covered by this License.
89
+
90
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
91
+ document.
92
+
93
+ c) For a Combined Work that displays copyright notices during
94
+ execution, include the copyright notice for the Library among
95
+ these notices, as well as a reference directing the user to the
96
+ copies of the GNU GPL and this license document.
97
+
98
+ d) Do one of the following:
99
+
100
+ 0) Convey the Minimal Corresponding Source under the terms of this
101
+ License, and the Corresponding Application Code in a form
102
+ suitable for, and under terms that permit, the user to
103
+ recombine or relink the Application with a modified version of
104
+ the Linked Version to produce a modified Combined Work, in the
105
+ manner specified by section 6 of the GNU GPL for conveying
106
+ Corresponding Source.
107
+
108
+ 1) Use a suitable shared library mechanism for linking with the
109
+ Library. A suitable mechanism is one that (a) uses at run time
110
+ a copy of the Library already present on the user's computer
111
+ system, and (b) will operate properly with a modified version
112
+ of the Library that is interface-compatible with the Linked
113
+ Version.
114
+
115
+ e) Provide Installation Information, but only if you would otherwise
116
+ be required to provide such information under section 6 of the
117
+ GNU GPL, and only to the extent that such information is
118
+ necessary to install and execute a modified version of the
119
+ Combined Work produced by recombining or relinking the
120
+ Application with a modified version of the Linked Version. (If
121
+ you use option 4d0, the Installation Information must accompany
122
+ the Minimal Corresponding Source and Corresponding Application
123
+ Code. If you use option 4d1, you must provide the Installation
124
+ Information in the manner specified by section 6 of the GNU GPL
125
+ for conveying Corresponding Source.)
126
+
127
+ 5. Combined Libraries.
128
+
129
+ You may place library facilities that are a work based on the
130
+ Library side by side in a single library together with other library
131
+ facilities that are not Applications and are not covered by this
132
+ License, and convey such a combined library under terms of your
133
+ choice, if you do both of the following:
134
+
135
+ a) Accompany the combined library with a copy of the same work based
136
+ on the Library, uncombined with any other library facilities,
137
+ conveyed under the terms of this License.
138
+
139
+ b) Give prominent notice with the combined library that part of it
140
+ is a work based on the Library, and explaining where to find the
141
+ accompanying uncombined form of the same work.
142
+
143
+ 6. Revised Versions of the GNU Lesser General Public License.
144
+
145
+ The Free Software Foundation may publish revised and/or new versions
146
+ of the GNU Lesser General Public License from time to time. Such new
147
+ versions will be similar in spirit to the present version, but may
148
+ differ in detail to address new problems or concerns.
149
+
150
+ Each version is given a distinguishing version number. If the
151
+ Library as you received it specifies that a certain numbered version
152
+ of the GNU Lesser General Public License "or any later version"
153
+ applies to it, you have the option of following the terms and
154
+ conditions either of that published version or of any later version
155
+ published by the Free Software Foundation. If the Library as you
156
+ received it does not specify a version number of the GNU Lesser
157
+ General Public License, you may choose any version of the GNU Lesser
158
+ General Public License ever published by the Free Software Foundation.
159
+
160
+ If the Library as you received it specifies that a proxy can decide
161
+ whether future versions of the GNU Lesser General Public License shall
162
+ apply, that proxy's public statement of acceptance of any version is
163
+ permanent authorization for you to choose that version for the
164
+ Library.
@@ -0,0 +1,133 @@
1
+ Metadata-Version: 2.4
2
+ Name: ipxact-compiler
3
+ Version: 0.1.0
4
+ Summary: Parses IEEE 1685-2022 IP-XACT XML into a Python object model.
5
+ Author: Maxime Travaillard
6
+ License-Expression: LGPL-3.0-only
7
+ Project-URL: Repository, https://github.com/IP-XACT/ipxact-compiler
8
+ Project-URL: Issues, https://github.com/IP-XACT/ipxact-compiler/issues
9
+ Keywords: IP-XACT,IEEE 1685,XML,Compiler
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Topic :: Scientific/Engineering
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: lxml
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ # ipxact-compiler
29
+
30
+ A Python library that parses [IEEE 1685-2022](https://standards.ieee.org/ieee/1685/10307/) IP-XACT
31
+ XML documents into a Python object model.
32
+
33
+ It is a standalone, general-purpose parsing library, not tied to any specific downstream tool or
34
+ flow. `ipxact-compiler` reads IP-XACT and hands you back Python objects; it does not resolve
35
+ cross-file references, elaborate a design, validate semantic consistency, or generate any output.
36
+ That is the job of tools built on top of it.
37
+
38
+ ## What it supports
39
+
40
+ Five IP-XACT top-level document types are supported for now:
41
+
42
+ - `component`
43
+ - `design`
44
+ - `designConfiguration`
45
+ - `busDefinition`
46
+ - `abstractionDefinition`
47
+
48
+ The object model aims for full fidelity with the IEEE 1685-2022 XSD schema for these document types:
49
+ every element and attribute the schema defines is represented.
50
+
51
+ A few things are intentionally represented in a simplified form rather than being modeled in full
52
+ depth:
53
+
54
+ - **Expressions are raw strings.** Fields typed as an IP-XACT `expression` (parameter values, array
55
+ bounds, and similar) are kept as unevaluated strings, not parsed or evaluated as arithmetic.
56
+ - **`vendorExtensions` is opaque.** It is parsed generically, not modeled per-vendor.
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ pip install ipxact-compiler
62
+ ```
63
+
64
+ Or, for local development:
65
+
66
+ ```bash
67
+ git clone <this repo>
68
+ cd ipxact-compiler
69
+ pip install -e ".[dev]"
70
+ ```
71
+
72
+ Requires Python >= 3.9. The only runtime dependency is [`lxml`](https://lxml.de/).
73
+
74
+ ## Usage
75
+
76
+ ```python
77
+ import ipxact
78
+
79
+ component = ipxact.parse_file("path/to/some_component.xml")
80
+
81
+ component.vlnv # VLNV
82
+ component.bus_interfaces # list[BusInterface]
83
+ component.memory_maps # list[MemoryMap]
84
+ component.model # Model | None
85
+ ```
86
+
87
+ `ipxact.parse_file(path)` reads a file, figures out its document type from the root element, and
88
+ returns the matching dataclass (`Component`, `Design`, `DesignConfiguration`, `BusDefinition`, or
89
+ `AbstractionDefinition`).
90
+
91
+ Every schema class (`Component`, `VLNV`, `BusInterface`, `Register`, `Field`, and so on) is
92
+ re-exported at the top level, so `ipxact.<ClassName>` works without reaching into submodules.
93
+
94
+ ## Design principles
95
+
96
+ - **Single-file parsing only.** `ipxact-compiler` never opens a second file on its own. Resolving
97
+ VLNV references across a library of files (for example, finding the `Component` that a `Design`'s
98
+ instance refers to) is left to the caller.
99
+ - **Input files are assumed to be valid.** `ipxact-compiler` does not perform validation; it assumes
100
+ the IP-XACT documents you give it are already well-formed and conform to the standard. This is why
101
+ the parser currently favors defaulting over raising on missing or malformed data. This may change
102
+ (see "Known limitations").
103
+ - **Hand-written, not XSD auto-generated.** The object model is a set of hand-written Python
104
+ dataclasses following the schema but not automatically generated from the XSD. This keeps the API
105
+ stable, at the cost of needing to keep it manually in sync with the standard.
106
+
107
+ ## Known limitations / ideas for later
108
+
109
+ These are open items, not commitments. None of them are currently planned to start imminently.
110
+
111
+ - **No XSD schema validation.** Malformed IP-XACT (missing required elements, wrong types, invalid
112
+ structure) is not rejected at parse time; the parser will generally just default missing fields
113
+ rather than erroring. A validation path using the bundled IEEE 1685-2022 XSDs and
114
+ `lxml.etree.XMLSchema` could be considered, but it means packaging the full IEEE 1685-2022 XSD
115
+ schema with this repository, for a benefit that only matters if you're feeding it genuinely
116
+ invalid files.
117
+ - **No deliberate error-handling philosophy yet.** Right now, malformed input either silently
118
+ produces a default value or raises whatever low-level Python exception happens to occur (a
119
+ `ValueError`, an `AttributeError`, etc.) rather than a clear, intentional error type. Deciding on
120
+ and implementing a consistent policy (raise vs. warn vs. silently default, and what exception
121
+ types/messages to use) is still open.
122
+ - **No Semantic Consistency Rule (SCR) checking**, per IEEE 1685-2022 Annex B. These are the
123
+ standard's own rules for validity that XSD alone can't express (VLNV resolution correctness,
124
+ bus/abstraction interface compatibility, and so on). Each rule is tagged with two independent
125
+ flags: whether it is checkable on a single document alone, and whether it applies
126
+ post-configuration (after linking). In our case, only the subset that is single-document-checkable
127
+ and not post-config could live in `ipxact-compiler`.
128
+ - **No dedicated documentation yet.** This README covers the basics, but a proper documentation site
129
+ (full API reference, more usage examples) is planned for the future.
130
+
131
+ ## License
132
+
133
+ LGPL-3.0. See [`LICENSE`](LICENSE).
@@ -0,0 +1,106 @@
1
+ # ipxact-compiler
2
+
3
+ A Python library that parses [IEEE 1685-2022](https://standards.ieee.org/ieee/1685/10307/) IP-XACT
4
+ XML documents into a Python object model.
5
+
6
+ It is a standalone, general-purpose parsing library, not tied to any specific downstream tool or
7
+ flow. `ipxact-compiler` reads IP-XACT and hands you back Python objects; it does not resolve
8
+ cross-file references, elaborate a design, validate semantic consistency, or generate any output.
9
+ That is the job of tools built on top of it.
10
+
11
+ ## What it supports
12
+
13
+ Five IP-XACT top-level document types are supported for now:
14
+
15
+ - `component`
16
+ - `design`
17
+ - `designConfiguration`
18
+ - `busDefinition`
19
+ - `abstractionDefinition`
20
+
21
+ The object model aims for full fidelity with the IEEE 1685-2022 XSD schema for these document types:
22
+ every element and attribute the schema defines is represented.
23
+
24
+ A few things are intentionally represented in a simplified form rather than being modeled in full
25
+ depth:
26
+
27
+ - **Expressions are raw strings.** Fields typed as an IP-XACT `expression` (parameter values, array
28
+ bounds, and similar) are kept as unevaluated strings, not parsed or evaluated as arithmetic.
29
+ - **`vendorExtensions` is opaque.** It is parsed generically, not modeled per-vendor.
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install ipxact-compiler
35
+ ```
36
+
37
+ Or, for local development:
38
+
39
+ ```bash
40
+ git clone <this repo>
41
+ cd ipxact-compiler
42
+ pip install -e ".[dev]"
43
+ ```
44
+
45
+ Requires Python >= 3.9. The only runtime dependency is [`lxml`](https://lxml.de/).
46
+
47
+ ## Usage
48
+
49
+ ```python
50
+ import ipxact
51
+
52
+ component = ipxact.parse_file("path/to/some_component.xml")
53
+
54
+ component.vlnv # VLNV
55
+ component.bus_interfaces # list[BusInterface]
56
+ component.memory_maps # list[MemoryMap]
57
+ component.model # Model | None
58
+ ```
59
+
60
+ `ipxact.parse_file(path)` reads a file, figures out its document type from the root element, and
61
+ returns the matching dataclass (`Component`, `Design`, `DesignConfiguration`, `BusDefinition`, or
62
+ `AbstractionDefinition`).
63
+
64
+ Every schema class (`Component`, `VLNV`, `BusInterface`, `Register`, `Field`, and so on) is
65
+ re-exported at the top level, so `ipxact.<ClassName>` works without reaching into submodules.
66
+
67
+ ## Design principles
68
+
69
+ - **Single-file parsing only.** `ipxact-compiler` never opens a second file on its own. Resolving
70
+ VLNV references across a library of files (for example, finding the `Component` that a `Design`'s
71
+ instance refers to) is left to the caller.
72
+ - **Input files are assumed to be valid.** `ipxact-compiler` does not perform validation; it assumes
73
+ the IP-XACT documents you give it are already well-formed and conform to the standard. This is why
74
+ the parser currently favors defaulting over raising on missing or malformed data. This may change
75
+ (see "Known limitations").
76
+ - **Hand-written, not XSD auto-generated.** The object model is a set of hand-written Python
77
+ dataclasses following the schema but not automatically generated from the XSD. This keeps the API
78
+ stable, at the cost of needing to keep it manually in sync with the standard.
79
+
80
+ ## Known limitations / ideas for later
81
+
82
+ These are open items, not commitments. None of them are currently planned to start imminently.
83
+
84
+ - **No XSD schema validation.** Malformed IP-XACT (missing required elements, wrong types, invalid
85
+ structure) is not rejected at parse time; the parser will generally just default missing fields
86
+ rather than erroring. A validation path using the bundled IEEE 1685-2022 XSDs and
87
+ `lxml.etree.XMLSchema` could be considered, but it means packaging the full IEEE 1685-2022 XSD
88
+ schema with this repository, for a benefit that only matters if you're feeding it genuinely
89
+ invalid files.
90
+ - **No deliberate error-handling philosophy yet.** Right now, malformed input either silently
91
+ produces a default value or raises whatever low-level Python exception happens to occur (a
92
+ `ValueError`, an `AttributeError`, etc.) rather than a clear, intentional error type. Deciding on
93
+ and implementing a consistent policy (raise vs. warn vs. silently default, and what exception
94
+ types/messages to use) is still open.
95
+ - **No Semantic Consistency Rule (SCR) checking**, per IEEE 1685-2022 Annex B. These are the
96
+ standard's own rules for validity that XSD alone can't express (VLNV resolution correctness,
97
+ bus/abstraction interface compatibility, and so on). Each rule is tagged with two independent
98
+ flags: whether it is checkable on a single document alone, and whether it applies
99
+ post-configuration (after linking). In our case, only the subset that is single-document-checkable
100
+ and not post-config could live in `ipxact-compiler`.
101
+ - **No dedicated documentation yet.** This README covers the basics, but a proper documentation site
102
+ (full API reference, more usage examples) is planned for the future.
103
+
104
+ ## License
105
+
106
+ LGPL-3.0. See [`LICENSE`](LICENSE).
@@ -0,0 +1,51 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ipxact-compiler"
7
+ dynamic = ["version"]
8
+ description = "Parses IEEE 1685-2022 IP-XACT XML into a Python object model."
9
+ readme = "README.md"
10
+ license = "LGPL-3.0-only"
11
+ license-files = ["LICENSE"]
12
+ authors = [
13
+ { name = "Maxime Travaillard"},
14
+ ]
15
+ requires-python = ">=3.9"
16
+ dependencies = [
17
+ "lxml",
18
+ ]
19
+ keywords = [
20
+ "IP-XACT", "IEEE 1685", "XML", "Compiler",
21
+ ]
22
+ classifiers = [
23
+ "Development Status :: 3 - Alpha",
24
+ "Programming Language :: Python :: 3",
25
+ "Programming Language :: Python :: 3 :: Only",
26
+ "Programming Language :: Python :: 3.9",
27
+ "Programming Language :: Python :: 3.10",
28
+ "Programming Language :: Python :: 3.11",
29
+ "Programming Language :: Python :: 3.12",
30
+ "Programming Language :: Python :: 3.13",
31
+ "Programming Language :: Python :: 3.14",
32
+ "Topic :: Scientific/Engineering",
33
+ ]
34
+
35
+ [project.urls]
36
+ Repository = "https://github.com/IP-XACT/ipxact-compiler"
37
+ Issues = "https://github.com/IP-XACT/ipxact-compiler/issues"
38
+
39
+ [project.optional-dependencies]
40
+ dev = [
41
+ "pytest",
42
+ ]
43
+
44
+ [tool.setuptools.dynamic]
45
+ version = {attr = "ipxact.__version__"}
46
+
47
+ [tool.setuptools.packages.find]
48
+ where = ["src"]
49
+
50
+ [tool.setuptools.package-data]
51
+ ipxact = ["py.typed"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,7 @@
1
+ __version__ = "0.1.0"
2
+
3
+ from .parser import parse_element, parse_file
4
+ from .schema import * # noqa: F401,F403
5
+ from .schema import __all__ as _schema_all
6
+
7
+ __all__ = [*_schema_all, "parse_element", "parse_file", "__version__"]
@@ -0,0 +1,3 @@
1
+ from .main_parser import parse_element, parse_file
2
+
3
+ __all__ = ["parse_element", "parse_file"]
@@ -0,0 +1,159 @@
1
+ from __future__ import annotations
2
+
3
+ from lxml import etree
4
+
5
+ from ..schema.abstractiondefinition import (
6
+ AbstractionDefinition,
7
+ AbstractionPort,
8
+ PortConstraints,
9
+ Presence,
10
+ RequiresDriver,
11
+ TransactionalAbstractionPort,
12
+ TransactionalModeConstraints,
13
+ TransactionalSystemConstraints,
14
+ WireAbstractionPort,
15
+ WireModeConstraints,
16
+ WireSystemConstraints,
17
+ )
18
+ from .common_parser import (
19
+ as_bool,
20
+ attr_bool,
21
+ bool_text,
22
+ child,
23
+ children,
24
+ elem_text,
25
+ parse_assertions,
26
+ parse_children,
27
+ parse_choices,
28
+ parse_drive_constraint,
29
+ parse_load_constraint,
30
+ parse_parameters,
31
+ parse_protocol,
32
+ parse_qualifier,
33
+ parse_timing_constraints,
34
+ parse_vendor_extensions,
35
+ parse_vlnv,
36
+ parse_vlnv_ref,
37
+ text,
38
+ )
39
+
40
+
41
+ def parse_abstractiondefinition(root: etree._Element) -> AbstractionDefinition:
42
+ """Parse an ipxact:abstractionDefinition root element into an AbstractionDefinition object."""
43
+ extends_elem = child(root, "extends")
44
+ return AbstractionDefinition(
45
+ vlnv=parse_vlnv(root),
46
+ bus_type=parse_vlnv_ref(child(root, "busType")),
47
+ extends=parse_vlnv_ref(extends_elem) if extends_elem is not None else None,
48
+ ports=parse_children(root, "ports", "port", _parse_abstraction_port),
49
+ choices=parse_choices(root),
50
+ parameters=parse_parameters(root),
51
+ assertions=parse_assertions(root),
52
+ display_name=text(root, "displayName"),
53
+ short_description=text(root, "shortDescription"),
54
+ description=text(root, "description"),
55
+ vendor_extensions=parse_vendor_extensions(root),
56
+ )
57
+
58
+
59
+ def _parse_port_constraints(elem: etree._Element) -> PortConstraints:
60
+ return PortConstraints(
61
+ timing_constraints=parse_timing_constraints(elem),
62
+ drive_constraint=parse_drive_constraint(elem),
63
+ load_constraint=parse_load_constraint(elem),
64
+ )
65
+
66
+
67
+ def _parse_requires_driver(elem: etree._Element) -> RequiresDriver:
68
+ return RequiresDriver(value=as_bool(elem.text, False), driver_type=elem.get("driverType", "any"))
69
+
70
+
71
+ def _parse_wire_mode_constraints(elem: etree._Element) -> WireModeConstraints:
72
+ presence = text(elem, "presence")
73
+ width_elem = child(elem, "width")
74
+ direction_elem = child(elem, "direction")
75
+ mode_constraints_elem = child(elem, "modeConstraints")
76
+ mirrored_mode_constraints_elem = child(elem, "mirroredModeConstraints")
77
+ return WireModeConstraints(
78
+ presence=Presence(presence) if presence else Presence.OPTIONAL,
79
+ width=elem_text(width_elem),
80
+ width_all_bits_required=attr_bool(width_elem, "allBits", False) if width_elem is not None else False,
81
+ # direction defaults to "out" when absent
82
+ direction=elem_text(direction_elem) or "out",
83
+ mode_constraints=(
84
+ _parse_port_constraints(mode_constraints_elem) if mode_constraints_elem is not None else None
85
+ ),
86
+ mirrored_mode_constraints=(
87
+ _parse_port_constraints(mirrored_mode_constraints_elem)
88
+ if mirrored_mode_constraints_elem is not None
89
+ else None
90
+ ),
91
+ )
92
+
93
+
94
+ def _parse_wire_system_constraints(elem: etree._Element) -> WireSystemConstraints:
95
+ return WireSystemConstraints(group=text(elem, "group") or "", constraints=_parse_wire_mode_constraints(elem))
96
+
97
+
98
+ def _parse_wire_abstraction_port(elem: etree._Element) -> WireAbstractionPort:
99
+ on_initiator_elem = child(elem, "onInitiator")
100
+ on_target_elem = child(elem, "onTarget")
101
+ requires_driver_elem = child(elem, "requiresDriver")
102
+ return WireAbstractionPort(
103
+ qualifier=parse_qualifier(elem),
104
+ on_system=[_parse_wire_system_constraints(e) for e in children(elem, "onSystem")],
105
+ on_initiator=_parse_wire_mode_constraints(on_initiator_elem) if on_initiator_elem is not None else None,
106
+ on_target=_parse_wire_mode_constraints(on_target_elem) if on_target_elem is not None else None,
107
+ default_value=text(elem, "defaultValue"),
108
+ requires_driver=_parse_requires_driver(requires_driver_elem) if requires_driver_elem is not None else None,
109
+ )
110
+
111
+
112
+ def _parse_transactional_mode_constraints(elem: etree._Element) -> TransactionalModeConstraints:
113
+ presence = text(elem, "presence")
114
+ initiative_elem = child(elem, "initiative")
115
+ kind_elem = child(elem, "kind")
116
+ return TransactionalModeConstraints(
117
+ presence=Presence(presence) if presence else Presence.OPTIONAL,
118
+ # initiative defaults to "requires" when absent
119
+ initiative=elem_text(initiative_elem) or "requires",
120
+ kind=elem_text(kind_elem),
121
+ bus_width=text(elem, "busWidth"),
122
+ protocol=parse_protocol(elem),
123
+ )
124
+
125
+
126
+ def _parse_transactional_system_constraints(elem: etree._Element) -> TransactionalSystemConstraints:
127
+ return TransactionalSystemConstraints(
128
+ group=text(elem, "group") or "", constraints=_parse_transactional_mode_constraints(elem)
129
+ )
130
+
131
+
132
+ def _parse_transactional_abstraction_port(elem: etree._Element) -> TransactionalAbstractionPort:
133
+ on_initiator_elem = child(elem, "onInitiator")
134
+ on_target_elem = child(elem, "onTarget")
135
+ return TransactionalAbstractionPort(
136
+ qualifier=parse_qualifier(elem),
137
+ on_system=[_parse_transactional_system_constraints(e) for e in children(elem, "onSystem")],
138
+ on_initiator=(
139
+ _parse_transactional_mode_constraints(on_initiator_elem) if on_initiator_elem is not None else None
140
+ ),
141
+ on_target=_parse_transactional_mode_constraints(on_target_elem) if on_target_elem is not None else None,
142
+ )
143
+
144
+
145
+ def _parse_abstraction_port(elem: etree._Element) -> AbstractionPort:
146
+ wire_elem = child(elem, "wire")
147
+ transactional_elem = child(elem, "transactional")
148
+ return AbstractionPort(
149
+ logical_name=text(elem, "logicalName") or "",
150
+ wire=_parse_wire_abstraction_port(wire_elem) if wire_elem is not None else None,
151
+ transactional=(
152
+ _parse_transactional_abstraction_port(transactional_elem) if transactional_elem is not None else None
153
+ ),
154
+ match=bool_text(elem, "match", False),
155
+ display_name=text(elem, "displayName"),
156
+ short_description=text(elem, "shortDescription"),
157
+ description=text(elem, "description"),
158
+ vendor_extensions=parse_vendor_extensions(elem),
159
+ )
@@ -0,0 +1,39 @@
1
+ from __future__ import annotations
2
+
3
+ from lxml import etree
4
+
5
+ from ..schema.busdefinition import BusDefinition
6
+ from .common_parser import (
7
+ bool_text,
8
+ child,
9
+ parse_assertions,
10
+ parse_choices,
11
+ parse_parameters,
12
+ parse_texts,
13
+ parse_vendor_extensions,
14
+ parse_vlnv,
15
+ parse_vlnv_ref,
16
+ text,
17
+ )
18
+
19
+
20
+ def parse_busdefinition(root: etree._Element) -> BusDefinition:
21
+ """Parse an ipxact:busDefinition root element into a BusDefinition object."""
22
+ extends_elem = child(root, "extends")
23
+ return BusDefinition(
24
+ vlnv=parse_vlnv(root),
25
+ direct_connection=bool_text(root, "directConnection", False),
26
+ is_addressable=bool_text(root, "isAddressable", False),
27
+ broadcast=bool_text(root, "broadcast"),
28
+ extends=parse_vlnv_ref(extends_elem) if extends_elem is not None else None,
29
+ max_initiators=text(root, "maxInitiators"),
30
+ max_targets=text(root, "maxTargets"),
31
+ system_group_names=parse_texts(root, "systemGroupNames", "systemGroupName"),
32
+ choices=parse_choices(root),
33
+ parameters=parse_parameters(root),
34
+ assertions=parse_assertions(root),
35
+ display_name=text(root, "displayName"),
36
+ short_description=text(root, "shortDescription"),
37
+ description=text(root, "description"),
38
+ vendor_extensions=parse_vendor_extensions(root),
39
+ )