Core: Give every symbol kind a common Symbol base class

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
This commit is contained in:
Pragyansh Chaturvedi
2026-09-03 11:30:21 +05:30
parent 2b77c406de
commit 526f113a5a
9 changed files with 71 additions and 52 deletions

View File

@ -50,7 +50,12 @@ def create_bpf_map(compilation_context, map_name, map_params):
map_global.align = 8
logger.info(f"Created BPF map: {map_name} with params {map_params}")
return MapSymbol(type=map_params["type"], sym=map_global, params=map_params)
return MapSymbol(
var=map_global,
ir_type=map_global.value_type,
type=map_params["type"],
params=map_params,
)
def _parse_map_params(rval, expected_args=None):
@ -112,7 +117,7 @@ def process_ringbuf_map(map_name, rval, compilation_context):
map_global = create_bpf_map(compilation_context, map_name, map_params)
create_ringbuf_debug_info(
compilation_context,
map_global.sym,
map_global.var,
map_name,
map_params,
)
@ -131,7 +136,7 @@ def process_hash_map(map_name, rval, compilation_context):
# Generate debug info for BTF
create_map_debug_info(
compilation_context,
map_global.sym,
map_global.var,
map_name,
map_params,
)
@ -150,7 +155,7 @@ def process_perf_event_map(map_name, rval, compilation_context):
# Generate debug info for BTF
create_map_debug_info(
compilation_context,
map_global.sym,
map_global.var,
map_name,
map_params,
)

View File

@ -1,16 +1,15 @@
from collections.abc import Callable
from dataclasses import dataclass
from llvmlite import ir
from typing import Any
from .map_types import BPFMapType
from ..symbols import Symbol
@dataclass
class MapSymbol:
"""Class representing a symbol on the map"""
class MapSymbol(Symbol):
"""A BPF map: var is the map's GlobalVariable in the .maps section."""
type: BPFMapType
sym: ir.GlobalVariable
type: BPFMapType = BPFMapType.UNSPEC
params: dict[str, Any] | None = None