Improve control local parameter handling
@@ -54,12 +54,18 @@ for smem in hlir.registers:
-all_locals = unique_everseen([(param.name, format_type(param.type)) for table in hlir.tables for local in table.control.controlLocals["P4Action"] for param in local.parameters.parameters])
+# temp = {action: action.flatmap('parameters.parameters') for action in hlir.tables.flatmap('control.controlLocals').filter('node_type', 'P4Action')}
+
+local_params = unique_everseen(hlir.tables.flatmap('control.controlLocals').filter('node_type', 'P4Action').flatmap('parameters.parameters'))
+all_locals = unique_everseen((param.name, format_type(param.type)) for param in local_params)
all_locals_dict = dict(all_locals)
if len(all_locals) != len(all_locals_dict):
names = [name for name, _type in all_locals]
- dups = unique_everseen([name for name in names if names.count(name) > 1])
- addError("Collecting counters, meters, registers and controls' local variables", "The following names are used with different types, which is currently unsupported: {}".format(", ".join(dups)))
+ dups = unique_everseen(name for name in names if names.count(name) > 1)
+ for dup in dups:
+ dup_types = {f'{format_type(lp.type)}': f'{lp.type.node_type}[{lp.type.size}]' for lp in local_params if lp.name == dup}
+ description = ", ".join(f'{t} aka {dup_types[t]}' for t in dup_types)
+ addError("Collecting local variables of controls", f"Local variable {dup} is used with different types, which is currently unsupported: {description}")
for locname, loctype in all_locals:
#[ $loctype $locname;
