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

20
tools/compile.py Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env python3
import argparse, subprocess, os
from pythonbpf import codegen
def main():
parser = argparse.ArgumentParser()
parser.add_argument("source", help="Python BPF program")
args = parser.parse_args()
ll_file = os.path.splitext(args.source)[0] + ".ll"
o_file = os.path.splitext(args.source)[0] + ".o"
print(f"[+] Compiling {args.source}{ll_file}")
codegen.compile_to_ir(args.source, ll_file)
print("[+] Running llc -march=bpf")
subprocess.run(["llc", "-march=bpf", "-filetype=obj", ll_file, "-o", o_file], check=True)
if __name__ == "__main__":
main()