Rename public API and remove deadcode in return_utils

This commit is contained in:
Pragyansh Chaturvedi
2025-10-13 04:23:58 +05:30
parent 7a67041ea3
commit 0042280ff1
2 changed files with 7 additions and 8 deletions

View File

@ -14,7 +14,7 @@ from pythonbpf.assign_pass import (
) )
from pythonbpf.allocation_pass import handle_assign_allocation, allocate_temp_pool from pythonbpf.allocation_pass import handle_assign_allocation, allocate_temp_pool
from .return_utils import _handle_none_return, _handle_xdp_return, _is_xdp_name from .return_utils import handle_none_return, handle_xdp_return, is_xdp_name
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -146,9 +146,9 @@ def handle_if(
def handle_return(builder, stmt, local_sym_tab, ret_type): def handle_return(builder, stmt, local_sym_tab, ret_type):
logger.info(f"Handling return statement: {ast.dump(stmt)}") logger.info(f"Handling return statement: {ast.dump(stmt)}")
if stmt.value is None: if stmt.value is None:
return _handle_none_return(builder) return handle_none_return(builder)
elif isinstance(stmt.value, ast.Name) and _is_xdp_name(stmt.value.id): elif isinstance(stmt.value, ast.Name) and is_xdp_name(stmt.value.id):
return _handle_xdp_return(stmt, builder, ret_type) return handle_xdp_return(stmt, builder, ret_type)
else: else:
val = eval_expr( val = eval_expr(
func=None, func=None,

View File

@ -14,19 +14,19 @@ XDP_ACTIONS = {
} }
def _handle_none_return(builder) -> bool: def handle_none_return(builder) -> bool:
"""Handle return or return None -> returns 0.""" """Handle return or return None -> returns 0."""
builder.ret(ir.Constant(ir.IntType(64), 0)) builder.ret(ir.Constant(ir.IntType(64), 0))
logger.debug("Generated default return: 0") logger.debug("Generated default return: 0")
return True return True
def _is_xdp_name(name: str) -> bool: def is_xdp_name(name: str) -> bool:
"""Check if a name is an XDP action""" """Check if a name is an XDP action"""
return name in XDP_ACTIONS return name in XDP_ACTIONS
def _handle_xdp_return(stmt: ast.Return, builder, ret_type) -> bool: def handle_xdp_return(stmt: ast.Return, builder, ret_type) -> bool:
"""Handle XDP returns""" """Handle XDP returns"""
if not isinstance(stmt.value, ast.Name): if not isinstance(stmt.value, ast.Name):
return False return False
@ -37,7 +37,6 @@ def _handle_xdp_return(stmt: ast.Return, builder, ret_type) -> bool:
raise ValueError( raise ValueError(
f"Unknown XDP action: {action_name}. Available: {XDP_ACTIONS.keys()}" f"Unknown XDP action: {action_name}. Available: {XDP_ACTIONS.keys()}"
) )
return False
value = XDP_ACTIONS[action_name] value = XDP_ACTIONS[action_name]
builder.ret(ir.Constant(ret_type, value)) builder.ret(ir.Constant(ret_type, value))