diff --git a/pythonbpf/functions/return_utils.py b/pythonbpf/functions/return_utils.py index 74df7d8..3c4e1c6 100644 --- a/pythonbpf/functions/return_utils.py +++ b/pythonbpf/functions/return_utils.py @@ -2,6 +2,7 @@ import logging import ast from llvmlite import ir +from pythonbpf.type_deducer import ctypes_to_ir logger: logging.Logger = logging.getLogger(__name__) @@ -21,6 +22,23 @@ def _handle_none_return(builder) -> bool: return True +def _handle_typed_constant_return(call_type, return_value, builder, ret_type) -> bool: + """Handle typed constant return like: return c_int64(42)""" + + # call_type = stmt.value.func.id + expected_type = ctypes_to_ir(call_type) + + if expected_type != ret_type: + raise ValueError( + f"Return type mismatch: expected {ret_type}, got {expected_type}" + ) + + # return_value = stmt.value.args[0].value + builder.ret(ir.Constant(ret_type, return_value)) + logger.debug(f"Generated typed constant return: {call_type}({return_value})") + return True + + def _handle_xdp_return(stmt: ast.Return, builder, ret_type) -> bool: """Handle XDP returns""" if not isinstance(stmt.value, ast.Name):