From 50cfe77ace4caa424352a163f90bbf7a684b60d6 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Wed, 2 Oct 2024 12:44:41 -0600 Subject: more bitfield --- lib9p/types.gen | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib9p/types.gen') diff --git a/lib9p/types.gen b/lib9p/types.gen index 1a2d45a..7d74558 100755 --- a/lib9p/types.gen +++ b/lib9p/types.gen @@ -343,8 +343,19 @@ enum {idprefix}version {{ ret += f"const char *{idprefix}version_str(enum {idprefix}version);\n" ret += """ -/* non-message structs ********************************************************/ +/* non-message types **********************************************************/ """ + for bf in just_bitfields(typs): + ret += "\n" + ret += f"typedef uint{bf.static_size*8}_t {c_typename(idprefix, bf)};\n" + vals = dict([ + *reversed([((k or f"_UNUSED_{v}"), f"1<<{v}") for (v, k) in enumerate(bf.bits)]), + *[(k, v) for (k, v) in bf.aliases.items() if v], + ]) + namewidth = max(len(name) for name in vals) + for name, val in vals.items(): + ret += f"#define {idprefix.upper()}{bf.name.upper()}_{name.ljust(namewidth)} (({c_typename(idprefix, bf)})({val}))\n" + for struct in just_structs_nonmsg(typs): all_the_same = len(struct.members) == 0 or all( m.ver == struct.members[0].ver for m in struct.members -- cgit v1.2.3-2-g168b