Skip to content

Commit e8026a1

Browse files
committed
Allow helpers to be called within themselves
1 parent a3b4d09 commit e8026a1

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

pythonbpf/expr/expr_pass.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,23 @@ def _handle_unary_op(
180180
logger.error("Only 'not' and '-' unary operators are supported")
181181
return None
182182

183-
operand = eval_expr(
184-
func, module, builder, expr.operand, local_sym_tab, map_sym_tab, structs_sym_tab
183+
from pythonbpf.binary_ops import get_operand_value
184+
185+
operand = get_operand_value(
186+
func, module, expr.operand, builder, local_sym_tab, map_sym_tab, structs_sym_tab
185187
)
186188
if operand is None:
187189
logger.error("Failed to evaluate operand for unary operation")
188190
return None
189191

190-
operand_val, operand_type = operand
191-
192192
if isinstance(expr.op, ast.Not):
193193
true_const = ir.Constant(ir.IntType(1), 1)
194-
result = builder.xor(convert_to_bool(builder, operand_val), true_const)
194+
result = builder.xor(convert_to_bool(builder, operand), true_const)
195195
return result, ir.IntType(1)
196196
elif isinstance(expr.op, ast.USub):
197197
# Multiply by -1
198198
neg_one = ir.Constant(ir.IntType(64), -1)
199-
result = builder.mul(operand_val, neg_one)
199+
result = builder.mul(operand, neg_one)
200200
return result, ir.IntType(64)
201201

202202

pythonbpf/helper/helper_utils.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from llvmlite import ir
66
from pythonbpf.expr import eval_expr, get_base_type_and_depth, deref_to_depth
7+
from pythonbpf.binary_ops import get_operand_value
78

89
logger = logging.getLogger(__name__)
910

@@ -98,14 +99,8 @@ def get_or_create_ptr_from_arg(
9899
ptr = create_int_constant_ptr(arg.value, builder, local_sym_tab)
99100
else:
100101
# Evaluate the expression and store the result in a temp variable
101-
val, _ = eval_expr(
102-
func,
103-
module,
104-
builder,
105-
arg,
106-
local_sym_tab,
107-
map_sym_tab,
108-
struct_sym_tab,
102+
val = get_operand_value(
103+
func, module, arg, builder, local_sym_tab, map_sym_tab, struct_sym_tab
109104
)
110105
if val is None:
111106
raise ValueError("Failed to evaluate expression for helper arg.")

0 commit comments

Comments
 (0)