diff options
author | Jakub Kicinski <kuba@kernel.org> | 2023-06-07 23:23:57 +0300 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2023-06-09 00:01:10 +0300 |
commit | 6afaa0ef9b0e446fde14a1424f2c2858484a3601 (patch) | |
tree | 2b4baf813b8306cc33fdfe932baf4a4a7d1f69f4 /tools/net | |
parent | ff6db4b58c93eada66f58423aa02363f987679c5 (diff) | |
download | linux-6afaa0ef9b0e446fde14a1424f2c2858484a3601.tar.xz |
tools: ynl-gen: try to sort the types more intelligently
We need to sort the structures to avoid the need for forward
declarations. While at it remove the sort of structs when
rendering, it doesn't do anything.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools/net')
-rwxr-xr-x | tools/net/ynl/ynl-gen-c.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py index 7b3e79e17c01..d9c74a678df8 100755 --- a/tools/net/ynl/ynl-gen-c.py +++ b/tools/net/ynl/ynl-gen-c.py @@ -875,6 +875,28 @@ class Family(SpecFamily): inherit.add('idx') self.pure_nested_structs[nested].set_inherited(inherit) + # Try to reorder according to dependencies + pns_key_list = list(self.pure_nested_structs.keys()) + pns_key_seen = set() + rounds = len(pns_key_list)**2 # it's basically bubble sort + for _ in range(rounds): + if len(pns_key_list) == 0: + break + name = pns_key_list.pop(0) + finished = True + for _, spec in self.attr_sets[name].items(): + if 'nested-attributes' in spec: + if spec['nested-attributes'] not in pns_key_seen: + # Dicts are sorted, this will make struct last + struct = self.pure_nested_structs.pop(name) + self.pure_nested_structs[name] = struct + finished = False + break + if finished: + pns_key_seen.add(name) + else: + pns_key_list.append(name) + def _load_all_notify(self): for op_name, op in self.ops.items(): if not op: @@ -2379,7 +2401,7 @@ def main(): cw.nl() cw.p('/* Common nested types */') - for attr_set, struct in sorted(parsed.pure_nested_structs.items()): + for attr_set, struct in parsed.pure_nested_structs.items(): ri = RenderInfo(cw, parsed, args.mode, "", "", "", attr_set) print_type_full(ri, struct) @@ -2448,7 +2470,7 @@ def main(): put_typol(cw, struct) cw.p('/* Common nested types */') - for attr_set, struct in sorted(parsed.pure_nested_structs.items()): + for attr_set, struct in parsed.pure_nested_structs.items(): ri = RenderInfo(cw, parsed, args.mode, "", "", "", attr_set) free_rsp_nested(ri, struct) |