mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 01:48:35 +00:00
Core: Resolve @bpfglobal reads in expressions and f-strings
Name resolution tried local_sym_tab, then vmlinux enums, then failed. Globals now resolve between the two, in _handle_name_expr, get_operand_value, and the printk f-string formatter, each emitting the plain 'load i64, ptr @counter' form the C reference produces. A global therefore works in conditions, binops, print arguments and as a helper scalar argument with no further changes -- those paths all funnel through eval_expr/get_operand_value. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L1PX8EuP9C3o3veWGA84RF
This commit is contained in:
@ -41,7 +41,7 @@ def handle_fstring_print(
|
||||
fmt_parts,
|
||||
exprs,
|
||||
local_sym_tab,
|
||||
compilation_context.structs_sym_tab,
|
||||
compilation_context,
|
||||
)
|
||||
else:
|
||||
raise NotImplementedError(f"Unsupported f-string value type: {type(value)}")
|
||||
@ -80,19 +80,21 @@ def _process_constant_in_fstring(cst, fmt_parts, exprs):
|
||||
)
|
||||
|
||||
|
||||
def _process_fval(fval, fmt_parts, exprs, local_sym_tab, struct_sym_tab):
|
||||
def _process_fval(fval, fmt_parts, exprs, local_sym_tab, compilation_context):
|
||||
"""Process formatted values in f-string."""
|
||||
logger.debug(f"Processing formatted value: {ast.dump(fval)}")
|
||||
|
||||
if isinstance(fval.value, ast.Name):
|
||||
_process_name_in_fval(fval.value, fmt_parts, exprs, local_sym_tab)
|
||||
_process_name_in_fval(
|
||||
fval.value, fmt_parts, exprs, local_sym_tab, compilation_context
|
||||
)
|
||||
elif isinstance(fval.value, ast.Attribute):
|
||||
_process_attr_in_fval(
|
||||
fval.value,
|
||||
fmt_parts,
|
||||
exprs,
|
||||
local_sym_tab,
|
||||
struct_sym_tab,
|
||||
compilation_context.structs_sym_tab,
|
||||
)
|
||||
else:
|
||||
raise NotImplementedError(
|
||||
@ -100,11 +102,16 @@ def _process_fval(fval, fmt_parts, exprs, local_sym_tab, struct_sym_tab):
|
||||
)
|
||||
|
||||
|
||||
def _process_name_in_fval(name_node, fmt_parts, exprs, local_sym_tab):
|
||||
def _process_name_in_fval(
|
||||
name_node, fmt_parts, exprs, local_sym_tab, compilation_context
|
||||
):
|
||||
"""Process name nodes in formatted values."""
|
||||
if local_sym_tab and name_node.id in local_sym_tab:
|
||||
_, var_type, tmp = local_sym_tab[name_node.id]
|
||||
_populate_fval(var_type, name_node, fmt_parts, exprs)
|
||||
elif name_node.id in compilation_context.bpf_globals:
|
||||
var_type = compilation_context.bpf_globals[name_node.id].ir_type
|
||||
_populate_fval(var_type, name_node, fmt_parts, exprs)
|
||||
else:
|
||||
# Try to resolve through vmlinux registry if not in local symbol table
|
||||
result = VmlinuxHandlerRegistry.handle_name(name_node.id)
|
||||
|
||||
Reference in New Issue
Block a user