Add map_sym_tab

This commit is contained in:
Pragyansh Chaturvedi
2025-09-08 22:48:09 +05:30
parent ed37aa01d2
commit a5a671133c

View File

@ -2,6 +2,9 @@ import ast
from llvmlite import ir from llvmlite import ir
from .type_deducer import ctypes_to_ir from .type_deducer import ctypes_to_ir
map_sym_tab = {}
def maps_proc(tree, module, chunks): def maps_proc(tree, module, chunks):
for func_node in chunks: for func_node in chunks:
# Check if this function is a map # Check if this function is a map
@ -18,7 +21,7 @@ def maps_proc(tree, module, chunks):
def create_bpf_map(module, map_name, map_params): def create_bpf_map(module, map_name, map_params):
"""Create a BPF map in the module with the given parameters""" """Create a BPF map in the module with the given parameters"""
# Create the anonymous struct type for BPF map # Create the anonymous struct type for BPF map
map_struct_type = ir.LiteralStructType([ map_struct_type = ir.LiteralStructType([
ir.PointerType(), ir.PointerType(),
@ -26,21 +29,23 @@ def create_bpf_map(module, map_name, map_params):
ir.PointerType(), ir.PointerType(),
ir.PointerType() ir.PointerType()
]) ])
# Create the global variable # Create the global variable
map_global = ir.GlobalVariable(module, map_struct_type, name=map_name) map_global = ir.GlobalVariable(module, map_struct_type, name=map_name)
map_global.linkage = 'dso_local' map_global.linkage = 'dso_local'
map_global.global_constant = False map_global.global_constant = False
# Initialize with zeroinitializer (all null pointers) # Initialize with zeroinitializer (all null pointers)
map_global.initializer = ir.Constant(map_struct_type, None) #type: ignore map_global.initializer = ir.Constant(map_struct_type, None) # type: ignore
map_global.section = ".maps" map_global.section = ".maps"
map_global.align = 8 # type: ignore map_global.align = 8 # type: ignore
print(f"Created BPF map: {map_name}") print(f"Created BPF map: {map_name}")
map_sym_tab[map_name] = map_global
return map_global return map_global
def process_hash_map(map_name, rval, module): def process_hash_map(map_name, rval, module):
print(f"Creating HashMap map: {map_name}") print(f"Creating HashMap map: {map_name}")
map_params: dict[str, object] = {"map_type": "HASH"} map_params: dict[str, object] = {"map_type": "HASH"}