From b64b5b2483e707c0bfed5df21dda36c5646e1c87 Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Thu, 11 Sep 2025 02:37:28 +0530 Subject: [PATCH] remove unary assign --- examples/execve3.py | 2 -- ...{unary_and_binary_ops.py => binary_ops.py} | 23 ------------------- pythonbpf/functions_pass.py | 15 ++---------- 3 files changed, 2 insertions(+), 38 deletions(-) rename pythonbpf/{unary_and_binary_ops.py => binary_ops.py} (57%) diff --git a/examples/execve3.py b/examples/execve3.py index d7998a5..2bcfe4b 100644 --- a/examples/execve3.py +++ b/examples/execve3.py @@ -49,8 +49,6 @@ def hello_again(ctx: c_void_p) -> c_int64: keema = 8 * 9 keesa = 10 - 11 keeda = 10 / 5 - # below does not spit IR - keeda += 1 return c_int64(0) @bpf diff --git a/pythonbpf/unary_and_binary_ops.py b/pythonbpf/binary_ops.py similarity index 57% rename from pythonbpf/unary_and_binary_ops.py rename to pythonbpf/binary_ops.py index 32ed0a7..1f0e84b 100644 --- a/pythonbpf/unary_and_binary_ops.py +++ b/pythonbpf/binary_ops.py @@ -33,26 +33,3 @@ def handle_binary_op(rval, module, builder, func, local_sym_tab, map_sym_tab): SyntaxError("Unsupported binary operation") return result - -def handle_unary_op(rval, module, builder, func, local_sym_tab, map_sym_tab): - print("UNARY ASSIGNMENT DOES NOT WORK") - return - # TODO: heavy fixxing needed - operand = rval.gay - op = rval.op - if isinstance(operand, ast.Name): - operand = local_sym_tab[operand.id] - elif isinstance(operand, ast.Constant): - operand = ir.Constant(ir.IntType(64), operand.value) - else: - SyntaxError("Unsupported operand type") - - if isinstance(op, ast.UAdd): - result = builder.add(ir.Constant(ir.IntType(64), 0), operand) - elif isinstance(op, ast.USub): - result = builder.sub(ir.Constant(ir.IntType(64), 0), operand) - else: - result = "all my homies hate type errors" - SyntaxError("Unsupported unary operation") - - return result diff --git a/pythonbpf/functions_pass.py b/pythonbpf/functions_pass.py index 1122af1..70ee989 100644 --- a/pythonbpf/functions_pass.py +++ b/pythonbpf/functions_pass.py @@ -3,7 +3,7 @@ import ast from .bpf_helper_handler import helper_func_list, handle_helper_call from .type_deducer import ctypes_to_ir -from .unary_and_binary_ops import handle_binary_op, handle_unary_op +from .binary_ops import handle_binary_op def get_probe_string(func_node): @@ -22,17 +22,6 @@ def get_probe_string(func_node): return arg.value return "helper" -def handle_unary_assign(func, module, builder, stmt, map_sym_tab, local_sym_tab): - """Handle unary assignment statements in the function body.""" - SyntaxError("Unary assignment not supported") - target = stmt.target - if not isinstance(target, ast.Name): - SyntaxError("Unsupported assignment target") - return - else: - handle_unary_op(func, module, builder, stmt, map_sym_tab, local_sym_tab) - return - def handle_assign(func, module, builder, stmt, map_sym_tab, local_sym_tab): """Handle assignment statements in the function body.""" if len(stmt.targets) != 1: @@ -256,7 +245,7 @@ def process_stmt(func, module, builder, stmt, local_sym_tab, map_sym_tab, did_re elif isinstance(stmt, ast.Assign): handle_assign(func, module, builder, stmt, map_sym_tab, local_sym_tab) elif isinstance(stmt, ast.AugAssign): - handle_unary_assign(func, module, builder, stmt, map_sym_tab, local_sym_tab) + raise SyntaxError("Augmented assignment not supported") elif isinstance(stmt, ast.If): handle_if(func, module, builder, stmt, map_sym_tab, local_sym_tab) elif isinstance(stmt, ast.Return):