summaryrefslogtreecommitdiff
path: root/lib9p/idl.gen
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-17 14:31:03 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-17 14:31:03 -0600
commitf132dab76a07473d41e14f5f4fb1857a3229ec6a (patch)
tree621a8f1ae6cb15d360cd47c0bccd08a1c2226f4e /lib9p/idl.gen
parenta1fb6a6103cc7d38d54270bcdb9779982d329c9e (diff)
libmisc
Diffstat (limited to 'lib9p/idl.gen')
-rwxr-xr-xlib9p/idl.gen56
1 files changed, 26 insertions, 30 deletions
diff --git a/lib9p/idl.gen b/lib9p/idl.gen
index e911ed7..a353a86 100755
--- a/lib9p/idl.gen
+++ b/lib9p/idl.gen
@@ -636,8 +636,6 @@ enum {idprefix}version {{
ret += f"\t{idprefix.upper()}TYP_{msg.name.ljust(namewidth)} = {msg.msgid},\n"
ret += ifdef_pop(0)
ret += "};\n"
- ret += "\n"
- ret += f"const char *{idprefix}msg_type_str(enum {idprefix}msg_type);\n"
for msg in [msg for msg in typs if isinstance(msg, Message)]:
ret += "\n"
@@ -717,20 +715,6 @@ const char *{idprefix}version_str(enum {idprefix}version ver) {{
assert(0 <= ver && ver < {c_ver_enum('NUM')});
return version_strs[ver];
}}
-
-static const char *msg_type_strs[0x100] = {{
-"""
- id2name: dict[int, str] = {}
- for msg in [msg for msg in typs if isinstance(msg, Message)]:
- id2name[msg.msgid] = msg.name
- for n in range(0, 0x100):
- ret += '\t[0x{:02X}] = "{}",\n'.format(n, id2name.get(n, "0x{:02X}".format(n)))
- ret += "};\n"
- ret += f"""
-const char *{idprefix}msg_type_str(enum {idprefix}msg_type typ) {{
- assert(0 <= typ && typ <= 0xFF);
- return msg_type_strs[typ];
-}}
"""
# validate_* ###############################################################
@@ -1093,33 +1077,45 @@ static ALWAYS_INLINE bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) {
ret += "}\n"
ret += ifdef_pop(0)
- # vtables / exports ########################################################
+ # tables / exports #########################################################
ret += f"""
-/* vtables / exports **********************************************************/
+/* tables / exports ***********************************************************/
#define _MSG(typ) [{idprefix.upper()}TYP_##typ] = {{ \\
+ .name = #typ, \\
.basesize = sizeof(struct {idprefix}msg_##typ), \\
.validate = validate_##typ, \\
.unmarshal = (_unmarshal_fn_t)unmarshal_##typ, \\
.marshal = (_marshal_fn_t)marshal_##typ, \\
}}
+#define _NONMSG(num) [num] = {{ \\
+ .name = #num, \\
+ }}
-struct _vtable_version _{idprefix}vtables[{c_ver_enum('NUM')}] = {{
+struct _table_version _{idprefix}versions[{c_ver_enum('NUM')}] = {{
"""
-
- ret += f"\t[{c_ver_enum('unknown')}] = {{ .msgs = {{\n"
+ id2typ: dict[int, Message] = {}
for msg in [msg for msg in typs if isinstance(msg, Message)]:
- if msg.name in ["Tversion", "Rversion", "Rerror"]: # SPECIAL
- ret += f"\t\t_MSG({msg.name}),\n"
- ret += "\t}},\n"
+ id2typ[msg.msgid] = msg
- for ver in sorted(versions):
- ret += ifdef_push(1, c_ver_ifdef({ver}))
+ for ver in ["unknown", *sorted(versions)]:
+ if ver != "unknown":
+ ret += ifdef_push(1, c_ver_ifdef({ver}))
ret += f"\t[{c_ver_enum(ver)}] = {{ .msgs = {{\n"
- for msg in [msg for msg in typs if isinstance(msg, Message)]:
- if ver not in msg.in_versions:
- continue
- ret += f"\t\t_MSG({msg.name}),\n"
+
+ for n in range(0, 0x100):
+ xmsg: Message | None = id2typ.get(n, None)
+ if xmsg:
+ if ver == "unknown": # SPECIAL
+ if xmsg.name not in ["Tversion", "Rversion", "Rerror"]:
+ xmsg = None
+ else:
+ if ver not in xmsg.in_versions:
+ xmsg = None
+ if xmsg:
+ ret += f"\t\t_MSG({xmsg.name}),\n"
+ else:
+ ret += "\t\t_NONMSG(0x{:02X}),\n".format(n)
ret += "\t}},\n"
ret += ifdef_pop(0)
ret += "};\n"