mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 18:08:36 +00:00
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
40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
from collections.abc import Callable
|
|
from dataclasses import dataclass
|
|
from typing import Any
|
|
from .map_types import BPFMapType
|
|
from ..symbols import Symbol
|
|
|
|
|
|
@dataclass
|
|
class MapSymbol(Symbol):
|
|
"""A BPF map: var is the map's GlobalVariable in the .maps section."""
|
|
|
|
type: BPFMapType = BPFMapType.UNSPEC
|
|
params: dict[str, Any] | None = None
|
|
|
|
|
|
class MapProcessorRegistry:
|
|
"""Registry for map processor functions"""
|
|
|
|
_processors: dict[str, Callable[..., Any]] = {}
|
|
|
|
@classmethod
|
|
def register(cls, map_type_name):
|
|
"""Decorator to register a processor function for a map type"""
|
|
|
|
def decorator(func):
|
|
cls._processors[map_type_name] = func
|
|
return func
|
|
|
|
return decorator
|
|
|
|
@classmethod
|
|
def get_processor(cls, map_type_name):
|
|
"""Get the processor function for a map type"""
|
|
return cls._processors.get(map_type_name)
|
|
|
|
@classmethod
|
|
def known_types(cls):
|
|
"""Names of every registered map type, for error messages"""
|
|
return list(cls._processors.keys())
|