diff --git a/pythonbpf/codegen.py b/pythonbpf/codegen.py index b749a46..98ff912 100644 --- a/pythonbpf/codegen.py +++ b/pythonbpf/codegen.py @@ -5,6 +5,7 @@ from .functions_pass import func_proc from pythonbpf.maps import maps_proc from .structs.structs_pass import structs_proc from .globals_pass import globals_processing +from .debuginfo import DW_LANG_C11, DwarfBehaviorEnum import os import subprocess import inspect @@ -12,6 +13,7 @@ from pathlib import Path from pylibbpf import BpfProgram import tempfile +VERSION = "v0.1.3" def find_bpf_chunks(tree): """Find all functions decorated with @bpf in the AST.""" @@ -58,7 +60,7 @@ def compile_to_ir(filename: str, output: str): module._debug_compile_unit = module.add_debug_info("DICompileUnit", { # type: ignore "language": 29, # DW_LANG_C11 "file": module._file_metadata, # type: ignore - "producer": "PythonBPF DSL Compiler", + "producer": f"PythonBPF {VERSION}", "isOptimized": True, "runtimeVersion": 0, "emissionKind": 1, @@ -92,7 +94,7 @@ def compile_to_ir(filename: str, output: str): module.add_named_metadata("llvm.module.flags", debug_info_version) module.add_named_metadata("llvm.module.flags", dwarf_version) - module.add_named_metadata("llvm.ident", ["llvmlite PythonBPF v0.0.1"]) + module.add_named_metadata("llvm.ident", [f"PythonBPF {VERSION}"]) print(f"IR written to {output}") with open(output, "w") as f: diff --git a/pythonbpf/debuginfo/__init__.py b/pythonbpf/debuginfo/__init__.py new file mode 100644 index 0000000..4647663 --- /dev/null +++ b/pythonbpf/debuginfo/__init__.py @@ -0,0 +1,2 @@ +from .dwarf_constants import * +from .dtypes import * diff --git a/pythonbpf/debuginfo/dtypes.py b/pythonbpf/debuginfo/dtypes.py new file mode 100644 index 0000000..640b3ae --- /dev/null +++ b/pythonbpf/debuginfo/dtypes.py @@ -0,0 +1,6 @@ +import llvmlite.ir as ir + +class DwarfBehaviorEnum: + ERROR_IF_MISMATCH = ir.Constant(ir.IntType(32), 1) + WARNING_IF_MISMATCH = ir.Constant(ir.IntType(32), 2) + OVERRIDE_USE_LARGEST = ir.Constant(ir.IntType(32), 7) diff --git a/pythonbpf/dwarf_constants.py b/pythonbpf/debuginfo/dwarf_constants.py similarity index 100% rename from pythonbpf/dwarf_constants.py rename to pythonbpf/debuginfo/dwarf_constants.py diff --git a/pythonbpf/maps/maps_pass.py b/pythonbpf/maps/maps_pass.py index a20a874..652d819 100644 --- a/pythonbpf/maps/maps_pass.py +++ b/pythonbpf/maps/maps_pass.py @@ -1,8 +1,8 @@ import ast from llvmlite import ir -from pythonbpf import dwarf_constants as dc from enum import Enum from .maps_utils import MapProcessorRegistry +from ..debuginfo import dwarf_constants as dc import logging logger = logging.getLogger(__name__)