Skip to content

Commit 3f9604a

Browse files
committed
Add _deref_to_depth in expr_pass
1 parent 480afd1 commit 3f9604a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pythonbpf/expr_pass.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ def _get_base_type_and_depth(ir_type):
139139
return cur_type, depth
140140

141141

142+
def _deref_to_depth(builder, val, target_depth):
143+
"""Dereference a pointer to a certain depth."""
144+
145+
cur_val = val
146+
for _ in range(target_depth):
147+
if not isinstance(val.type, ir.PointerType):
148+
logger.error("Cannot dereference further, non-pointer type")
149+
return None
150+
cur_val = builder.load(cur_val)
151+
return cur_val
152+
153+
142154
def _normalize_types(builder, lhs, rhs):
143155
"""Normalize types for comparison."""
144156

0 commit comments

Comments
 (0)