Update imports to use direct namespace imports

WARNING: OLD STYLE IMPORTS DO NOT WORK The old style of importing the
full module and using pb.* prefixes has been replaced with direct
imports of the needed names. This makes the code more explicit about
what is being used and removes the unnecessary pb prefix.
This commit is contained in:
2025-09-09 17:12:04 +05:30
parent ccd2bb3366
commit 8ee5d03c5d
3 changed files with 28 additions and 26 deletions

View File

@ -6,8 +6,8 @@ from .maps_pass import maps_proc
from .globals_pass import globals_processing
import os
import subprocess
import pathlib
import __main__
import inspect
from pathlib import Path
def find_bpf_chunks(tree):
"""Find all functions decorated with @bpf in the AST."""
@ -96,12 +96,14 @@ def compile_to_ir(filename: str, output: str):
return output
def compile():
main_file = pathlib.Path(__main__.__file__).resolve()
# Look one level up the stack to the caller of this function
caller_frame = inspect.stack()[1]
caller_file = Path(caller_frame.filename).resolve()
ll_file = pathlib.Path("/tmp") / main_file.with_suffix(".ll").name
o_file = main_file.with_suffix(".o")
ll_file = Path("/tmp") / caller_file.with_suffix(".ll").name
o_file = caller_file.with_suffix(".o")
compile_to_ir(str(main_file), str(ll_file))
compile_to_ir(str(caller_file), str(ll_file))
subprocess.run([
"llc", "-march=bpf", "-filetype=obj", "-O2",