From 69b73003caa507d83a6b90e195ee806dbaf59d4b Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Wed, 15 Oct 2025 04:42:38 +0530 Subject: [PATCH] setup skeleton for offset calculation --- pythonbpf/vmlinux_parser/class_handler.py | 1 + pythonbpf/vmlinux_parser/dependency_node.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/pythonbpf/vmlinux_parser/class_handler.py b/pythonbpf/vmlinux_parser/class_handler.py index cf82e50..ce08530 100644 --- a/pythonbpf/vmlinux_parser/class_handler.py +++ b/pythonbpf/vmlinux_parser/class_handler.py @@ -71,6 +71,7 @@ def process_vmlinux_post_ast( if len(field_elem) == 2: field_name, field_type = field_elem elif len(field_elem) == 3: + raise NotImplementedError("Bitfields are not supported in the current version") field_name, field_type, bitfield_size = field_elem field_table[field_name] = [field_type, bitfield_size] elif hasattr(class_obj, "__annotations__"): diff --git a/pythonbpf/vmlinux_parser/dependency_node.py b/pythonbpf/vmlinux_parser/dependency_node.py index 7f32323..8a512cd 100644 --- a/pythonbpf/vmlinux_parser/dependency_node.py +++ b/pythonbpf/vmlinux_parser/dependency_node.py @@ -13,6 +13,7 @@ class Field: containing_type: Optional[Any] type_size: Optional[int] bitfield_size: Optional[int] + offset: int value: Any = None ready: bool = False @@ -60,6 +61,10 @@ class Field: if mark_ready: self.ready = True + def set_offset(self, offset: int) -> None: + """Set the offset of this field""" + self.offset = offset + @dataclass class DependencyNode: @@ -109,6 +114,7 @@ class DependencyNode: depends_on: Optional[list[str]] = None fields: Dict[str, Field] = field(default_factory=dict) _ready_cache: Optional[bool] = field(default=None, repr=False) + current_offset: int = 0 def add_field( self, @@ -120,6 +126,7 @@ class DependencyNode: ctype_complex_type: Optional[int] = None, bitfield_size: Optional[int] = None, ready: bool = False, + offset: int = 0, ) -> None: """Add a field to the node with an optional initial value and readiness state.""" if self.depends_on is None: @@ -133,6 +140,7 @@ class DependencyNode: type_size=type_size, ctype_complex_type=ctype_complex_type, bitfield_size=bitfield_size, + offset=offset ) # Invalidate readiness cache self._ready_cache = None @@ -209,9 +217,14 @@ class DependencyNode: raise KeyError(f"Field '{name}' does not exist in node '{self.name}'") self.fields[name].set_ready(is_ready) + self.fields[name].set_offset(self.current_offset) + self.current_offset += self._calculate_size(name) + # Invalidate readiness cache self._ready_cache = None + def _calculate_size(self, name: str) -> int: + pass @property def is_ready(self) -> bool: """Check if the node is ready (all fields are ready)."""