Skip to content

Commit 18f164b

Browse files
committed
Add get_flags_val to helper_utils
1 parent 8d9ff2d commit 18f164b

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

pythonbpf/helper/helper_utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,22 @@ def get_or_create_ptr_from_arg(arg, builder, local_sym_tab):
4848
raise NotImplementedError(
4949
"Only simple variable names are supported as args in map helpers.")
5050
return ptr
51+
52+
53+
def get_flags_val(arg, builder, local_sym_tab):
54+
"""Extract or create flags value from the call arguments."""
55+
if not arg:
56+
return 0
57+
58+
if isinstance(arg, ast.Name):
59+
if local_sym_tab and arg.id in local_sym_tab:
60+
flags_ptr = local_sym_tab[arg.id][0]
61+
return builder.load(flags_ptr)
62+
else:
63+
raise ValueError(
64+
f"Variable '{arg.id}' not found in local symbol table")
65+
elif isinstance(arg, ast.Constant) and isinstance(arg.value, int):
66+
return arg.value
67+
68+
raise NotImplementedError(
69+
"Only simple variable names or integer constants are supported as flags in map helpers.")

0 commit comments

Comments
 (0)