44
55def maps_proc (tree , module , chunks ):
66 for func_node in chunks :
7- # Check if this function is a global
8- is_global = False
7+ # Check if this function is a map
8+ is_map = False
99 for decorator in func_node .decorator_list :
1010 if isinstance (decorator , ast .Name ) and decorator .id == "map" :
11- is_global = True
11+ is_map = True
1212 break
13- if is_global :
13+ if is_map :
1414 print (f"Found BPF map: { func_node .name } " )
15- process_bpf_global (func_node , module )
15+ process_bpf_map (func_node , module )
1616 continue
1717
1818
@@ -34,10 +34,10 @@ def create_bpf_map(module, map_name, map_params):
3434
3535 map_global = ir .GlobalVariable (module , map_struct_type , name = map_name )
3636 map_global .linkage = 'external'
37- map_global .initializer = ir .Constant (
37+ map_global .initializer = ir .Constant ( # type: ignore
3838 map_struct_type , [None , None , None , None ])
3939 map_global .section = ".maps"
40- map_global .align = 8
40+ map_global .align = 8 # type: ignore
4141
4242 # TODO: Store map parameters in metadata or a suitable structure
4343 # maps[map_name] = {
@@ -52,10 +52,10 @@ def create_bpf_map(module, map_name, map_params):
5252 return map_global
5353
5454
55- def process_bpf_global (func_node , module ):
56- """Process a BPF global (a function decorated with @bpfglobal )"""
57- global_name = func_node .name
58- print (f"Processing BPF global : { global_name } " )
55+ def process_bpf_map (func_node , module ):
56+ """Process a BPF map (a function decorated with @map )"""
57+ map_name = func_node .name
58+ print (f"Processing BPF map : { map_name } " )
5959
6060 # For now, assume single return statement
6161 return_stmt = None
@@ -64,13 +64,13 @@ def process_bpf_global(func_node, module):
6464 return_stmt = stmt
6565 break
6666 if return_stmt is None :
67- raise ValueError ("BPF global must have a return statement" )
67+ raise ValueError ("BPF map must have a return statement" )
6868
6969 rval = return_stmt .value
7070
7171 # For now, just handle maps
7272 if isinstance (rval , ast .Call ) and isinstance (rval .func , ast .Name ) and rval .func .id == "HashMap" :
73- print (f"Creating HashMap global : { global_name } " )
73+ print (f"Creating HashMap map : { map_name } " )
7474 map_params = {'map_type' : 'HASH' }
7575 # Handle positional arguments
7676 if rval .args :
@@ -91,4 +91,4 @@ def process_bpf_global(func_node, module):
9191 elif keyword .arg == "max_entries" and isinstance (keyword .value , ast .Constant ):
9292 map_params ['max_entries' ] = keyword .value .value
9393 print (f"Map parameters: { map_params } " )
94- print (create_bpf_map (module , global_name , map_params ))
94+ print (create_bpf_map (module , map_name , map_params ))
0 commit comments