Skip to content

Commit a8b3f4f

Browse files
committed
Fix recursive binops, move failing binops to passing
1 parent d593969 commit a8b3f4f

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

pythonbpf/binary_ops.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def recursive_dereferencer(var, builder):
1818
raise TypeError(f"Unsupported type for dereferencing: {var.type}")
1919

2020

21-
def get_operand_value(operand, builder, local_sym_tab):
21+
def get_operand_value(operand, module, builder, local_sym_tab):
2222
"""Extract the value from an operand, handling variables and constants."""
2323
if isinstance(operand, ast.Name):
2424
if operand.id in local_sym_tab:
@@ -28,13 +28,15 @@ def get_operand_value(operand, builder, local_sym_tab):
2828
if isinstance(operand.value, int):
2929
return ir.Constant(ir.IntType(64), operand.value)
3030
raise TypeError(f"Unsupported constant type: {type(operand.value)}")
31+
elif isinstance(operand, ast.BinOp):
32+
return handle_binary_op_impl(operand, module, builder, local_sym_tab)
3133
raise TypeError(f"Unsupported operand type: {type(operand)}")
3234

3335

34-
def handle_binary_op(rval, module, builder, var_name, local_sym_tab, map_sym_tab, func):
36+
def handle_binary_op_impl(rval, module, builder, local_sym_tab):
3537
op = rval.op
36-
left = get_operand_value(rval.left, builder, local_sym_tab)
37-
right = get_operand_value(rval.right, builder, local_sym_tab)
38+
left = get_operand_value(rval.left, module, builder, local_sym_tab)
39+
right = get_operand_value(rval.right, module, builder, local_sym_tab)
3840
logger.info(f"left is {left}, right is {right}, op is {op}")
3941

4042
# Map AST operation nodes to LLVM IR builder methods
@@ -54,6 +56,11 @@ def handle_binary_op(rval, module, builder, var_name, local_sym_tab, map_sym_tab
5456

5557
if type(op) in op_map:
5658
result = op_map[type(op)](left, right)
57-
builder.store(result, local_sym_tab[var_name].var)
59+
return result
5860
else:
5961
raise SyntaxError("Unsupported binary operation")
62+
63+
64+
def handle_binary_op(rval, module, builder, var_name, local_sym_tab):
65+
result = handle_binary_op_impl(rval, module, builder, local_sym_tab)
66+
builder.store(result, local_sym_tab[var_name].var)

pythonbpf/codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def compile_to_ir(filename: str, output: str, loglevel=logging.WARNING):
121121
return output
122122

123123

124-
def compile(loglevel=logging.WARNING) -> bool:
124+
def compile(loglevel=logging.INFO) -> bool:
125125
# Look one level up the stack to the caller of this function
126126
caller_frame = inspect.stack()[1]
127127
caller_file = Path(caller_frame.filename).resolve()

pythonbpf/functions_pass.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,7 @@ def handle_assign(
233233
else:
234234
logger.info("Unsupported assignment call function type")
235235
elif isinstance(rval, ast.BinOp):
236-
handle_binary_op(
237-
rval, module, builder, var_name, local_sym_tab, map_sym_tab, func
238-
)
236+
handle_binary_op(rval, module, builder, var_name, local_sym_tab)
239237
else:
240238
logger.info("Unsupported assignment value type")
241239

tests/failing_tests/binops.py renamed to tests/passing_tests/binops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
@bpf
6-
@section("sometag1")
6+
@section("tracepoint/syscalls/sys_enter_sync")
77
def sometag(ctx: c_void_p) -> c_int64:
88
a = 1 + 2 + 1
99
print(f"{a}")

0 commit comments

Comments
 (0)