mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Add _handle_none_return
This commit is contained in:
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user