LocalSymbol, BpfGlobalSymbol and MapSymbol each named the storage behind a
name differently (var, var, sym) and shared no type. They now all derive from
symbols.Symbol, which carries what every symbol has -- the storage pointer
(alloca, GlobalVariable, or None for the context parameter) and its IR type
-- and each subclass adds only what its kind needs: LocalSymbol its metadata
and declared_global flag, BpfGlobalSymbol its ctypes name, MapSymbol its map
type and params. MapSymbol.sym becomes var to match.
local_symbol.py is folded into the new symbols.py. LocalSymbol keeps its
three-field __iter__ for the call sites that tuple-unpack a symbol.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BSDVsZH5NtoASyxB8FCtGU
Reading a context field narrower than a register was hardcoded to
struct_xdp_md's i32 fields in three places that had to agree with each other:
the destination alloca in allocation_pass, the zext in load_ctx_field, and
the store in assign_pass. struct pt_regs' cs and ss are 2 bytes, so a second
special case would have been needed.
Replace all three with the general rule: a context field is loaded at its
natural width and zero-extended to i64, so its destination is i64.
allocation_pass gains the same context discriminator load_ctx_field uses
(a context argument has no alloca of its own), so non-context field reads,
which go through load_struct_field and bpf_probe_read_kernel, keep their
natural width and are untouched.
struct_xdp_md's generated IR is byte-identical, as is every other vmlinux/xdp
test program's; the only diff in the whole corpus remains the four new globals
from the previous commit.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
has_field() consulted hasattr() on the ctypes class while get_field_type()
indexed the parsed members dict. For any member ctypes exposes but the
vmlinux parser never registered, has_field() said True and get_field_type()
then died with a raw KeyError.
Both now consult the parsed members dict, and a lookup that misses raises a
ValueError that distinguishes "no such field" from "field exists in
vmlinux.py but the parser does not support it yet".
get_field_index() additionally derives the index from the ctypes _fields_
list (the C declaration order) instead of the insertion order of the parsed
members dict, so it no longer depends on the two happening to coincide.
No change to generated IR: every vmlinux/xdp test program compiles to a
byte-identical .ll.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>