Skip to content

Commit 8776d76

Browse files
committed
Add count_temps_in_call to call scratch space needed in a helper call
1 parent 8b7b1c0 commit 8776d76

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pythonbpf/functions/functions_pass.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,33 @@ def process_stmt(
383383
return did_return
384384

385385

386+
def count_temps_in_call(call_node):
387+
"""Count the number of temporary variables needed for a function call."""
388+
389+
count = 0
390+
is_helper = False
391+
392+
if isinstance(call_node.func, ast.Name):
393+
if HelperHandlerRegistry.has_handler(call_node.func.id):
394+
is_helper = True
395+
elif isinstance(call_node.func, ast.Attribute):
396+
if HelperHandlerRegistry.has_handler(call_node.func.attr):
397+
is_helper = True
398+
399+
if not is_helper:
400+
return 0
401+
402+
for arg in call_node.args:
403+
if (
404+
isinstance(arg, ast.BinOp)
405+
or isinstance(arg, ast.Constant)
406+
or isinstance(arg, ast.UnaryOp)
407+
):
408+
count += 1
409+
410+
return count
411+
412+
386413
def allocate_mem(
387414
module, builder, body, func, ret_type, map_sym_tab, local_sym_tab, structs_sym_tab
388415
):

0 commit comments

Comments
 (0)