Skip to content

Commit cd74e89

Browse files
committed
Allow binops as args to helpers accepting int*
1 parent 207f714 commit cd74e89

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pythonbpf/helper/helper_utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,25 @@ def get_or_create_ptr_from_arg(arg, builder, local_sym_tab):
9494
ptr = get_var_ptr_from_name(arg.id, local_sym_tab)
9595
elif isinstance(arg, ast.Constant) and isinstance(arg.value, int):
9696
ptr = create_int_constant_ptr(arg.value, builder, local_sym_tab)
97+
elif isinstance(arg, ast.BinOp):
98+
# Evaluate the expression and store the result in a temp variable
99+
val, _ = eval_expr(
100+
None,
101+
None,
102+
builder,
103+
arg,
104+
local_sym_tab,
105+
None,
106+
None,
107+
)
108+
if val is None:
109+
raise ValueError("Failed to evaluate expression for helper arg.")
110+
111+
# NOTE: We assume the result is an int64 for now
112+
ptr, temp_name = _temp_pool_manager.get_next_temp(local_sym_tab)
113+
logger.debug(f"Using temp variable '{temp_name}' for expression result")
114+
builder.store(val, ptr)
115+
97116
else:
98117
raise NotImplementedError(
99118
"Only simple variable names are supported as args in map helpers."

0 commit comments

Comments
 (0)