peakrdl-python 0.7.0__tar.gz → 0.7.3__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.
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/.github/workflows/action.yaml +10 -10
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/PKG-INFO +1 -1
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/example/array_access/demo_array_access.py +0 -3
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/__about__.py +1 -1
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/__peakrdl__.py +14 -4
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/exporter.py +137 -66
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/lib/base.py +152 -85
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/lib/register.py +20 -14
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/safe_name_utility.py +6 -14
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/templates/addrmap_tb.py.jinja +1 -13
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python.egg-info/PKG-INFO +1 -1
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/unit_tests/test_array_indexing.py +42 -37
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/.gitignore +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/.readthedocs.yaml +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/LICENSE +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/MANIFEST.in +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/README.md +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/docs/api.rst +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/docs/api_components.rst +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/docs/command_line.rst +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/docs/conf.py +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/docs/customisation.rst +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/docs/generated_package.rst +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/docs/genindex.rst +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/docs/index.rst +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/docs/requirements.txt +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/example/array_access/array_access.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/example/optimised_access/demo_optimised_access.py +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/example/optimised_access/optimised_access.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/example/overridden_names/over_ridden_names.py +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/example/overridden_names/overridden_names.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/example/simulating_callbacks/chip_with_a_GPIO.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/example/simulating_callbacks/flashing_the_LED.py +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/example/tranversing_address_map/chip_with_registers.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/example/tranversing_address_map/dumping_register_state_to_json_file.py +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/example/tranversing_address_map/reg_dump.json +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/example/tranversing_address_map/reseting_registers.py +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/example/tranversing_address_map/writing_register_state_from_json_file.py +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/generate_testcases.py +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/pyproject.toml +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/setup.cfg +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/.coveragerc +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/__init__.py +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/_node_walkers.py +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/lib/__init__.py +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/lib/callbacks.py +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/lib/fields.py +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/lib/memory.py +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/systemrdl_node_utility_functions.py +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/templates/__init__.py +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/templates/addrmap.py.jinja +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/templates/addrmap_field.py.jinja +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/templates/addrmap_memory.py.jinja +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/templates/addrmap_register.py.jinja +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/templates/addrmap_simulation.py.jinja +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/templates/addrmap_simulation_tb.jinja +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/templates/baseclass_tb.py.jinja +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/templates/header.py.jinja +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/templates/header_tb.py.jinja +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python/templates/reg_definitions.py.jinja +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python.egg-info/SOURCES.txt +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python.egg-info/dependency_links.txt +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python.egg-info/entry_points.txt +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python.egg-info/requires.txt +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/src/peakrdl_python.egg-info/top_level.txt +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/.mypy.ini +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/alternative_template_toml/peakrdl.toml +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/alternative_templates/header.py.jinja +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/alternative_templates/header_tb.py.jinja +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/pylint.rc +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/RDLFormatCode_example.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/addr_map.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/all_register_access_types.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/basic.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/block_a.xml +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/block_b.xml +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/different_array_types.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/enum_example.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/example_issue_106.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/field_scope.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/field_with_overridden_reset.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/fields_with_HW_write.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/fields_with_reset_values.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/memories.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/memories_with_registers.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/msb0_and_lsb0.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/multi_block.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/multifile.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/name_clash.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/overridden_python_name.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/parametrised_readonly_and_readwrite.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/regfile_and_arrays.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/same_but_different_enum.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/signals_definitions_at_various_levels.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/simple.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/simple.xml +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/sizes_registers.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/testcases/write_only_enum_with_undefined_reset.rdl +0 -0
- {peakrdl-python-0.7.0 → peakrdl-python-0.7.3}/tests/unit_tests/__init__.py +0 -0
|
@@ -23,9 +23,9 @@ jobs:
|
|
|
23
23
|
lint:
|
|
24
24
|
runs-on: ubuntu-latest
|
|
25
25
|
steps:
|
|
26
|
-
- uses: actions/checkout@
|
|
26
|
+
- uses: actions/checkout@v4
|
|
27
27
|
- name: Set up Python
|
|
28
|
-
uses: actions/setup-python@
|
|
28
|
+
uses: actions/setup-python@v5
|
|
29
29
|
with:
|
|
30
30
|
python-version: "3.11"
|
|
31
31
|
|
|
@@ -41,9 +41,9 @@ jobs:
|
|
|
41
41
|
mypy:
|
|
42
42
|
runs-on: ubuntu-latest
|
|
43
43
|
steps:
|
|
44
|
-
- uses: actions/checkout@
|
|
44
|
+
- uses: actions/checkout@v4
|
|
45
45
|
- name: Set up Python
|
|
46
|
-
uses: actions/setup-python@
|
|
46
|
+
uses: actions/setup-python@v5
|
|
47
47
|
with:
|
|
48
48
|
python-version: "3.11"
|
|
49
49
|
|
|
@@ -65,10 +65,10 @@ jobs:
|
|
|
65
65
|
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
|
|
66
66
|
|
|
67
67
|
steps:
|
|
68
|
-
- uses: actions/checkout@
|
|
68
|
+
- uses: actions/checkout@v4
|
|
69
69
|
|
|
70
70
|
- name: Set up Python ${{ matrix.python-version }}
|
|
71
|
-
uses: actions/setup-python@
|
|
71
|
+
uses: actions/setup-python@v5
|
|
72
72
|
with:
|
|
73
73
|
python-version: ${{ matrix.python-version }}
|
|
74
74
|
|
|
@@ -159,9 +159,9 @@ jobs:
|
|
|
159
159
|
name: Build source distribution
|
|
160
160
|
runs-on: ubuntu-latest
|
|
161
161
|
steps:
|
|
162
|
-
- uses: actions/checkout@
|
|
162
|
+
- uses: actions/checkout@v4
|
|
163
163
|
|
|
164
|
-
- uses: actions/setup-python@
|
|
164
|
+
- uses: actions/setup-python@v5
|
|
165
165
|
name: Install Python
|
|
166
166
|
with:
|
|
167
167
|
python-version: "3.11"
|
|
@@ -173,7 +173,7 @@ jobs:
|
|
|
173
173
|
- name: Build
|
|
174
174
|
run: python -m build
|
|
175
175
|
|
|
176
|
-
- uses: actions/upload-artifact@
|
|
176
|
+
- uses: actions/upload-artifact@v4
|
|
177
177
|
with:
|
|
178
178
|
path: |
|
|
179
179
|
dist/*.tar.gz
|
|
@@ -190,7 +190,7 @@ jobs:
|
|
|
190
190
|
# Only publish when a GitHub Release is created.
|
|
191
191
|
if: github.event_name == 'release'
|
|
192
192
|
steps:
|
|
193
|
-
- uses: actions/download-artifact@
|
|
193
|
+
- uses: actions/download-artifact@v4
|
|
194
194
|
with:
|
|
195
195
|
name: artifact
|
|
196
196
|
path: dist
|
|
@@ -36,9 +36,6 @@ if __name__ == '__main__':
|
|
|
36
36
|
for index, array_item in regmodel.reg_array_1D.items():
|
|
37
37
|
print(f'item[{index[0]}]={array_item.field_a.read():d}')
|
|
38
38
|
|
|
39
|
-
# access a entry in the 3D array
|
|
40
|
-
print(regmodel.reg_array_3D[1][1][1].field_a.read())
|
|
41
|
-
|
|
42
39
|
# access a entry in the 3D array with other indexing scheme
|
|
43
40
|
print(regmodel.reg_array_3D[1,1,1].field_a.read())
|
|
44
41
|
|
|
@@ -29,7 +29,7 @@ class Exporter(ExporterSubcommandPlugin):
|
|
|
29
29
|
"user_template_dir": schema.DirectoryPath(),
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
def add_exporter_arguments(self, arg_group: 'argparse.
|
|
32
|
+
def add_exporter_arguments(self, arg_group: 'argparse._ActionsContainer') -> None:
|
|
33
33
|
"""
|
|
34
34
|
Added the arguments to the PeakRDL arguments
|
|
35
35
|
|
|
@@ -42,7 +42,16 @@ class Exporter(ExporterSubcommandPlugin):
|
|
|
42
42
|
arg_group.add_argument('--async', action='store_true', dest='is_async',
|
|
43
43
|
help='define accesses to register model as asynchronous')
|
|
44
44
|
arg_group.add_argument('--skip_test_case_generation', action='store_true',
|
|
45
|
-
|
|
45
|
+
help='skip the generation of the test cases')
|
|
46
|
+
arg_group.add_argument('--suppress_cleanup', action='store_true', dest='suppress_cleanup',
|
|
47
|
+
help='by default peakrdl_python deletes all existing python .py '
|
|
48
|
+
'files found in the directory where the package will be'
|
|
49
|
+
' generated. This is normally useful if the user is '
|
|
50
|
+
'generating over the top of an existing package and prevents '
|
|
51
|
+
'problems when the strucutre of the register map changes. '
|
|
52
|
+
'However, if additional python files are added by the user '
|
|
53
|
+
'(not recommended) this cleanup will need to be suppressed '
|
|
54
|
+
'and managed by the user')
|
|
46
55
|
|
|
47
56
|
def do_export(self, top_node: 'AddrmapNode', options: 'argparse.Namespace') -> None:
|
|
48
57
|
"""
|
|
@@ -57,11 +66,12 @@ class Exporter(ExporterSubcommandPlugin):
|
|
|
57
66
|
"""
|
|
58
67
|
templates = self.cfg['user_template_dir']
|
|
59
68
|
peakrdl_exporter = \
|
|
60
|
-
PythonExporter(user_template_dir=templates)
|
|
69
|
+
PythonExporter(user_template_dir=templates) # type: ignore[no-untyped-call]
|
|
61
70
|
|
|
62
71
|
peakrdl_exporter.export(
|
|
63
72
|
top_node,
|
|
64
73
|
options.output,
|
|
65
74
|
options.is_async,
|
|
66
|
-
skip_test_case_generation=options.skip_test_case_generation
|
|
75
|
+
skip_test_case_generation=options.skip_test_case_generation,
|
|
76
|
+
delete_existing_package_content=not options.suppress_cleanup
|
|
67
77
|
)
|
|
@@ -3,9 +3,8 @@ Main Classes for the PeakRDL Python
|
|
|
3
3
|
"""
|
|
4
4
|
import os
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from shutil import
|
|
6
|
+
from shutil import copy
|
|
7
7
|
from typing import List, NoReturn, Iterable, Tuple
|
|
8
|
-
from glob import glob
|
|
9
8
|
|
|
10
9
|
import jinja2 as jj
|
|
11
10
|
from systemrdl import RDLWalker # type: ignore
|
|
@@ -39,6 +38,120 @@ class PythonExportTemplateError(Exception):
|
|
|
39
38
|
Exception for hading errors in the templating
|
|
40
39
|
"""
|
|
41
40
|
|
|
41
|
+
class _PythonPackage:
|
|
42
|
+
"""
|
|
43
|
+
Class to represent a python package
|
|
44
|
+
"""
|
|
45
|
+
def __init__(self, path: Path):
|
|
46
|
+
self._path = path
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def path(self) -> Path:
|
|
50
|
+
"""
|
|
51
|
+
path of the package
|
|
52
|
+
"""
|
|
53
|
+
return self._path
|
|
54
|
+
|
|
55
|
+
def child_package(self, name: str) -> '_PythonPackage':
|
|
56
|
+
"""
|
|
57
|
+
provide a child package within the current package
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
name: name of child package
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
None
|
|
64
|
+
|
|
65
|
+
"""
|
|
66
|
+
return _PythonPackage(path=self.path / name)
|
|
67
|
+
|
|
68
|
+
def child_module_path(self, name: str) -> Path:
|
|
69
|
+
"""
|
|
70
|
+
return a child module within the package
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
name: name of module
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
None
|
|
77
|
+
|
|
78
|
+
"""
|
|
79
|
+
return Path(self.path) / name
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def _init_path(self) -> Path:
|
|
83
|
+
return self.child_module_path('__init__.py')
|
|
84
|
+
|
|
85
|
+
def _make_empty_init_file(self) -> None:
|
|
86
|
+
with self._init_path.open('w', encoding='utf-8') as fid:
|
|
87
|
+
fid.write('pass\n')
|
|
88
|
+
|
|
89
|
+
def create_empty_package(self, cleanup: bool) -> None:
|
|
90
|
+
"""
|
|
91
|
+
make the package folder (if it does not already exist), populate the __init__.py and
|
|
92
|
+
optionally remove any existing python files
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
cleanup (bool) : delete any existing python files in the package
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
None
|
|
99
|
+
"""
|
|
100
|
+
if self.path.exists():
|
|
101
|
+
if cleanup:
|
|
102
|
+
for file in self.path.glob('*.py'):
|
|
103
|
+
os.remove(file.resolve())
|
|
104
|
+
else:
|
|
105
|
+
self.path.mkdir(parents=True, exist_ok=False)
|
|
106
|
+
self._make_empty_init_file()
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class _Package(_PythonPackage):
|
|
110
|
+
"""
|
|
111
|
+
Class to define the package being generated
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
include_tests (bool): include the tests package
|
|
115
|
+
"""
|
|
116
|
+
def __init__(self, path:str, package_name: str, include_tests: bool):
|
|
117
|
+
super().__init__(Path(path) / package_name)
|
|
118
|
+
self.reg_model = self.child_package('reg_model')
|
|
119
|
+
self._include_tests = include_tests
|
|
120
|
+
if include_tests:
|
|
121
|
+
self.tests = self.child_package('tests')
|
|
122
|
+
self.lib = self.child_package('lib')
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def create_empty_package(self, cleanup: bool) -> None:
|
|
126
|
+
"""
|
|
127
|
+
create the directories and __init__.py files associated with the exported package
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
package_path: directory for the package output
|
|
131
|
+
cleanup (bool): delete existing python files
|
|
132
|
+
|
|
133
|
+
Returns:
|
|
134
|
+
None
|
|
135
|
+
|
|
136
|
+
"""
|
|
137
|
+
|
|
138
|
+
# make the folder for this package and populate the empty __init__.py
|
|
139
|
+
super().create_empty_package(cleanup=cleanup)
|
|
140
|
+
# make all the child packages folders and their __init__.py
|
|
141
|
+
self.reg_model.create_empty_package(cleanup=cleanup)
|
|
142
|
+
if self._include_tests:
|
|
143
|
+
self.tests.create_empty_package(cleanup=cleanup)
|
|
144
|
+
self.lib.create_empty_package(cleanup=cleanup)
|
|
145
|
+
|
|
146
|
+
# copy all the python source code that is part of the library which comes as part of the
|
|
147
|
+
# peakrdl-python to the lib direction of the generated package
|
|
148
|
+
template_package = Path(__file__).parent / 'lib'
|
|
149
|
+
files_in_package = template_package.glob('*.py')
|
|
150
|
+
|
|
151
|
+
for file_in_package in files_in_package:
|
|
152
|
+
copy(src=file_in_package, dst=self.lib.path)
|
|
153
|
+
|
|
154
|
+
|
|
42
155
|
class PythonExporter:
|
|
43
156
|
"""
|
|
44
157
|
PeakRDL Python Exporter class
|
|
@@ -96,7 +209,8 @@ class PythonExporter:
|
|
|
96
209
|
|
|
97
210
|
def export(self, node: Node, path: str,
|
|
98
211
|
asyncoutput: bool=False,
|
|
99
|
-
skip_test_case_generation: bool=False
|
|
212
|
+
skip_test_case_generation: bool=False,
|
|
213
|
+
delete_existing_package_content: bool = True) -> List[str]:
|
|
100
214
|
"""
|
|
101
215
|
Generated Python Code and Testbench
|
|
102
216
|
|
|
@@ -106,6 +220,9 @@ class PythonExporter:
|
|
|
106
220
|
path (str) : Output package path.
|
|
107
221
|
asyncoutput (bool) : If set this builds a register model with async callbacks
|
|
108
222
|
skip_test_case_generation (bool): skip generation the generation of the test cases
|
|
223
|
+
delete_existing_package_content (bool): delete any python files in the package
|
|
224
|
+
location, normally left over from previous
|
|
225
|
+
operations
|
|
109
226
|
|
|
110
227
|
Returns:
|
|
111
228
|
List[str] : modules that have been exported:
|
|
@@ -118,9 +235,10 @@ class PythonExporter:
|
|
|
118
235
|
else:
|
|
119
236
|
top_block = node
|
|
120
237
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
238
|
+
package = _Package(path=path,
|
|
239
|
+
package_name=node.inst_name,
|
|
240
|
+
include_tests=not skip_test_case_generation)
|
|
241
|
+
package.create_empty_package(cleanup=delete_existing_package_content)
|
|
124
242
|
|
|
125
243
|
self._build_node_type_table(top_block)
|
|
126
244
|
|
|
@@ -167,21 +285,19 @@ class PythonExporter:
|
|
|
167
285
|
context.update(self.user_template_context)
|
|
168
286
|
|
|
169
287
|
template = self.jj_env.get_template("addrmap.py.jinja")
|
|
170
|
-
|
|
171
|
-
'reg_model',
|
|
172
|
-
top_block.inst_name + '.py')
|
|
288
|
+
module_path = package.reg_model.child_module_path(top_block.inst_name + '.py')
|
|
173
289
|
|
|
174
|
-
|
|
175
|
-
|
|
290
|
+
with module_path.open('w', encoding='utf-8') as fp:
|
|
291
|
+
stream = template.stream(context)
|
|
292
|
+
stream.dump(fp)
|
|
176
293
|
|
|
177
294
|
if not skip_test_case_generation:
|
|
178
295
|
|
|
179
296
|
# make the top level base class for all the other test, this is what instantes
|
|
180
297
|
# the register model
|
|
181
298
|
template = self.jj_env.get_template("baseclass_tb.py.jinja")
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
'_' + top_block.inst_name + '_test_base.py')
|
|
299
|
+
module_tb_path = package.tests.child_module_path(
|
|
300
|
+
'_' + top_block.inst_name + '_test_base.py')
|
|
185
301
|
|
|
186
302
|
context = {
|
|
187
303
|
'top_node': top_block,
|
|
@@ -189,9 +305,9 @@ class PythonExporter:
|
|
|
189
305
|
'version': __version__
|
|
190
306
|
}
|
|
191
307
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
308
|
+
with module_tb_path.open('w', encoding='utf-8') as fp:
|
|
309
|
+
stream = template.stream(context)
|
|
310
|
+
stream.dump(fp)
|
|
195
311
|
|
|
196
312
|
# make the tests themselves
|
|
197
313
|
template = self.jj_env.get_template("addrmap_tb.py.jinja")
|
|
@@ -208,10 +324,7 @@ class PythonExporter:
|
|
|
208
324
|
RDLWalker(unroll=True).walk(block, owned_elements, skip_top=True)
|
|
209
325
|
|
|
210
326
|
fq_block_name = '_'.join(block.get_path_segments(array_suffix = '_{index:d}_'))
|
|
211
|
-
|
|
212
|
-
module_tb_fqfn = os.path.join(package_path,
|
|
213
|
-
'tests',
|
|
214
|
-
'test_' + fq_block_name + '.py')
|
|
327
|
+
module_tb_path = package.tests.child_module_path('test_' + fq_block_name + '.py')
|
|
215
328
|
|
|
216
329
|
context = {
|
|
217
330
|
'top_node': top_block,
|
|
@@ -244,8 +357,9 @@ class PythonExporter:
|
|
|
244
357
|
'version': __version__
|
|
245
358
|
}
|
|
246
359
|
|
|
247
|
-
|
|
248
|
-
|
|
360
|
+
with module_tb_path.open('w', encoding='utf-8') as fp:
|
|
361
|
+
stream = template.stream(context)
|
|
362
|
+
stream.dump(fp)
|
|
249
363
|
|
|
250
364
|
return top_block.inst_name
|
|
251
365
|
|
|
@@ -291,49 +405,6 @@ class PythonExporter:
|
|
|
291
405
|
else:
|
|
292
406
|
self.node_type_name[child_inst] = cand_type_name
|
|
293
407
|
|
|
294
|
-
@staticmethod
|
|
295
|
-
def _create_empty_package(package_path:str,
|
|
296
|
-
skip_test_case_generation: bool) -> None:
|
|
297
|
-
"""
|
|
298
|
-
create the directories and __init__.py files associated with the exported package
|
|
299
|
-
|
|
300
|
-
Args:
|
|
301
|
-
package_path: directory for the package output
|
|
302
|
-
skip_test_case_generation: skip the generation of the test folders
|
|
303
|
-
|
|
304
|
-
Returns:
|
|
305
|
-
None
|
|
306
|
-
|
|
307
|
-
"""
|
|
308
|
-
|
|
309
|
-
Path(package_path).mkdir(parents=True, exist_ok=True)
|
|
310
|
-
Path(os.path.join(package_path, 'reg_model')).mkdir(parents=True, exist_ok=True)
|
|
311
|
-
if not skip_test_case_generation:
|
|
312
|
-
Path(os.path.join(package_path, 'tests')).mkdir(parents=True, exist_ok=True)
|
|
313
|
-
Path(os.path.join(package_path, 'lib')).mkdir(parents=True, exist_ok=True)
|
|
314
|
-
|
|
315
|
-
module_fqfn = os.path.join(package_path, 'reg_model', '__init__.py')
|
|
316
|
-
with open(module_fqfn, 'w', encoding='utf-8') as fid:
|
|
317
|
-
fid.write('pass\n')
|
|
318
|
-
if not skip_test_case_generation:
|
|
319
|
-
module_fqfn = os.path.join(package_path, 'tests', '__init__.py')
|
|
320
|
-
with open(module_fqfn, 'w', encoding='utf-8') as fid:
|
|
321
|
-
fid.write('pass\n')
|
|
322
|
-
module_fqfn = os.path.join(package_path, '__init__.py')
|
|
323
|
-
with open(module_fqfn, 'w', encoding='utf-8') as fid:
|
|
324
|
-
fid.write('pass\n')
|
|
325
|
-
|
|
326
|
-
template_package = os.path.join(os.path.dirname(__file__),
|
|
327
|
-
'lib')
|
|
328
|
-
files_in_package = glob(os.path.join(template_package,'*.py'))
|
|
329
|
-
|
|
330
|
-
for file_in_package in files_in_package:
|
|
331
|
-
filename = os.path.basename(file_in_package)
|
|
332
|
-
copyfile(src=os.path.join(template_package,
|
|
333
|
-
filename),
|
|
334
|
-
dst=os.path.join(package_path,
|
|
335
|
-
'lib',
|
|
336
|
-
filename))
|
|
337
408
|
|
|
338
409
|
def _raise_template_error(self, message: str) -> NoReturn:
|
|
339
410
|
"""
|