mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
29 lines
837 B
Python
29 lines
837 B
Python
import ast
|
|
from llvmlite import ir
|
|
from .license_pass import license_processing
|
|
from .functions_pass import functions_processing
|
|
|
|
def processor(source_code, filename, module):
|
|
tree = ast.parse(source_code, filename)
|
|
print(ast.dump(tree))
|
|
section_names = []
|
|
section_names.append(license_processing(tree, module))
|
|
section_names.append(functions_processing(tree, module))
|
|
if any(name is None for name in section_names):
|
|
print("Processing failed")
|
|
|
|
def compile_to_ir(filename: str, output: str):
|
|
with open(filename) as f:
|
|
source = f.read()
|
|
|
|
module = ir.Module(name=filename)
|
|
module.data_layout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
|
|
module.triple = "bpf"
|
|
|
|
processor(source, filename, module)
|
|
|
|
with open(output, "w") as f:
|
|
f.write(str(module))
|
|
|
|
return output
|