Skip to content

Commit 1a1f2cf

Browse files
committed
create BPFMapType enum
1 parent 0d69186 commit 1a1f2cf

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

pythonbpf/maps_pass.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from llvmlite import ir
33
from .type_deducer import ctypes_to_ir
44
from . import dwarf_constants as dc
5+
from enum import Enum
56

67
map_sym_tab = {}
78

@@ -22,6 +23,11 @@ def is_map(func_node):
2223
)
2324

2425

26+
class BPFMapType(Enum):
27+
HASH = 1
28+
PERF_EVENT_ARRAY = 4
29+
30+
2531
BPF_MAP_MAPPINGS = {
2632
"HASH": 1, # BPF_MAP_TYPE_HASH
2733
"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):
186192

187193
def process_hash_map(map_name, rval, module):
188194
print(f"Creating HashMap map: {map_name}")
189-
map_params: dict[str, object] = {"type": "HASH"}
195+
map_params: = {"type": BPFMapType.HASH}
190196

191197
# Assuming order: key_type, value_type, max_entries
192198
if len(rval.args) >= 1 and isinstance(rval.args[0], ast.Name):
@@ -214,7 +220,7 @@ def process_hash_map(map_name, rval, module):
214220

215221
def process_perf_event_map(map_name, rval, module):
216222
print(f"Creating PerfEventArray map: {map_name}")
217-
map_params = {"type": "PERF_EVENT_ARRAY"}
223+
map_params = {"type": BPFMapType.PERF_EVENT_ARRAY}
218224

219225
if len(rval.args) >= 1 and isinstance(rval.args[0], ast.Name):
220226
map_params["key_size"] = rval.args[0].id

0 commit comments

Comments
 (0)