33from pythonbpf .type_deducer import ctypes_to_ir
44from pythonbpf import dwarf_constants as dc
55from enum import Enum
6+ from .maps_utils import MapProcessorRegistry
67
78map_sym_tab = {}
89
@@ -183,6 +184,7 @@ def create_map_debug_info(module, map_global, map_name, map_params):
183184 return global_var_expr
184185
185186
187+ @MapProcessorRegistry .register ("HashMap" )
186188def process_hash_map (map_name , rval , module ):
187189 print (f"Creating HashMap map: { map_name } " )
188190 map_params = {"type" : BPFMapType .HASH }
@@ -211,6 +213,7 @@ def process_hash_map(map_name, rval, module):
211213 return create_bpf_map (module , map_name , map_params )
212214
213215
216+ @MapProcessorRegistry .register ("PerfEventArray" )
214217def process_perf_event_map (map_name , rval , module ):
215218 print (f"Creating PerfEventArray map: { map_name } " )
216219 map_params = {"type" : BPFMapType .PERF_EVENT_ARRAY }
@@ -235,10 +238,6 @@ def process_bpf_map(func_node, module):
235238 map_name = func_node .name
236239 print (f"Processing BPF map: { map_name } " )
237240
238- BPF_MAP_TYPES = {"HashMap" : process_hash_map , # BPF_MAP_TYPE_HASH
239- "PerfEventArray" : process_perf_event_map , # BPF_MAP_TYPE_PERF_EVENT_ARRAY
240- }
241-
242241 # For now, assume single return statement
243242 return_stmt = None
244243 for stmt in func_node .body :
@@ -252,8 +251,8 @@ def process_bpf_map(func_node, module):
252251
253252 # Handle only HashMap maps
254253 if isinstance (rval , ast .Call ) and isinstance (rval .func , ast .Name ):
255- if rval .func .id in BPF_MAP_TYPES :
256- handler = BPF_MAP_TYPES [ rval . func . id ]
254+ handler = MapProcessorRegistry . get ( rval .func .id )
255+ if handler :
257256 handler (map_name , rval , module )
258257 else :
259258 print (f"Unknown map type { rval .func .id } , defaulting to HashMap" )
0 commit comments