Initialize PythonBPF project and toolchain

This commit is contained in:
2025-08-30 18:08:14 +05:30
commit d5557d3c01
10 changed files with 119 additions and 0 deletions

0
pythonbpf/__init__.py Normal file
View File

19
pythonbpf/codegen.py Normal file
View File

@ -0,0 +1,19 @@
import ast
from llvmlite import ir
def compile_to_ir(filename: str, output: str):
with open(filename) as f:
ast.parse(f.read(), filename)
module = ir.Module(name="pythonbpf")
func_ty = ir.FunctionType(ir.IntType(64), [], False)
func = ir.Function(module, func_ty, name="trace_execve")
block = func.append_basic_block(name="entry")
builder = ir.IRBuilder(block)
builder.ret(ir.IntType(64)(0))
with open(output, "w") as f:
f.write(str(module))
return output

15
pythonbpf/decorators.py Normal file
View File

@ -0,0 +1,15 @@
def tracepoint(name: str):
def wrapper(fn):
fn._section = f"tracepoint/{name}"
return fn
return wrapper
def license(name: str):
def wrapper(fn):
fn._license = name
return fn
return wrapper
def trace_printk(msg: str):
# placeholder — real version lowers to IR later
print(f"[trace_printk] {msg}")