mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-03-29 08:31:28 +00:00
format chore
This commit is contained in:
@ -11,17 +11,17 @@ from llvmlite import ir
|
||||
class StructType:
|
||||
"""
|
||||
Wrapper class for LLVM IR struct types with field access helpers.
|
||||
|
||||
|
||||
Attributes:
|
||||
ir_type: The LLVM IR struct type
|
||||
fields: Dictionary mapping field names to their types
|
||||
size: Total size of the struct in bytes
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, ir_type, fields, size):
|
||||
"""
|
||||
Initialize a StructType.
|
||||
|
||||
|
||||
Args:
|
||||
ir_type: The LLVM IR struct type
|
||||
fields: Dictionary mapping field names to their types
|
||||
@ -34,10 +34,10 @@ class StructType:
|
||||
def field_idx(self, field_name):
|
||||
"""
|
||||
Get the index of a field in the struct.
|
||||
|
||||
|
||||
Args:
|
||||
field_name: The name of the field
|
||||
|
||||
|
||||
Returns:
|
||||
The zero-based index of the field
|
||||
"""
|
||||
@ -46,10 +46,10 @@ class StructType:
|
||||
def field_type(self, field_name):
|
||||
"""
|
||||
Get the LLVM IR type of a field.
|
||||
|
||||
|
||||
Args:
|
||||
field_name: The name of the field
|
||||
|
||||
|
||||
Returns:
|
||||
The LLVM IR type of the field
|
||||
"""
|
||||
@ -58,12 +58,12 @@ class StructType:
|
||||
def gep(self, builder, ptr, field_name):
|
||||
"""
|
||||
Generate a GEP (GetElementPtr) instruction to access a struct field.
|
||||
|
||||
|
||||
Args:
|
||||
builder: LLVM IR builder
|
||||
ptr: Pointer to the struct
|
||||
field_name: Name of the field to access
|
||||
|
||||
|
||||
Returns:
|
||||
A pointer to the field
|
||||
"""
|
||||
@ -77,13 +77,13 @@ class StructType:
|
||||
def field_size(self, field_name):
|
||||
"""
|
||||
Calculate the size of a field in bytes.
|
||||
|
||||
|
||||
Args:
|
||||
field_name: The name of the field
|
||||
|
||||
|
||||
Returns:
|
||||
The size of the field in bytes
|
||||
|
||||
|
||||
Raises:
|
||||
TypeError: If the field type is not supported
|
||||
"""
|
||||
|
||||
@ -35,10 +35,10 @@ def structs_proc(tree, module, chunks):
|
||||
def is_bpf_struct(cls_node):
|
||||
"""
|
||||
Check if a class node is decorated with @struct.
|
||||
|
||||
|
||||
Args:
|
||||
cls_node: The AST class node to check
|
||||
|
||||
|
||||
Returns:
|
||||
True if the class is decorated with @struct, False otherwise
|
||||
"""
|
||||
@ -51,11 +51,11 @@ def is_bpf_struct(cls_node):
|
||||
def process_bpf_struct(cls_node, module):
|
||||
"""
|
||||
Process a single BPF struct definition and create its LLVM IR representation.
|
||||
|
||||
|
||||
Args:
|
||||
cls_node: The AST class node representing the struct
|
||||
module: The LLVM IR module (not used in current implementation)
|
||||
|
||||
|
||||
Returns:
|
||||
A StructType object containing the struct's type information
|
||||
"""
|
||||
@ -71,13 +71,13 @@ def process_bpf_struct(cls_node, module):
|
||||
def parse_struct_fields(cls_node):
|
||||
"""
|
||||
Parse fields of a struct class node.
|
||||
|
||||
|
||||
Args:
|
||||
cls_node: The AST class node representing the struct
|
||||
|
||||
|
||||
Returns:
|
||||
A dictionary mapping field names to their LLVM IR types
|
||||
|
||||
|
||||
Raises:
|
||||
TypeError: If a field has an unsupported type annotation
|
||||
"""
|
||||
@ -95,13 +95,13 @@ def parse_struct_fields(cls_node):
|
||||
def get_type_from_ann(annotation):
|
||||
"""
|
||||
Convert an AST annotation node to an LLVM IR type for struct fields.
|
||||
|
||||
|
||||
Args:
|
||||
annotation: The AST annotation node (e.g., c_int64, str(32))
|
||||
|
||||
|
||||
Returns:
|
||||
The corresponding LLVM IR type
|
||||
|
||||
|
||||
Raises:
|
||||
TypeError: If the annotation type is not supported
|
||||
"""
|
||||
@ -121,10 +121,10 @@ def get_type_from_ann(annotation):
|
||||
def calc_struct_size(field_types):
|
||||
"""
|
||||
Calculate total size of the struct with alignment and padding.
|
||||
|
||||
|
||||
Args:
|
||||
field_types: List of LLVM IR types for each field
|
||||
|
||||
|
||||
Returns:
|
||||
The total size of the struct in bytes
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user