From 30bcfcbbd00313c8e3b43947e27f6c6d87c1eb75 Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Fri, 24 Oct 2025 03:08:22 +0530 Subject: [PATCH] remove compile error on normal c_void_p in arg and separate localsymbol to avoid circular dep --- pythonbpf/allocation_pass.py | 15 +-------------- pythonbpf/functions/functions_pass.py | 14 ++------------ pythonbpf/local_symbol.py | 15 +++++++++++++++ .../vmlinux_parser/vmlinux_exports_handler.py | 5 ++++- 4 files changed, 22 insertions(+), 27 deletions(-) create mode 100644 pythonbpf/local_symbol.py diff --git a/pythonbpf/allocation_pass.py b/pythonbpf/allocation_pass.py index 4fe3945..44d74fc 100644 --- a/pythonbpf/allocation_pass.py +++ b/pythonbpf/allocation_pass.py @@ -2,8 +2,7 @@ import ast import logging from llvmlite import ir -from dataclasses import dataclass -from typing import Any +from .local_symbol import LocalSymbol from pythonbpf.helper import HelperHandlerRegistry from pythonbpf.vmlinux_parser.dependency_node import Field from .expr import VmlinuxHandlerRegistry @@ -12,18 +11,6 @@ from pythonbpf.type_deducer import ctypes_to_ir logger = logging.getLogger(__name__) -@dataclass -class LocalSymbol: - var: ir.AllocaInstr - ir_type: ir.Type - metadata: Any = None - - def __iter__(self): - yield self.var - yield self.ir_type - yield self.metadata - - def create_targets_and_rvals(stmt): """Create lists of targets and right-hand values from an assignment statement.""" if isinstance(stmt.targets[0], ast.Tuple): diff --git a/pythonbpf/functions/functions_pass.py b/pythonbpf/functions/functions_pass.py index 9ef97bf..1cf3577 100644 --- a/pythonbpf/functions/functions_pass.py +++ b/pythonbpf/functions/functions_pass.py @@ -351,18 +351,8 @@ def process_func_body( context_type = LocalSymbol( None, ir.PointerType(resolved_type), resolved_type ) - else: - try: - resolved_type = ctypes_to_ir(context_type_name) - logger.error("THIS SHOULD NOT HAPPEN. I THINK. PROBABLY.") - context_type = LocalSymbol( - None, ir.PointerType(resolved_type), resolved_type - ) - except Exception: - raise TypeError(f"Type '{context_type_name}' not declared") - - local_sym_tab[context_name] = context_type - logger.info(f"Added argument '{context_name}' to local symbol table") + local_sym_tab[context_name] = context_type + logger.info(f"Added argument '{context_name}' to local symbol table") # pre-allocate dynamic variables local_sym_tab = allocate_mem( diff --git a/pythonbpf/local_symbol.py b/pythonbpf/local_symbol.py new file mode 100644 index 0000000..ccef9d2 --- /dev/null +++ b/pythonbpf/local_symbol.py @@ -0,0 +1,15 @@ +import llvmlite.ir as ir +from dataclasses import dataclass +from typing import Any + + +@dataclass +class LocalSymbol: + var: ir.AllocaInstr + ir_type: ir.Type + metadata: Any = None + + def __iter__(self): + yield self.var + yield self.ir_type + yield self.metadata diff --git a/pythonbpf/vmlinux_parser/vmlinux_exports_handler.py b/pythonbpf/vmlinux_parser/vmlinux_exports_handler.py index 3f65506..4a78316 100644 --- a/pythonbpf/vmlinux_parser/vmlinux_exports_handler.py +++ b/pythonbpf/vmlinux_parser/vmlinux_exports_handler.py @@ -1,6 +1,7 @@ import logging from llvmlite import ir +from pythonbpf.local_symbol import LocalSymbol from pythonbpf.vmlinux_parser.assignment_info import AssignmentType logger = logging.getLogger(__name__) @@ -88,10 +89,12 @@ class VmlinuxHandler: ): """Handle access to vmlinux struct fields""" if struct_var_name in local_sym_tab: - var_info = local_sym_tab[struct_var_name] + var_info: LocalSymbol = local_sym_tab[struct_var_name] logger.info( f"Attempting to access field {field_name} of possible vmlinux struct {struct_var_name}" ) + print(var_info.ir_type) + print(self.get_field_type(struct_var_name, field_name)) # Return pointer to field and field type return None else: