mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
setup skeleton for offset calculation
This commit is contained in:
@ -71,6 +71,7 @@ def process_vmlinux_post_ast(
|
|||||||
if len(field_elem) == 2:
|
if len(field_elem) == 2:
|
||||||
field_name, field_type = field_elem
|
field_name, field_type = field_elem
|
||||||
elif len(field_elem) == 3:
|
elif len(field_elem) == 3:
|
||||||
|
raise NotImplementedError("Bitfields are not supported in the current version")
|
||||||
field_name, field_type, bitfield_size = field_elem
|
field_name, field_type, bitfield_size = field_elem
|
||||||
field_table[field_name] = [field_type, bitfield_size]
|
field_table[field_name] = [field_type, bitfield_size]
|
||||||
elif hasattr(class_obj, "__annotations__"):
|
elif hasattr(class_obj, "__annotations__"):
|
||||||
|
|||||||
@ -13,6 +13,7 @@ class Field:
|
|||||||
containing_type: Optional[Any]
|
containing_type: Optional[Any]
|
||||||
type_size: Optional[int]
|
type_size: Optional[int]
|
||||||
bitfield_size: Optional[int]
|
bitfield_size: Optional[int]
|
||||||
|
offset: int
|
||||||
value: Any = None
|
value: Any = None
|
||||||
ready: bool = False
|
ready: bool = False
|
||||||
|
|
||||||
@ -60,6 +61,10 @@ class Field:
|
|||||||
if mark_ready:
|
if mark_ready:
|
||||||
self.ready = True
|
self.ready = True
|
||||||
|
|
||||||
|
def set_offset(self, offset: int) -> None:
|
||||||
|
"""Set the offset of this field"""
|
||||||
|
self.offset = offset
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class DependencyNode:
|
class DependencyNode:
|
||||||
@ -109,6 +114,7 @@ class DependencyNode:
|
|||||||
depends_on: Optional[list[str]] = None
|
depends_on: Optional[list[str]] = None
|
||||||
fields: Dict[str, Field] = field(default_factory=dict)
|
fields: Dict[str, Field] = field(default_factory=dict)
|
||||||
_ready_cache: Optional[bool] = field(default=None, repr=False)
|
_ready_cache: Optional[bool] = field(default=None, repr=False)
|
||||||
|
current_offset: int = 0
|
||||||
|
|
||||||
def add_field(
|
def add_field(
|
||||||
self,
|
self,
|
||||||
@ -120,6 +126,7 @@ class DependencyNode:
|
|||||||
ctype_complex_type: Optional[int] = None,
|
ctype_complex_type: Optional[int] = None,
|
||||||
bitfield_size: Optional[int] = None,
|
bitfield_size: Optional[int] = None,
|
||||||
ready: bool = False,
|
ready: bool = False,
|
||||||
|
offset: int = 0,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Add a field to the node with an optional initial value and readiness state."""
|
"""Add a field to the node with an optional initial value and readiness state."""
|
||||||
if self.depends_on is None:
|
if self.depends_on is None:
|
||||||
@ -133,6 +140,7 @@ class DependencyNode:
|
|||||||
type_size=type_size,
|
type_size=type_size,
|
||||||
ctype_complex_type=ctype_complex_type,
|
ctype_complex_type=ctype_complex_type,
|
||||||
bitfield_size=bitfield_size,
|
bitfield_size=bitfield_size,
|
||||||
|
offset=offset
|
||||||
)
|
)
|
||||||
# Invalidate readiness cache
|
# Invalidate readiness cache
|
||||||
self._ready_cache = None
|
self._ready_cache = None
|
||||||
@ -209,9 +217,14 @@ class DependencyNode:
|
|||||||
raise KeyError(f"Field '{name}' does not exist in node '{self.name}'")
|
raise KeyError(f"Field '{name}' does not exist in node '{self.name}'")
|
||||||
|
|
||||||
self.fields[name].set_ready(is_ready)
|
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
|
# Invalidate readiness cache
|
||||||
self._ready_cache = None
|
self._ready_cache = None
|
||||||
|
|
||||||
|
def _calculate_size(self, name: str) -> int:
|
||||||
|
pass
|
||||||
@property
|
@property
|
||||||
def is_ready(self) -> bool:
|
def is_ready(self) -> bool:
|
||||||
"""Check if the node is ready (all fields are ready)."""
|
"""Check if the node is ready (all fields are ready)."""
|
||||||
|
|||||||
Reference in New Issue
Block a user