Fix hwif type name generation to properly handle parameterized component names. #70

This commit is contained in:
Alex Mykyta
2023-10-11 21:58:10 -07:00
parent c0e341579c
commit 0da6efe85c
4 changed files with 15 additions and 40 deletions

View File

@@ -23,6 +23,7 @@ jobs:
- 3.9 - 3.9
- "3.10" - "3.10"
- "3.11" - "3.11"
- "3.12"
include: include:
- os: ubuntu-latest - os: ubuntu-latest

View File

@@ -13,3 +13,5 @@ sphinx:
python: python:
install: install:
- requirements: docs/requirements.txt - requirements: docs/requirements.txt
- method: pip
path: .

View File

@@ -24,7 +24,7 @@ setuptools.setup(
include_package_data=True, include_package_data=True,
python_requires='>=3.6', python_requires='>=3.6',
install_requires=[ install_requires=[
"systemrdl-compiler >= 1.25.1, < 2", "systemrdl-compiler >= 1.27.0, < 2",
"Jinja2>=2.11", "Jinja2>=2.11",
], ],
entry_points = { entry_points = {
@@ -43,6 +43,7 @@ setuptools.setup(
"Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3 :: Only",
"Intended Audience :: Developers", "Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",

View File

@@ -230,41 +230,35 @@ class OutputStructGenerator_Hier(HWIFStructGenerator):
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
class InputStructGenerator_TypeScope(InputStructGenerator_Hier): class InputStructGenerator_TypeScope(InputStructGenerator_Hier):
def get_typdef_name(self, node:'Node') -> str: 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: if scope_path is None:
# Unable to determine a reusable type name. Fall back to hierarchical path # Unable to determine a reusable type name. Fall back to hierarchical path
# Add prefix to prevent collision when mixing namespace methods # Add prefix to prevent collision when mixing namespace methods
scope_path = "xtern__" + super().get_typdef_name(node) scope_path = "xtern__" + super().get_typdef_name(node)
if isinstance(node, FieldNode): if node.external:
extra_suffix = get_field_type_name_suffix(node) # Node generates alternate external signals
extra_suffix = "__external"
else: else:
extra_suffix = "" extra_suffix = ""
if node.external: return f'{scope_path}{extra_suffix}__in_t'
# Node generates alternate external signals
extra_suffix += "__external"
return f'{scope_path}__{node.type_name}{extra_suffix}__in_t'
class OutputStructGenerator_TypeScope(OutputStructGenerator_Hier): class OutputStructGenerator_TypeScope(OutputStructGenerator_Hier):
def get_typdef_name(self, node:'Node') -> str: 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: if scope_path is None:
# Unable to determine a reusable type name. Fall back to hierarchical path # Unable to determine a reusable type name. Fall back to hierarchical path
# Add prefix to prevent collision when mixing namespace methods # Add prefix to prevent collision when mixing namespace methods
scope_path = "xtern__" + super().get_typdef_name(node) scope_path = "xtern__" + super().get_typdef_name(node)
if isinstance(node, FieldNode): if node.external:
extra_suffix = get_field_type_name_suffix(node) # Node generates alternate external signals
extra_suffix = "__external"
else: else:
extra_suffix = "" extra_suffix = ""
if node.external: return f'{scope_path}{extra_suffix}__out_t'
# Node generates alternate external signals
extra_suffix += "__external"
return f'{scope_path}__{node.type_name}{extra_suffix}__out_t'
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
class EnumGenerator: class EnumGenerator:
@@ -302,26 +296,3 @@ class EnumGenerator:
+ ",\n".join(lines) + ",\n".join(lines)
+ f"\n}} {prefix}_e;" + 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}"