Repair multi-enumerations in one regfile bug

When a regfile did use enumerations from multiple scopes this messed up
the eventual packages because every regfile only assumed 1 scope. This
is fixed now.

TODO: Check what happens if enums are defined in the register scope.
This commit is contained in:
Dennis Potter 2021-09-30 00:11:50 -07:00
parent d3bfdeb3f0
commit 8756945a6d
Signed by: Dennis
GPG Key ID: 186A8AD440942BAF
2 changed files with 29 additions and 37 deletions

View File

@ -303,11 +303,12 @@ class AddrMap(Component):
# First go through all registers in this scope to generate a package
package_rtl = []
enum_rtl = []
rtl_return = dict()
# Need to keep track of enum names since they shall be unique
# per scope
enum_rtl = dict()
enum_rtl[self.name] = []
enum_members = dict()
for i in self.registers.values():
@ -344,27 +345,34 @@ class AddrMap(Component):
max_name_width = max_name_width,
name = var[0]))
enum_rtl.append(
enum_rtl[self.name].append(
AddrMap.templ_dict['enum_declaration']['rtl'].format(
width=value.width-1,
name = key,
enum_var_list = ',\n'.join(variable_list)))
# Invoke get_package_rtl method from regfiles
for regfile in self.regfiles.values():
for key, value in regfile.get_package_rtl().items():
if key in enum_rtl:
enum_rtl[key] = [*enum_rtl[key], *value]
else:
enum_rtl[key] = value
# Create RTL to return
for key, value in enum_rtl.items():
package_rtl =\
AddrMap.templ_dict['package_declaration']['rtl'].format(
name = self.name,
pkg_content = '\n\n'.join(enum_rtl))
name = key,
pkg_content = '\n\n'.join(enum_rtl[key]))
rtl_return[self.name] = AddrMap.add_tabs(
rtl_return[key] = AddrMap.add_tabs(
package_rtl,
tab_width,
real_tabs)
# Invoke get_package_rtl method from regfiles
[rtl_return.update(x.get_package_rtl(tab_width, real_tabs))
for x in self.regfiles.values()]
return rtl_return
def get_regwidth(self) -> int:

View File

@ -200,25 +200,23 @@ class RegFile(Component):
return names
def get_package_rtl(self, tab_width: int = 4, real_tabs = False) -> dict():
def get_package_rtl(self) -> dict():
if not self.config['enums']:
return None
# First go through all registers in this scope to generate a package
package_rtl = []
enum_rtl = []
enum_rtl = dict()
rtl_return = list()
# Need to keep track of enum names since they shall be unique
# per scope
enum_members = dict()
enum_found = False
for i in self.registers.values():
for key, value in i.get_typedefs().items():
if not enum_found:
enum_found = True
scope = value.scope
if value.scope not in enum_rtl:
enum_rtl[value.scope] = []
variable_list = []
@ -241,7 +239,7 @@ class RegFile(Component):
"Exiting...".format(
var[0],
enum_members[var[0]],
"::".join([self.name, key])))
"::".join([value.scope, key])))
sys.exit(1)
@ -252,27 +250,13 @@ class RegFile(Component):
max_name_width = max_name_width,
name = var[0]))
enum_rtl.append(
enum_rtl[value.scope].append(
RegFile.templ_dict['enum_declaration']['rtl'].format(
width=value.width-1,
name = key,
enum_var_list = ',\n'.join(variable_list)))
if enum_found:
package_rtl =\
RegFile.templ_dict['package_declaration']['rtl'].format(
name = scope,
pkg_content = '\n\n'.join(enum_rtl))
return {scope:
RegFile.add_tabs(
package_rtl,
tab_width,
real_tabs)
}
else:
return {None: None}
return enum_rtl
def get_regwidth(self) -> int:
return self.regwidth