3 Commits

Author SHA1 Message Date
a2b1a8baff Clarify compilation target in package documentation
Updated documentation to clarify that the compilation targets LLVM IR instead of eBPF bytecode directly.
2025-10-09 10:10:34 +05:30
22289821f9 format chore 2025-10-09 10:06:17 +05:30
d86dd683f4 ignore vmlinux and extend example 2025-10-09 10:04:35 +05:30
21 changed files with 138 additions and 129 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ __pycache__/
*.ll *.ll
*.o *.o
.ipynb_checkpoints/ .ipynb_checkpoints/
vmlinux.py

View File

@ -2,7 +2,7 @@
PythonBPF - A Python frontend for eBPF programs. PythonBPF - A Python frontend for eBPF programs.
This package provides decorators and compilation tools to write BPF programs This package provides decorators and compilation tools to write BPF programs
in Python syntax and compile them to eBPF bytecode that can run in the kernel. in Python syntax and compile them to LLVM IR that can be compiled to eBPF bytecode.
""" """
from .decorators import bpf, map, section, bpfglobal, struct from .decorators import bpf, map, section, bpfglobal, struct

View File

@ -5,6 +5,7 @@ import llvmlite.ir as ir
class DwarfBehaviorEnum: class DwarfBehaviorEnum:
"""DWARF module flag behavior constants for LLVM.""" """DWARF module flag behavior constants for LLVM."""
ERROR_IF_MISMATCH = ir.Constant(ir.IntType(32), 1) ERROR_IF_MISMATCH = ir.Constant(ir.IntType(32), 1)
WARNING_IF_MISMATCH = ir.Constant(ir.IntType(32), 2) WARNING_IF_MISMATCH = ir.Constant(ir.IntType(32), 2)
OVERRIDE_USE_LARGEST = ir.Constant(ir.IntType(32), 7) OVERRIDE_USE_LARGEST = ir.Constant(ir.IntType(32), 7)

View File

@ -40,6 +40,7 @@ def section(name: str):
Returns: Returns:
A decorator function that marks the function with the section name A decorator function that marks the function with the section name
""" """
def wrapper(fn): def wrapper(fn):
"""Decorator that sets the section name on the function.""" """Decorator that sets the section name on the function."""
fn._section = name fn._section = name

View File

@ -33,6 +33,7 @@ class LocalSymbol:
ir_type: LLVM IR type of the variable ir_type: LLVM IR type of the variable
metadata: Optional metadata (e.g., struct type name) metadata: Optional metadata (e.g., struct type name)
""" """
var: ir.AllocaInstr var: ir.AllocaInstr
ir_type: ir.Type ir_type: ir.Type
metadata: Any = None metadata: Any = None

View File

@ -25,6 +25,7 @@ logger: Logger = logging.getLogger(__name__)
class BPFHelperID(Enum): class BPFHelperID(Enum):
"""Enumeration of BPF helper function IDs.""" """Enumeration of BPF helper function IDs."""
BPF_MAP_LOOKUP_ELEM = 1 BPF_MAP_LOOKUP_ELEM = 1
BPF_MAP_UPDATE_ELEM = 2 BPF_MAP_UPDATE_ELEM = 2
BPF_MAP_DELETE_ELEM = 3 BPF_MAP_DELETE_ELEM = 3

View File

@ -6,6 +6,7 @@ These are used for type checking and map definition; the actual BPF maps
are generated as LLVM IR during compilation. are generated as LLVM IR during compilation.
""" """
# This file provides type and function hints only and does not actually give any functionality. # This file provides type and function hints only and does not actually give any functionality.
class HashMap: class HashMap:
""" """

View File

@ -44,6 +44,7 @@ def is_map(func_node):
class BPFMapType(Enum): class BPFMapType(Enum):
"""Enumeration of BPF map types.""" """Enumeration of BPF map types."""
UNSPEC = 0 UNSPEC = 0
HASH = 1 HASH = 1
ARRAY = 2 ARRAY = 2

View File

@ -33,3 +33,5 @@ compile_to_ir("ringbuf.py", "ringbuf.ll")
compile() compile()
b = BPF() b = BPF()
b.load_and_attach() b.load_and_attach()
while True:
print("running")