diff --git a/pythonbpf/functions/functions_pass.py b/pythonbpf/functions/functions_pass.py index 64b9233..6eff2e7 100644 --- a/pythonbpf/functions/functions_pass.py +++ b/pythonbpf/functions/functions_pass.py @@ -9,6 +9,8 @@ from pythonbpf.type_deducer import ctypes_to_ir from pythonbpf.binary_ops import handle_binary_op from pythonbpf.expr_pass import eval_expr, handle_expr +from .return_utils import _handle_none_return + logger = logging.getLogger(__name__) @@ -353,8 +355,7 @@ def handle_if( def handle_return(builder, stmt, local_sym_tab, ret_type): if stmt.value is None: - builder.ret(ir.Constant(ir.IntType(64), 0)) - return True + return _handle_none_return(builder) elif ( isinstance(stmt.value, ast.Call) and isinstance(stmt.value.func, ast.Name) diff --git a/pythonbpf/functions/return_utils.py b/pythonbpf/functions/return_utils.py index e69de29..12a2d01 100644 --- a/pythonbpf/functions/return_utils.py +++ b/pythonbpf/functions/return_utils.py @@ -0,0 +1,11 @@ +import logging +import ir + +logger: logging.Logger = logging.getLogger(__name__) + + +def _handle_none_return(builder) -> bool: + """Handle return or return None -> returns 0.""" + builder.ret(ir.Constant(ir.IntType(64), 0)) + logger.debug("Generated default return: 0") + return True