From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
jiri@resnulli.us, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 05/11] tools: ynl-gen: try to sort the types more intelligently
Date: Wed, 7 Jun 2023 13:23:57 -0700 [thread overview]
Message-ID: <20230607202403.1089925-6-kuba@kernel.org> (raw)
In-Reply-To: <20230607202403.1089925-1-kuba@kernel.org>
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>
---
tools/net/ynl/ynl-gen-c.py | 26 ++++++++++++++++++++++++--
1 file 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 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
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 @@ _C_KW = {
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 @@ _C_KW = {
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)
--
2.40.1
next prev parent reply other threads:[~2023-06-07 20:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-07 20:23 [PATCH net-next 00/11] tools: ynl: generate code for the devlink family Jakub Kicinski
2023-06-07 20:23 ` [PATCH net-next 01/11] netlink: specs: devlink: fill in some details important for C Jakub Kicinski
2023-06-07 20:23 ` [PATCH net-next 02/11] tools: ynl-gen: use enum names in op strmap more carefully Jakub Kicinski
2023-06-07 20:23 ` [PATCH net-next 03/11] tools: ynl-gen: refactor strmap helper generation Jakub Kicinski
2023-06-07 20:23 ` [PATCH net-next 04/11] tools: ynl-gen: enable code gen for directional specs Jakub Kicinski
2023-06-07 20:23 ` Jakub Kicinski [this message]
2023-06-07 20:23 ` [PATCH net-next 06/11] tools: ynl-gen: inherit struct use info Jakub Kicinski
2023-06-07 20:23 ` [PATCH net-next 07/11] tools: ynl-gen: walk nested types in depth Jakub Kicinski
2023-06-07 20:24 ` [PATCH net-next 08/11] tools: ynl-gen: don't generate forward declarations for policies Jakub Kicinski
2023-06-07 20:24 ` [PATCH net-next 09/11] tools: ynl-gen: don't generate forward declarations for policies - regen Jakub Kicinski
2023-06-07 20:24 ` [PATCH net-next 10/11] tools: ynl: generate code for the devlink family Jakub Kicinski
2023-06-08 11:48 ` Simon Horman
2023-06-08 15:53 ` Jakub Kicinski
2023-06-09 7:46 ` Simon Horman
2023-06-07 20:24 ` [PATCH net-next 11/11] tools: ynl: add sample for devlink Jakub Kicinski
2023-06-08 21:10 ` [PATCH net-next 00/11] tools: ynl: generate code for the devlink family patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230607202403.1089925-6-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jiri@resnulli.us \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).