mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
remove compile error on normal c_void_p in arg and separate localsymbol to avoid circular dep
This commit is contained in:
@ -2,8 +2,7 @@ import ast
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from llvmlite import ir
|
from llvmlite import ir
|
||||||
from dataclasses import dataclass
|
from .local_symbol import LocalSymbol
|
||||||
from typing import Any
|
|
||||||
from pythonbpf.helper import HelperHandlerRegistry
|
from pythonbpf.helper import HelperHandlerRegistry
|
||||||
from pythonbpf.vmlinux_parser.dependency_node import Field
|
from pythonbpf.vmlinux_parser.dependency_node import Field
|
||||||
from .expr import VmlinuxHandlerRegistry
|
from .expr import VmlinuxHandlerRegistry
|
||||||
@ -12,18 +11,6 @@ from pythonbpf.type_deducer import ctypes_to_ir
|
|||||||
logger = logging.getLogger(__name__)
|
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):
|
def create_targets_and_rvals(stmt):
|
||||||
"""Create lists of targets and right-hand values from an assignment statement."""
|
"""Create lists of targets and right-hand values from an assignment statement."""
|
||||||
if isinstance(stmt.targets[0], ast.Tuple):
|
if isinstance(stmt.targets[0], ast.Tuple):
|
||||||
|
|||||||
@ -351,18 +351,8 @@ def process_func_body(
|
|||||||
context_type = LocalSymbol(
|
context_type = LocalSymbol(
|
||||||
None, ir.PointerType(resolved_type), resolved_type
|
None, ir.PointerType(resolved_type), resolved_type
|
||||||
)
|
)
|
||||||
else:
|
local_sym_tab[context_name] = context_type
|
||||||
try:
|
logger.info(f"Added argument '{context_name}' to local symbol table")
|
||||||
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")
|
|
||||||
|
|
||||||
# pre-allocate dynamic variables
|
# pre-allocate dynamic variables
|
||||||
local_sym_tab = allocate_mem(
|
local_sym_tab = allocate_mem(
|
||||||
|
|||||||
15
pythonbpf/local_symbol.py
Normal file
15
pythonbpf/local_symbol.py
Normal file
@ -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
|
||||||
@ -1,6 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from llvmlite import ir
|
from llvmlite import ir
|
||||||
|
|
||||||
|
from pythonbpf.local_symbol import LocalSymbol
|
||||||
from pythonbpf.vmlinux_parser.assignment_info import AssignmentType
|
from pythonbpf.vmlinux_parser.assignment_info import AssignmentType
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -88,10 +89,12 @@ class VmlinuxHandler:
|
|||||||
):
|
):
|
||||||
"""Handle access to vmlinux struct fields"""
|
"""Handle access to vmlinux struct fields"""
|
||||||
if struct_var_name in local_sym_tab:
|
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(
|
logger.info(
|
||||||
f"Attempting to access field {field_name} of possible vmlinux struct {struct_var_name}"
|
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 pointer to field and field type
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user