mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Add process_bpf_struct
This commit is contained in:
@ -16,5 +16,24 @@ def structs_proc(tree, module, chunks):
|
|||||||
break
|
break
|
||||||
if is_struct:
|
if is_struct:
|
||||||
print(f"Found BPF struct: {cls_node.name}")
|
print(f"Found BPF struct: {cls_node.name}")
|
||||||
|
process_bpf_struct(cls_node, module)
|
||||||
continue
|
continue
|
||||||
return structs_sym_tab
|
return structs_sym_tab
|
||||||
|
|
||||||
|
|
||||||
|
def process_bpf_struct(cls_node, module):
|
||||||
|
struct_name = cls_node.name
|
||||||
|
field_names = []
|
||||||
|
field_types = []
|
||||||
|
|
||||||
|
for item in cls_node.body:
|
||||||
|
if isinstance(item, ast.AnnAssign) and isinstance(item.target, ast.Name):
|
||||||
|
field_names.append(item.target.id)
|
||||||
|
field_types.append(ctypes_to_ir(item.annotation.id))
|
||||||
|
|
||||||
|
struct_type = ir.LiteralStructType(field_types)
|
||||||
|
structs_sym_tab[struct_name] = {
|
||||||
|
"type": struct_type,
|
||||||
|
"fields": {name: idx for idx, name in enumerate(field_names)}
|
||||||
|
}
|
||||||
|
print(f"Created struct {struct_name} with fields {field_names}")
|
||||||
|
|||||||
Reference in New Issue
Block a user