Skip to content

Commit 4557b09

Browse files
committed
Use StructType in struct_pass, fix indexing
1 parent 8450030 commit 4557b09

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

pythonbpf/structs/struct_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def __init__(self, ir_type, fields, size):
88
self.size = size
99

1010
def field_idx(self, field_name):
11-
return self.fields.keys().index(field_name)
11+
return list(self.fields.keys()).index(field_name)
1212

1313
def field_type(self, field_name):
1414
return self.fields[field_name]

pythonbpf/structs/structs_pass.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
from llvmlite import ir
44
from .type_deducer import ctypes_to_ir
5+
from .struct_type import StructType
56

67
logger = logging.getLogger(__name__)
78

@@ -35,14 +36,11 @@ def process_bpf_struct(cls_node, module):
3536
""" Process a single BPF struct definition """
3637

3738
fields = parse_struct_fields(cls_node)
38-
total_size = calc_struct_size(fields.values())
39-
struct_type = ir.LiteralStructType(fields.values())
39+
field_types = list(fields.values())
40+
total_size = calc_struct_size(field_types)
41+
struct_type = ir.LiteralStructType(field_types)
4042
logger.info(f"Created struct {cls_node.name} with fields {fields.keys()}")
41-
return {
42-
"type": struct_type,
43-
"fields": fields,
44-
"size": total_size,
45-
}
43+
return StructType(struct_type, fields, total_size)
4644

4745

4846
def parse_struct_fields(cls_node):

0 commit comments

Comments
 (0)