Skip to content

Commit 23183da

Browse files
committed
Add _handle_variable_return
1 parent c6fef16 commit 23183da

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pythonbpf/functions/return_utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,25 @@ def _handle_binop_return(arg, builder, ret_type, local_sym_tab) -> bool:
5959
return True
6060

6161

62+
def _handle_variable_return(var_name, builder, ret_type, local_sym_tab) -> bool:
63+
"""Handle return of a variable: return c_int64(my_var)"""
64+
65+
# var_name = stmt.value.args[0].id
66+
67+
if var_name not in local_sym_tab:
68+
raise ValueError(f"Undefined variable in return: {var_name}")
69+
70+
var = local_sym_tab[var_name].var
71+
val = builder.load(var)
72+
73+
if val.type != ret_type:
74+
raise ValueError(f"Return type mismatch: expected {ret_type}, got {val.type}")
75+
76+
builder.ret(val)
77+
logger.debug(f"Generated variable return: {var_name}")
78+
return True
79+
80+
6281
def _handle_xdp_return(stmt: ast.Return, builder, ret_type) -> bool:
6382
"""Handle XDP returns"""
6483
if not isinstance(stmt.value, ast.Name):

0 commit comments

Comments
 (0)