Skip to content

Commit 30bcfcb

Browse files
remove compile error on normal c_void_p in arg and separate localsymbol to avoid circular dep
1 parent f18a439 commit 30bcfcb

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

pythonbpf/allocation_pass.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import logging
33

44
from llvmlite import ir
5-
from dataclasses import dataclass
6-
from typing import Any
5+
from .local_symbol import LocalSymbol
76
from pythonbpf.helper import HelperHandlerRegistry
87
from pythonbpf.vmlinux_parser.dependency_node import Field
98
from .expr import VmlinuxHandlerRegistry
@@ -12,18 +11,6 @@
1211
logger = logging.getLogger(__name__)
1312

1413

15-
@dataclass
16-
class LocalSymbol:
17-
var: ir.AllocaInstr
18-
ir_type: ir.Type
19-
metadata: Any = None
20-
21-
def __iter__(self):
22-
yield self.var
23-
yield self.ir_type
24-
yield self.metadata
25-
26-
2714
def create_targets_and_rvals(stmt):
2815
"""Create lists of targets and right-hand values from an assignment statement."""
2916
if isinstance(stmt.targets[0], ast.Tuple):

pythonbpf/functions/functions_pass.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -351,18 +351,8 @@ def process_func_body(
351351
context_type = LocalSymbol(
352352
None, ir.PointerType(resolved_type), resolved_type
353353
)
354-
else:
355-
try:
356-
resolved_type = ctypes_to_ir(context_type_name)
357-
logger.error("THIS SHOULD NOT HAPPEN. I THINK. PROBABLY.")
358-
context_type = LocalSymbol(
359-
None, ir.PointerType(resolved_type), resolved_type
360-
)
361-
except Exception:
362-
raise TypeError(f"Type '{context_type_name}' not declared")
363-
364-
local_sym_tab[context_name] = context_type
365-
logger.info(f"Added argument '{context_name}' to local symbol table")
354+
local_sym_tab[context_name] = context_type
355+
logger.info(f"Added argument '{context_name}' to local symbol table")
366356

367357
# pre-allocate dynamic variables
368358
local_sym_tab = allocate_mem(

pythonbpf/local_symbol.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import llvmlite.ir as ir
2+
from dataclasses import dataclass
3+
from typing import Any
4+
5+
6+
@dataclass
7+
class LocalSymbol:
8+
var: ir.AllocaInstr
9+
ir_type: ir.Type
10+
metadata: Any = None
11+
12+
def __iter__(self):
13+
yield self.var
14+
yield self.ir_type
15+
yield self.metadata

pythonbpf/vmlinux_parser/vmlinux_exports_handler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
from llvmlite import ir
33

4+
from pythonbpf.local_symbol import LocalSymbol
45
from pythonbpf.vmlinux_parser.assignment_info import AssignmentType
56

67
logger = logging.getLogger(__name__)
@@ -88,10 +89,12 @@ def handle_vmlinux_struct_field(
8889
):
8990
"""Handle access to vmlinux struct fields"""
9091
if struct_var_name in local_sym_tab:
91-
var_info = local_sym_tab[struct_var_name]
92+
var_info: LocalSymbol = local_sym_tab[struct_var_name]
9293
logger.info(
9394
f"Attempting to access field {field_name} of possible vmlinux struct {struct_var_name}"
9495
)
96+
print(var_info.ir_type)
97+
print(self.get_field_type(struct_var_name, field_name))
9598
# Return pointer to field and field type
9699
return None
97100
else:

0 commit comments

Comments
 (0)