From 1a1f2cf634b357fe330591419230ec470b1bc9ad Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Tue, 30 Sep 2025 12:20:07 +0530 Subject: [PATCH] create BPFMapType enum --- pythonbpf/maps_pass.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pythonbpf/maps_pass.py b/pythonbpf/maps_pass.py index 0553996..7484aea 100644 --- a/pythonbpf/maps_pass.py +++ b/pythonbpf/maps_pass.py @@ -2,6 +2,7 @@ import ast from llvmlite import ir from .type_deducer import ctypes_to_ir from . import dwarf_constants as dc +from enum import Enum map_sym_tab = {} @@ -22,6 +23,11 @@ def is_map(func_node): ) +class BPFMapType(Enum): + HASH = 1 + PERF_EVENT_ARRAY = 4 + + BPF_MAP_MAPPINGS = { "HASH": 1, # BPF_MAP_TYPE_HASH "PERF_EVENT_ARRAY": 4, # BPF_MAP_TYPE_PERF_EVENT_ARRAY @@ -186,7 +192,7 @@ def create_map_debug_info(module, map_global, map_name, map_params): def process_hash_map(map_name, rval, module): print(f"Creating HashMap map: {map_name}") - map_params: dict[str, object] = {"type": "HASH"} + map_params: = {"type": BPFMapType.HASH} # Assuming order: key_type, value_type, max_entries if len(rval.args) >= 1 and isinstance(rval.args[0], ast.Name): @@ -214,7 +220,7 @@ def process_hash_map(map_name, rval, module): def process_perf_event_map(map_name, rval, module): print(f"Creating PerfEventArray map: {map_name}") - map_params = {"type": "PERF_EVENT_ARRAY"} + map_params = {"type": BPFMapType.PERF_EVENT_ARRAY} if len(rval.args) >= 1 and isinstance(rval.args[0], ast.Name): map_params["key_size"] = rval.args[0].id