Skip to content

Commit 617aac9

Browse files
committed
Add handle_expr
1 parent 55c9b2e commit 617aac9

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

pythonbpf/functions_pass.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ def handle_assign(module, builder, stmt, map_sym_tab, local_sym_tab):
8181
print("Unsupported assignment call function type")
8282

8383

84+
def handle_expr(module, builder, expr, local_sym_tab, map_sym_tab):
85+
"""Handle expression statements in the function body."""
86+
call = expr.value
87+
if isinstance(call, ast.Call):
88+
if isinstance(call.func, ast.Name):
89+
# check for helpers first
90+
if call.func.id in helper_func_list:
91+
handle_helper_call(
92+
call, module, builder, None, local_sym_tab, map_sym_tab)
93+
return
94+
print("Unsupported expression statement")
95+
96+
8497
def process_func_body(module, builder, func_node, func, ret_type, map_sym_tab):
8598
"""Process the body of a bpf function"""
8699
# TODO: A lot. We just have print -> bpf_trace_printk for now
@@ -89,13 +102,8 @@ def process_func_body(module, builder, func_node, func, ret_type, map_sym_tab):
89102
local_sym_tab = {}
90103

91104
for stmt in func_node.body:
92-
if isinstance(stmt, ast.Expr) and isinstance(stmt.value, ast.Call):
93-
call = stmt.value
94-
if isinstance(call.func, ast.Name):
95-
# check for helpers first
96-
if call.func.id in helper_func_list:
97-
handle_helper_call(
98-
call, module, builder, func, local_sym_tab, map_sym_tab)
105+
if isinstance(stmt, ast.Expr):
106+
handle_expr(module, builder, stmt, local_sym_tab, map_sym_tab)
99107
elif isinstance(stmt, ast.Assign):
100108
handle_assign(module, builder, stmt, map_sym_tab, local_sym_tab)
101109
elif isinstance(stmt, ast.Return):

0 commit comments

Comments
 (0)