|
7 | 7 | reset_scratch_pool, |
8 | 8 | ) |
9 | 9 | from pythonbpf.type_deducer import ctypes_to_ir |
10 | | -from pythonbpf.expr import eval_expr, handle_expr, convert_to_bool |
| 10 | +from pythonbpf.expr import ( |
| 11 | + eval_expr, |
| 12 | + handle_expr, |
| 13 | + convert_to_bool, |
| 14 | + VmlinuxHandlerRegistry, |
| 15 | +) |
11 | 16 | from pythonbpf.assign_pass import ( |
12 | 17 | handle_variable_assignment, |
13 | 18 | handle_struct_field_assignment, |
@@ -337,6 +342,35 @@ def process_func_body( |
337 | 342 | structs_sym_tab, |
338 | 343 | ) |
339 | 344 |
|
| 345 | + # Add the context parameter (first function argument) to the local symbol table |
| 346 | + if func_node.args.args and len(func_node.args.args) > 0: |
| 347 | + context_arg = func_node.args.args[0] |
| 348 | + context_name = context_arg.arg |
| 349 | + |
| 350 | + if hasattr(context_arg, "annotation") and context_arg.annotation: |
| 351 | + if isinstance(context_arg.annotation, ast.Name): |
| 352 | + context_type_name = context_arg.annotation.id |
| 353 | + elif isinstance(context_arg.annotation, ast.Attribute): |
| 354 | + context_type_name = context_arg.annotation.attr |
| 355 | + else: |
| 356 | + raise TypeError( |
| 357 | + f"Unsupported annotation type: {ast.dump(context_arg.annotation)}" |
| 358 | + ) |
| 359 | + if VmlinuxHandlerRegistry.is_vmlinux_struct(context_type_name): |
| 360 | + resolved_type = VmlinuxHandlerRegistry.get_struct_type( |
| 361 | + context_type_name |
| 362 | + ) |
| 363 | + context_type = {"type": ir.PointerType(resolved_type), "ptr": True} |
| 364 | + else: |
| 365 | + try: |
| 366 | + resolved_type = ctypes_to_ir(context_type_name) |
| 367 | + context_type = {"type": ir.PointerType(resolved_type), "ptr": True} |
| 368 | + except Exception: |
| 369 | + raise TypeError(f"Type '{context_type_name}' not declared") |
| 370 | + |
| 371 | + local_sym_tab[context_name] = context_type |
| 372 | + logger.info(f"Added argument '{context_name}' to local symbol table") |
| 373 | + |
340 | 374 | logger.info(f"Local symbol table: {local_sym_tab.keys()}") |
341 | 375 |
|
342 | 376 | for stmt in func_node.body: |
|
0 commit comments