mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
format chore
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import ast
|
||||
import ctypes
|
||||
import logging
|
||||
|
||||
from llvmlite import ir
|
||||
@ -246,12 +245,16 @@ def _allocate_for_attribute(builder, var_name, rval, local_sym_tab, structs_sym_
|
||||
# Handle vmlinux struct field access
|
||||
vmlinux_struct_name = struct_type.__name__
|
||||
if not VmlinuxHandlerRegistry.has_field(vmlinux_struct_name, field_name):
|
||||
logger.error(f"Field '{field_name}' not found in vmlinux struct '{vmlinux_struct_name}'")
|
||||
logger.error(
|
||||
f"Field '{field_name}' not found in vmlinux struct '{vmlinux_struct_name}'"
|
||||
)
|
||||
return
|
||||
|
||||
field_type: tuple[ir.GlobalVariable, Field] = VmlinuxHandlerRegistry.get_field_type(vmlinux_struct_name, field_name)
|
||||
field_type: tuple[ir.GlobalVariable, Field] = (
|
||||
VmlinuxHandlerRegistry.get_field_type(vmlinux_struct_name, field_name)
|
||||
)
|
||||
field_ir, field = field_type
|
||||
#TODO: For now, we only support integer type allocations.
|
||||
# TODO: For now, we only support integer type allocations.
|
||||
|
||||
# loaded_value = builder.load(field_ir, align=8)
|
||||
# #TODO: fatal flaw that this always assumes first argument of function to be the context of what this gets.
|
||||
@ -270,7 +273,9 @@ def _allocate_for_attribute(builder, var_name, rval, local_sym_tab, structs_sym_
|
||||
var = _allocate_with_type(builder, var_name, actual_ir_type)
|
||||
local_sym_tab[var_name] = LocalSymbol(var, actual_ir_type, field)
|
||||
|
||||
logger.info(f"Pre-allocated {var_name} from vmlinux struct {vmlinux_struct_name}.{field_name}")
|
||||
logger.info(
|
||||
f"Pre-allocated {var_name} from vmlinux struct {vmlinux_struct_name}.{field_name}"
|
||||
)
|
||||
return
|
||||
else:
|
||||
logger.error(f"Struct type '{struct_type}' not found")
|
||||
|
||||
@ -72,8 +72,13 @@ def _handle_attribute_expr(
|
||||
if var_name in local_sym_tab:
|
||||
var_ptr, var_type, var_metadata = local_sym_tab[var_name]
|
||||
logger.info(f"Loading attribute {attr_name} from variable {var_name}")
|
||||
logger.info(f"Variable type: {var_type}, Variable ptr: {var_ptr}, Variable Metadata: {var_metadata}")
|
||||
if hasattr(var_metadata, "__module__") and var_metadata.__module__ == "vmlinux":
|
||||
logger.info(
|
||||
f"Variable type: {var_type}, Variable ptr: {var_ptr}, Variable Metadata: {var_metadata}"
|
||||
)
|
||||
if (
|
||||
hasattr(var_metadata, "__module__")
|
||||
and var_metadata.__module__ == "vmlinux"
|
||||
):
|
||||
# Try vmlinux handler when var_metadata is not a string, but has a module attribute.
|
||||
# This has been done to keep everything separate in vmlinux struct handling.
|
||||
vmlinux_result = VmlinuxHandlerRegistry.handle_attribute(
|
||||
|
||||
@ -20,7 +20,8 @@ from pythonbpf.assign_pass import (
|
||||
from pythonbpf.allocation_pass import (
|
||||
handle_assign_allocation,
|
||||
allocate_temp_pool,
|
||||
create_targets_and_rvals, LocalSymbol,
|
||||
create_targets_and_rvals,
|
||||
LocalSymbol,
|
||||
)
|
||||
|
||||
from .return_utils import handle_none_return, handle_xdp_return, is_xdp_name
|
||||
@ -347,12 +348,16 @@ def process_func_body(
|
||||
resolved_type = VmlinuxHandlerRegistry.get_struct_type(
|
||||
context_type_name
|
||||
)
|
||||
context_type = LocalSymbol(None, ir.PointerType(resolved_type), resolved_type)
|
||||
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)
|
||||
context_type = LocalSymbol(
|
||||
None, ir.PointerType(resolved_type), resolved_type
|
||||
)
|
||||
except Exception:
|
||||
raise TypeError(f"Type '{context_type_name}' not declared")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user