@@ -75,6 +75,7 @@ def bpf_printk_emitter(call, map_ptr, module, builder, func, local_sym_tab=None,
7575 exprs = []
7676
7777 for value in call .args [0 ].values :
78+ print ("Value in f-string:" , ast .dump (value ))
7879 if isinstance (value , ast .Constant ):
7980 if isinstance (value .value , str ):
8081 fmt_parts .append (value .value )
@@ -86,10 +87,24 @@ def bpf_printk_emitter(call, map_ptr, module, builder, func, local_sym_tab=None,
8687 "Only string and integer constants are supported in f-string." )
8788 elif isinstance (value , ast .FormattedValue ):
8889 print ("Formatted value:" , ast .dump (value ))
89- # Assume int for now
90+ # TODO: Dirty handling here, only checks for int or str
9091 if isinstance (value .value , ast .Name ):
91- fmt_parts .append ("%lld" )
92- exprs .append (value .value )
92+ if local_sym_tab and value .value .id in local_sym_tab :
93+ var_ptr , var_type = local_sym_tab [value .value .id ]
94+ if isinstance (var_type , ir .IntType ):
95+ fmt_parts .append ("%lld" )
96+ exprs .append (value .value )
97+ elif var_type == ir .PointerType (ir .IntType (8 )):
98+ # Case with string
99+ fmt_parts .append ("%s" )
100+ exprs .append (value .value )
101+ else :
102+ raise NotImplementedError (
103+ "Only integer and pointer types are supported in formatted values." )
104+ print ("Formatted value variable:" , var_ptr , var_type )
105+ else :
106+ raise ValueError (
107+ f"Variable { value .value .id } not found in local symbol table." )
93108 else :
94109 raise NotImplementedError (
95110 "Only simple variable names are supported in formatted values." )
0 commit comments