From 46f5eca33d161baa939e8311dcd4c7a9f97ed361 Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Wed, 8 Oct 2025 03:12:17 +0530 Subject: [PATCH] Add _deref_to_depth in expr_pass --- pythonbpf/expr_pass.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pythonbpf/expr_pass.py b/pythonbpf/expr_pass.py index fe04b68..834d924 100644 --- a/pythonbpf/expr_pass.py +++ b/pythonbpf/expr_pass.py @@ -139,6 +139,18 @@ def _get_base_type_and_depth(ir_type): return cur_type, depth +def _deref_to_depth(builder, val, target_depth): + """Dereference a pointer to a certain depth.""" + + cur_val = val + for _ in range(target_depth): + if not isinstance(val.type, ir.PointerType): + logger.error("Cannot dereference further, non-pointer type") + return None + cur_val = builder.load(cur_val) + return cur_val + + def _normalize_types(builder, lhs, rhs): """Normalize types for comparison."""