Skip to content

Commit

Permalink
Fix hwif type name generation to properly handle parameterized compon…
Browse files Browse the repository at this point in the history
…ent names. #70
  • Loading branch information
amykyta3 committed Oct 12, 2023
1 parent c0e3415 commit 0da6efe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 40 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- 3.9
- "3.10"
- "3.11"
- "3.12"
include:
- os: ubuntu-latest

Expand Down
2 changes: 2 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ sphinx:
python:
install:
- requirements: docs/requirements.txt
- method: pip
path: .
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
include_package_data=True,
python_requires='>=3.6',
install_requires=[
"systemrdl-compiler >= 1.25.1, < 2",
"systemrdl-compiler >= 1.27.0, < 2",
"Jinja2>=2.11",
],
entry_points = {
Expand All @@ -43,6 +43,7 @@
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
Expand Down
49 changes: 10 additions & 39 deletions src/peakrdl_regblock/hwif/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,41 +230,35 @@ def exit_Reg(self, node: 'RegNode') -> None:
#-------------------------------------------------------------------------------
class InputStructGenerator_TypeScope(InputStructGenerator_Hier):
def get_typdef_name(self, node:'Node') -> str:
scope_path = node.inst.get_scope_path("__")
scope_path = node.get_global_type_name("__")
if scope_path is None:
# Unable to determine a reusable type name. Fall back to hierarchical path
# Add prefix to prevent collision when mixing namespace methods
scope_path = "xtern__" + super().get_typdef_name(node)

if isinstance(node, FieldNode):
extra_suffix = get_field_type_name_suffix(node)
else:
extra_suffix = ""

if node.external:
# Node generates alternate external signals
extra_suffix += "__external"
extra_suffix = "__external"
else:
extra_suffix = ""

return f'{scope_path}__{node.type_name}{extra_suffix}__in_t'
return f'{scope_path}{extra_suffix}__in_t'

class OutputStructGenerator_TypeScope(OutputStructGenerator_Hier):
def get_typdef_name(self, node:'Node') -> str:
scope_path = node.inst.get_scope_path("__")
scope_path = node.get_global_type_name("__")
if scope_path is None:
# Unable to determine a reusable type name. Fall back to hierarchical path
# Add prefix to prevent collision when mixing namespace methods
scope_path = "xtern__" + super().get_typdef_name(node)

if isinstance(node, FieldNode):
extra_suffix = get_field_type_name_suffix(node)
else:
extra_suffix = ""

if node.external:
# Node generates alternate external signals
extra_suffix += "__external"
extra_suffix = "__external"
else:
extra_suffix = ""

return f'{scope_path}__{node.type_name}{extra_suffix}__out_t'
return f'{scope_path}{extra_suffix}__out_t'

#-------------------------------------------------------------------------------
class EnumGenerator:
Expand Down Expand Up @@ -302,26 +296,3 @@ def _enum_typedef(self, user_enum: Type['UserEnum']) -> str:
+ ",\n".join(lines)
+ f"\n}} {prefix}_e;"
)


def get_field_type_name_suffix(field: FieldNode) -> str:
"""
Fields may reuse the same type, but end up instantiating different widths
Uniquify the type name further if the field width was overridden when instantiating
"""
if field.inst.original_def is None:
return ""

if field.inst.original_def.type_name is None:
# is an anonymous definition. No extra suffix needed
return ""

if "fieldwidth" in field.list_properties():
# fieldwidth was explicitly set. This type name is already sufficiently distinct
return ""

if field.width == 1:
# field width is the default. Skip suffix
return ""

return f"_w{field.width}"

0 comments on commit 0da6efe

Please sign in to comment.