Skip to content

Commit 84ed27f

Browse files
committed
Add handle_variable_assignment stub and boilerplate in handle_assign
1 parent 6008d98 commit 84ed27f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

pythonbpf/assign_pass.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def handle_variable_assignment(
2+
func, module, builder, var_name, rval, local_sym_tab, map_sym_tab, structs_sym_tab
3+
):
4+
pass

pythonbpf/functions/functions_pass.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pythonbpf.type_deducer import ctypes_to_ir
99
from pythonbpf.binary_ops import handle_binary_op
1010
from pythonbpf.expr import eval_expr, handle_expr, convert_to_bool
11+
from pythonbpf.assign_pass import handle_variable_assignment
1112

1213
from .return_utils import _handle_none_return, _handle_xdp_return, _is_xdp_name
1314

@@ -55,9 +56,28 @@ def handle_assign(
5556
logger.error("Multi-target assignment is not supported for now")
5657
return
5758

59+
target = stmt.targets[0]
60+
rval = stmt.value
61+
62+
if isinstance(target, ast.Name):
63+
# NOTE: Simple variable assignment case: x = 5
64+
var_name = target.id
65+
result = handle_variable_assignment(
66+
func,
67+
module,
68+
builder,
69+
var_name,
70+
rval,
71+
local_sym_tab,
72+
map_sym_tab,
73+
structs_sym_tab,
74+
)
75+
if not result:
76+
logger.error(f"Failed to handle assignment to {var_name}")
77+
return
78+
5879
num_types = ("c_int32", "c_int64", "c_uint32", "c_uint64")
5980

60-
target = stmt.targets[0]
6181
logger.info(f"Handling assignment to {ast.dump(target)}")
6282
if not isinstance(target, ast.Name) and not isinstance(target, ast.Attribute):
6383
logger.info("Unsupported assignment target")

0 commit comments

Comments
 (0)