mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
21 lines
617 B
Python
Executable File
21 lines
617 B
Python
Executable File
#!/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()
|