@@ -22,33 +22,17 @@ PythonBPF uses decorators to mark code for BPF compilation:
2222
2323Your Python code goes through several stages:
2424
25- 1 . ** AST Parsing** - Python code is parsed into an Abstract Syntax Tree
26- 2 . ** IR Generation** - The AST is transformed into LLVM IR using llvmlite
27- 3 . ** BPF Compilation** - LLVM IR is compiled to BPF bytecode using ` llc `
28- 4 . ** Loading** - The BPF object is loaded into the kernel using libbpf
29- 5 . ** Attachment** - Programs are attached to kernel hooks (tracepoints, kprobes, etc.)
30-
31- ## Guide Contents
32-
33- ``` {toctree}
34- :maxdepth: 2
35-
36- decorators
37- maps
38- structs
39- compilation
40- helpers
41- ```
25+ 1 . ** IR Generation** - The Python AST is transformed into LLVM IR using llvmlite
26+ 2 . ** BPF Compilation** - LLVM IR is compiled to BPF bytecode using ` llc `
27+ 3 . ** Loading** - The BPF object is loaded into the kernel using libbpf
28+ 4 . ** Attachment** - Programs are attached to kernel hooks (tracepoints, kprobes, etc.)
4229
4330## Code Organization
4431
4532When writing BPF programs with PythonBPF, we recommend:
4633
47- 1 . ** Keep BPF code in separate files** - Easier to manage and test
48- 2 . ** Use type hints** - Required for proper code generation
49- 3 . ** Follow naming conventions** - Use descriptive names for maps and functions
50- 4 . ** Document your code** - Add comments explaining BPF-specific logic
51- 5 . ** Test incrementally** - Verify each component works before adding complexity
34+ 1 . ** Use type hints** - Required for proper code generation
35+ 2 . ** Test incrementally** - Verify each component works before adding complexity
5236
5337## Type System
5438
@@ -65,7 +49,7 @@ PythonBPF uses Python's `ctypes` module for type definitions:
6549A typical PythonBPF program follows this structure:
6650
6751``` python
68- from pythonbpf import bpf, map , section, bpfglobal, BPF
52+ from pythonbpf import bpf, map , section, bpfglobal, BPF , compile
6953from pythonbpf.maps import HashMap
7054from ctypes import c_void_p, c_int64, c_uint32
7155
@@ -80,7 +64,7 @@ def my_map() -> HashMap:
8064@section (" tracepoint/..." )
8165def my_function (ctx : c_void_p) -> c_int64:
8266 # BPF logic here
83- return c_int64( 0 )
67+ return 0
8468
8569# License (required)
8670@bpf
@@ -93,6 +77,9 @@ if __name__ == "__main__":
9377 b = BPF()
9478 b.load_and_attach()
9579 # Use the program...
80+
81+ # Or, compile to an object file
82+ compile ()
9683```
9784
9885## Next Steps
0 commit comments