summaryrefslogtreecommitdiff
path: root/lib9p/types.gen
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-02 12:44:41 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-02 12:44:41 -0600
commit50cfe77ace4caa424352a163f90bbf7a684b60d6 (patch)
treeeec52aca00a7dada9335cef9f3f6555b4039c851 /lib9p/types.gen
parentada828fc3eaf9891e1bbb6503106d36ef53b6c8a (diff)
more bitfield
Diffstat (limited to 'lib9p/types.gen')
-rwxr-xr-xlib9p/types.gen13
1 files changed, 12 insertions, 1 deletions
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