Add support for unary op 'not' in eval_expr, move not test to passing

This commit is contained in:
Pragyansh Chaturvedi
2025-10-07 04:49:45 +05:30
committed by varun-r-mallya
parent 7720437ca5
commit 5451ba646d
4 changed files with 43 additions and 13 deletions

View File

@ -7,7 +7,7 @@ from dataclasses import dataclass
from pythonbpf.helper import HelperHandlerRegistry, handle_helper_call
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 pythonbpf.expr_pass import eval_expr, handle_expr, convert_to_bool
from .return_utils import _handle_none_return, _handle_xdp_return, _is_xdp_name
@ -240,20 +240,10 @@ def handle_assign(
logger.info("Unsupported assignment value type")
def _convert_to_bool(builder, val):
if val.type == ir.IntType(1):
return val
if isinstance(val.type, ir.PointerType):
zero = ir.Constant(val.type, None)
else:
zero = ir.Constant(val.type, 0)
return builder.icmp_signed("!=", val, zero)
def handle_cond(func, module, builder, cond, local_sym_tab, map_sym_tab):
if True:
val = eval_expr(func, module, builder, cond, local_sym_tab, map_sym_tab)[0]
return _convert_to_bool(builder, val)
return convert_to_bool(builder, val)
if isinstance(cond, ast.Constant):
if isinstance(cond.value, bool) or isinstance(cond.value, int):
return ir.Constant(ir.IntType(1), int(cond.value))