Add _handle_binop_return

This commit is contained in:
Pragyansh Chaturvedi
2025-10-06 00:03:34 +05:30
parent 192e03aa98
commit c6fef1693e

View File

@ -3,6 +3,7 @@ import ast
from llvmlite import ir
from pythonbpf.type_deducer import ctypes_to_ir
from pythonbpf.binary_ops import handle_binary_op
logger: logging.Logger = logging.getLogger(__name__)
@ -39,6 +40,25 @@ def _handle_typed_constant_return(call_type, return_value, builder, ret_type) ->
return True
def _handle_binop_return(arg, builder, ret_type, local_sym_tab) -> bool:
"""Handle return with binary operation: return c_int64(x + 1)"""
# result = handle_binary_op(stmt.value.args[0], builder, None, local_sym_tab)
result = handle_binary_op(arg, builder, None, local_sym_tab)
if result is None:
raise ValueError("Failed to evaluate binary operation in return statement")
val, val_type = result
if val_type != ret_type:
raise ValueError(f"Return type mismatch: expected {ret_type}, got {val_type}")
builder.ret(val)
logger.debug(f"Generated binary operation return: {val}")
return True
def _handle_xdp_return(stmt: ast.Return, builder, ret_type) -> bool:
"""Handle XDP returns"""
if not isinstance(stmt.value, ast.Name):