Skip to content

Commit c79dc63

Browse files
committed
Add process_bpf_struct
1 parent 9fc939c commit c79dc63

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pythonbpf/structs_pass.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,24 @@ def structs_proc(tree, module, chunks):
1616
break
1717
if is_struct:
1818
print(f"Found BPF struct: {cls_node.name}")
19+
process_bpf_struct(cls_node, module)
1920
continue
2021
return structs_sym_tab
22+
23+
24+
def process_bpf_struct(cls_node, module):
25+
struct_name = cls_node.name
26+
field_names = []
27+
field_types = []
28+
29+
for item in cls_node.body:
30+
if isinstance(item, ast.AnnAssign) and isinstance(item.target, ast.Name):
31+
field_names.append(item.target.id)
32+
field_types.append(ctypes_to_ir(item.annotation.id))
33+
34+
struct_type = ir.LiteralStructType(field_types)
35+
structs_sym_tab[struct_name] = {
36+
"type": struct_type,
37+
"fields": {name: idx for idx, name in enumerate(field_names)}
38+
}
39+
print(f"Created struct {struct_name} with fields {field_names}")

0 commit comments

Comments
 (0)