mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Initialize PythonBPF project and toolchain
This commit is contained in:
20
tools/compile.py
Executable file
20
tools/compile.py
Executable 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()
|
||||
Reference in New Issue
Block a user