Skip to content

Commit 55c9b2e

Browse files
committed
Add var assigning for helpers
1 parent dafd6d1 commit 55c9b2e

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

examples/execve2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def hello_again(ctx: c_void_p) -> c_int64:
2525
key = 0
2626
tsp = last().lookup(key)
2727
print(tsp)
28-
ktime()
28+
ts = ktime()
2929
return c_int64(0)
3030

3131

pythonbpf/bpf_helper_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def handle_helper_call(call, module, builder, func, local_sym_tab=None, map_sym_
107107
func_name = call.func.id
108108
if func_name in helper_func_list:
109109
# it is not a map method call
110-
helper_func_list[func_name](call, module, builder, func)
110+
return helper_func_list[func_name](call, module, builder, func)
111111
else:
112112
raise NotImplementedError(
113113
f"Function {func_name} is not implemented as a helper function.")
@@ -119,7 +119,7 @@ def handle_helper_call(call, module, builder, func, local_sym_tab=None, map_sym_
119119
if map_sym_tab and map_name in map_sym_tab:
120120
map_ptr = map_sym_tab[map_name]
121121
if method_name in helper_func_list:
122-
helper_func_list[method_name](
122+
return helper_func_list[method_name](
123123
call, map_ptr, module, builder, local_sym_tab)
124124
else:
125125
raise NotImplementedError(

pythonbpf/functions_pass.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def handle_assign(module, builder, stmt, map_sym_tab, local_sym_tab):
3939
if isinstance(rval, ast.Constant):
4040
if isinstance(rval.value, int):
4141
# Assume c_int64 for now
42-
# TODO: make symtab for this
4342
var = builder.alloca(ir.IntType(64), name=var_name)
4443
var.align = 8
4544
builder.store(ir.Constant(ir.IntType(64), rval.value), var)
@@ -57,6 +56,14 @@ def handle_assign(module, builder, stmt, map_sym_tab, local_sym_tab):
5756
print(f"Assigned {call_type} constant "
5857
f"{rval.args[0].value} to {var_name}")
5958
local_sym_tab[var_name] = var
59+
elif call_type in helper_func_list:
60+
var = builder.alloca(ir.IntType(64), name=var_name)
61+
var.align = 8
62+
val = handle_helper_call(
63+
rval, module, builder, None, local_sym_tab, map_sym_tab)
64+
builder.store(val, var)
65+
local_sym_tab[var_name] = var
66+
print(f"Assigned constant {rval.func.id} to {var_name}")
6067
else:
6168
print(f"Unsupported assignment call type: {call_type}")
6269
elif isinstance(rval.func, ast.Attribute):
@@ -70,6 +77,8 @@ def handle_assign(module, builder, stmt, map_sym_tab, local_sym_tab):
7077
rval, module, builder, None, local_sym_tab, map_sym_tab)
7178
else:
7279
print("Unsupported assignment call structure")
80+
else:
81+
print("Unsupported assignment call function type")
7382

7483

7584
def process_func_body(module, builder, func_node, func, ret_type, map_sym_tab):

0 commit comments

Comments
 (0)