From 6cf5115ea95efe8741e84f78e4c0cfc7d0a9054f Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Mon, 6 Oct 2025 22:38:43 +0530 Subject: [PATCH] Eval LHS and RHS in _handle_compare --- pythonbpf/expr_pass.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/pythonbpf/expr_pass.py b/pythonbpf/expr_pass.py index 78987cd..fd673df 100644 --- a/pythonbpf/expr_pass.py +++ b/pythonbpf/expr_pass.py @@ -133,9 +133,37 @@ def _handle_ctypes_call( def _handle_compare( - func, module, builder, expr, local_sym_tab, map_sym_tab, structs_sym_tab=None + func, module, builder, cond, local_sym_tab, map_sym_tab, structs_sym_tab=None ): - pass + if len(cond.ops) != 1 or len(cond.comparators) != 1: + logger.error("Only single comparisons are supported") + return None + lhs = eval_expr( + func, + module, + builder, + cond.left, + local_sym_tab, + map_sym_tab, + structs_sym_tab, + ) + rhs = eval_expr( + func, + module, + builder, + cond.comparators[0], + local_sym_tab, + map_sym_tab, + structs_sym_tab, + ) + + if lhs is None or rhs is None: + logger.error("Failed to evaluate comparison operands") + return None + + lhs, _ = lhs + rhs, _ = rhs + return None def eval_expr(