Skip to content

Commit b75dc82

Browse files
committed
Remove clutter from handle_return
1 parent f53ca3b commit b75dc82

File tree

1 file changed

+1
-43
lines changed

1 file changed

+1
-43
lines changed

pythonbpf/functions/functions_pass.py

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -359,53 +359,11 @@ def handle_return(builder, stmt, local_sym_tab, ret_type):
359359
return _handle_none_return(builder)
360360
elif isinstance(stmt.value, ast.Name) and _is_xdp_name(stmt.value.id):
361361
return _handle_xdp_return(stmt, builder, ret_type)
362-
elif True:
362+
else:
363363
val = eval_expr(None, None, builder, stmt.value, local_sym_tab, {}, {})
364364
logger.info(f"Evaluated return expression to {val}")
365365
builder.ret(val[0])
366366
return True
367-
elif (
368-
isinstance(stmt.value, ast.Call)
369-
and isinstance(stmt.value.func, ast.Name)
370-
and len(stmt.value.args) == 1
371-
):
372-
if isinstance(stmt.value.args[0], ast.Constant) and isinstance(
373-
stmt.value.args[0].value, int
374-
):
375-
call_type = stmt.value.func.id
376-
if ctypes_to_ir(call_type) != ret_type:
377-
raise ValueError(
378-
"Return type mismatch: expected"
379-
f"{ctypes_to_ir(call_type)}, got {call_type}"
380-
)
381-
else:
382-
builder.ret(ir.Constant(ret_type, stmt.value.args[0].value))
383-
return True
384-
elif isinstance(stmt.value.args[0], ast.BinOp):
385-
# TODO: Should be routed through eval_expr
386-
val = handle_binary_op(stmt.value.args[0], builder, None, local_sym_tab)
387-
if val is None:
388-
raise ValueError("Failed to evaluate return expression")
389-
if val[1] != ret_type:
390-
raise ValueError(
391-
f"Return type mismatch: expected {ret_type}, got {val[1]}"
392-
)
393-
builder.ret(val[0])
394-
return True
395-
elif isinstance(stmt.value.args[0], ast.Name):
396-
if stmt.value.args[0].id in local_sym_tab:
397-
var = local_sym_tab[stmt.value.args[0].id].var
398-
val = builder.load(var)
399-
if val.type != ret_type:
400-
raise ValueError(
401-
f"Return type mismatch: expected {ret_type}, got {val.type}"
402-
)
403-
builder.ret(val)
404-
return True
405-
else:
406-
raise ValueError("Failed to evaluate return expression")
407-
else:
408-
raise ValueError("Unsupported return value")
409367

410368

411369
def process_stmt(

0 commit comments

Comments
 (0)