diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-02 21:44:27 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-02 21:50:40 -0600 |
commit | ad2027ae26e5d83eb42c9edaa90f7b278f9b0d3d (patch) | |
tree | 696c1d8bca3c8a7b29aa89ec0763b2e2e5c850eb /lib9p/types.gen | |
parent | 06ab37743a3a657178a17d56252794073c00342b (diff) |
lib9p: Exclude the MOUNT bit from masks, align masks
Diffstat (limited to 'lib9p/types.gen')
-rwxr-xr-x | lib9p/types.gen | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/lib9p/types.gen b/lib9p/types.gen index 3e800e8..da99c36 100755 --- a/lib9p/types.gen +++ b/lib9p/types.gen @@ -50,6 +50,16 @@ class Bitfield: def static_size(self) -> int: return int((len(self.bits) + 7) / 8) + def bitname_is_valid(self, bitname: str, ver: str | None = None) -> bool: + assert bitname in self.bits + if not bitname: + return False + if bitname.startswith("_"): + return False + if ver and (ver not in self.names[bitname].ver): + return False + return True + # `msgid/structname = "member1 member2..."` # `structname = "member1 member2..."` @@ -137,7 +147,9 @@ re_structspec = ( re_structspec_cont = r'\s+"(?P<members>[^"]*)"' re_bitfieldspec = r"bitfield\s+(?P<name>\S+)\s+(?P<size>[0-9]+)" re_bitfieldspec_bit = r"(?:\s+|(?P<bitfield>\S+)\s*\+=\s*)(?P<bit>[0-9]+)/(?P<name>\S+)" -re_bitfieldspec_alias = r"(?:\s+|(?P<bitfield>\S+)\s*\+=\s*)(?P<name>\S+)\s*=\s*(?P<val>.*)" +re_bitfieldspec_alias = ( + r"(?:\s+|(?P<bitfield>\S+)\s*\+=\s*)(?P<name>\S+)\s*=\s*(?P<val>.*)" +) def parse_file( @@ -595,7 +607,11 @@ static ALWAYS_INLINE bool _validate_list(struct _validate_ctx *ctx, val.ver == [*typ.names.values()][0].ver for val in typ.names.values() ) - if all_the_same and all(not bit for bit in typ.bits): + if ( + all_the_same + and (len(typ.bits) == typ.static_size * 8) + and all(typ.bitname_is_valid(bitname) for bitname in typ.bits) + ): ret += f"\treturn validate_{typ.static_size}(ctx));\n" else: ret += f"\t if (validate_{typ.static_size}(ctx))\n" @@ -603,19 +619,21 @@ static ALWAYS_INLINE bool _validate_list(struct _validate_ctx *ctx, if all_the_same: ret += ( f"\tstatic const {c_typename(idprefix, typ)} mask = 0b" - + ("".join("1" if b else "0" for b in reversed(typ.bits))) + + "".join( + "1" if typ.bitname_is_valid(bitname) else "0" + for bitname in reversed(typ.bits) + ) + ";\n" ) else: ret += f"\tstatic const {c_typename(idprefix, typ)} masks[{c_verenum(idprefix, 'NUM')}] = {{\n" + verwidth = max(len(ver) for ver in versions) for ver in sorted(versions): ret += ( - f"\t\t[{c_verenum(idprefix, ver)}] = 0b" - + ( - "".join( - "1" if (b and ver in typ.names[b].ver) else "0" - for b in reversed(typ.bits) - ) + f"\t\t[{c_verenum(idprefix, ver)}]{' '*(verwidth-len(ver))} = 0b" + + "".join( + "1" if typ.bitname_is_valid(bitname, ver) else "0" + for bitname in reversed(typ.bits) ) + ",\n" ) |