mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Allow helpers to be called within themselves
This commit is contained in:
@ -180,23 +180,23 @@ def _handle_unary_op(
|
|||||||
logger.error("Only 'not' and '-' unary operators are supported")
|
logger.error("Only 'not' and '-' unary operators are supported")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
operand = eval_expr(
|
from pythonbpf.binary_ops import get_operand_value
|
||||||
func, module, builder, expr.operand, local_sym_tab, map_sym_tab, structs_sym_tab
|
|
||||||
|
operand = get_operand_value(
|
||||||
|
func, module, expr.operand, builder, local_sym_tab, map_sym_tab, structs_sym_tab
|
||||||
)
|
)
|
||||||
if operand is None:
|
if operand is None:
|
||||||
logger.error("Failed to evaluate operand for unary operation")
|
logger.error("Failed to evaluate operand for unary operation")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
operand_val, operand_type = operand
|
|
||||||
|
|
||||||
if isinstance(expr.op, ast.Not):
|
if isinstance(expr.op, ast.Not):
|
||||||
true_const = ir.Constant(ir.IntType(1), 1)
|
true_const = ir.Constant(ir.IntType(1), 1)
|
||||||
result = builder.xor(convert_to_bool(builder, operand_val), true_const)
|
result = builder.xor(convert_to_bool(builder, operand), true_const)
|
||||||
return result, ir.IntType(1)
|
return result, ir.IntType(1)
|
||||||
elif isinstance(expr.op, ast.USub):
|
elif isinstance(expr.op, ast.USub):
|
||||||
# Multiply by -1
|
# Multiply by -1
|
||||||
neg_one = ir.Constant(ir.IntType(64), -1)
|
neg_one = ir.Constant(ir.IntType(64), -1)
|
||||||
result = builder.mul(operand_val, neg_one)
|
result = builder.mul(operand, neg_one)
|
||||||
return result, ir.IntType(64)
|
return result, ir.IntType(64)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ from collections.abc import Callable
|
|||||||
|
|
||||||
from llvmlite import ir
|
from llvmlite import ir
|
||||||
from pythonbpf.expr import eval_expr, get_base_type_and_depth, deref_to_depth
|
from pythonbpf.expr import eval_expr, get_base_type_and_depth, deref_to_depth
|
||||||
|
from pythonbpf.binary_ops import get_operand_value
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -98,14 +99,8 @@ def get_or_create_ptr_from_arg(
|
|||||||
ptr = create_int_constant_ptr(arg.value, builder, local_sym_tab)
|
ptr = create_int_constant_ptr(arg.value, builder, local_sym_tab)
|
||||||
else:
|
else:
|
||||||
# Evaluate the expression and store the result in a temp variable
|
# Evaluate the expression and store the result in a temp variable
|
||||||
val, _ = eval_expr(
|
val = get_operand_value(
|
||||||
func,
|
func, module, arg, builder, local_sym_tab, map_sym_tab, struct_sym_tab
|
||||||
module,
|
|
||||||
builder,
|
|
||||||
arg,
|
|
||||||
local_sym_tab,
|
|
||||||
map_sym_tab,
|
|
||||||
struct_sym_tab,
|
|
||||||
)
|
)
|
||||||
if val is None:
|
if val is None:
|
||||||
raise ValueError("Failed to evaluate expression for helper arg.")
|
raise ValueError("Failed to evaluate expression for helper arg.")
|
||||||
|
|||||||
Reference in New Issue
Block a user