Skip to content

Commit 23afb0b

Browse files
committed
Add deref_to_val to deref into final value and return the chain as well in binops
1 parent c596213 commit 23afb0b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pythonbpf/binary_ops.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ def recursive_dereferencer(var, builder):
1919
raise TypeError(f"Unsupported type for dereferencing: {var.type}")
2020

2121

22+
def deref_to_val(var, builder):
23+
"""Dereference a variable to get its value and pointer chain."""
24+
logger.info(f"Dereferencing {var}, type is {var.type}")
25+
26+
chain = [var]
27+
cur = var
28+
29+
while isinstance(cur.type, ir.PointerType):
30+
cur = builder.load(cur)
31+
chain.append(cur)
32+
33+
if isinstance(cur.type, ir.IntType):
34+
logger.info(f"dereference chain: {chain}")
35+
return cur, chain
36+
else:
37+
raise TypeError(f"Unsupported type for dereferencing: {cur.type}")
38+
39+
2240
def get_operand_value(operand, builder, local_sym_tab):
2341
"""Extract the value from an operand, handling variables and constants."""
2442
if isinstance(operand, ast.Name):

0 commit comments

Comments
 (0)