Skip to content

Commit be05b5d

Browse files
committed
Allow local symbols to be used within return
1 parent 3f06175 commit be05b5d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pythonbpf/functions_pass.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,19 @@ def process_stmt(
417417
)
418418
builder.ret(val[0])
419419
did_return = True
420+
elif isinstance(stmt.value.args[0], ast.Name):
421+
if stmt.value.args[0].id in local_sym_tab:
422+
var = local_sym_tab[stmt.value.args[0].id].var
423+
val = builder.load(var)
424+
if val.type != ret_type:
425+
raise ValueError(
426+
"Return type mismatch: expected"
427+
f"{ret_type}, got {val.type}"
428+
)
429+
builder.ret(val)
430+
did_return = True
431+
else:
432+
raise ValueError("Failed to evaluate return expression")
420433
elif isinstance(stmt.value, ast.Name):
421434
if stmt.value.id == "XDP_PASS":
422435
builder.ret(ir.Constant(ret_type, 2))

0 commit comments

Comments
 (0)