mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Pass down type info in local_sym_tab
This commit is contained in:
@ -85,6 +85,7 @@ def bpf_printk_emitter(call, map_ptr, module, builder, func, local_sym_tab=None,
|
|||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"Only string and integer constants are supported in f-string.")
|
"Only string and integer constants are supported in f-string.")
|
||||||
elif isinstance(value, ast.FormattedValue):
|
elif isinstance(value, ast.FormattedValue):
|
||||||
|
print("Formatted value:", ast.dump(value))
|
||||||
# Assume int for now
|
# Assume int for now
|
||||||
fmt_parts.append("%lld")
|
fmt_parts.append("%lld")
|
||||||
if isinstance(value.value, ast.Name):
|
if isinstance(value.value, ast.Name):
|
||||||
|
|||||||
@ -81,6 +81,19 @@ def handle_assign(func, module, builder, stmt, map_sym_tab, local_sym_tab, struc
|
|||||||
local_sym_tab[var_name])
|
local_sym_tab[var_name])
|
||||||
# local_sym_tab[var_name] = var
|
# local_sym_tab[var_name] = var
|
||||||
print(f"Assigned constant {rval.value} to {var_name}")
|
print(f"Assigned constant {rval.value} to {var_name}")
|
||||||
|
elif isinstance(rval.value, str):
|
||||||
|
str_val = rval.value.encode('utf-8') + b'\x00'
|
||||||
|
str_const = ir.Constant(ir.ArrayType(
|
||||||
|
ir.IntType(8), len(str_val)), bytearray(str_val))
|
||||||
|
global_str = ir.GlobalVariable(
|
||||||
|
module, str_const.type, name=f"{var_name}_str")
|
||||||
|
global_str.linkage = 'internal'
|
||||||
|
global_str.global_constant = True
|
||||||
|
global_str.initializer = str_const
|
||||||
|
str_ptr = builder.bitcast(
|
||||||
|
global_str, ir.PointerType(ir.IntType(8)))
|
||||||
|
builder.store(str_ptr, local_sym_tab[var_name])
|
||||||
|
print(f"Assigned string constant '{rval.value}' to {var_name}")
|
||||||
else:
|
else:
|
||||||
print("Unsupported constant type")
|
print("Unsupported constant type")
|
||||||
elif isinstance(rval, ast.Call):
|
elif isinstance(rval, ast.Call):
|
||||||
@ -389,7 +402,7 @@ def allocate_mem(module, builder, body, func, ret_type, map_sym_tab, local_sym_t
|
|||||||
else:
|
else:
|
||||||
print("Unsupported assignment value type")
|
print("Unsupported assignment value type")
|
||||||
continue
|
continue
|
||||||
local_sym_tab[var_name] = var
|
local_sym_tab[var_name] = (var, ir_type)
|
||||||
return local_sym_tab
|
return local_sym_tab
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user