wip, removing parsing from string inside the class RegisterAddress, BitAddress and RegisterValue

This commit is contained in:
2025-12-18 13:14:50 +01:00
parent 3546a4fe4b
commit 2bcec2ae31
17 changed files with 234 additions and 269 deletions

View File

@@ -8,6 +8,7 @@ to be installed.
When the Detector API is updated this file should be run
manually.
"""
import os
from clang import cindex
import subprocess
import argparse
@@ -33,6 +34,24 @@ def green(msg):
return f"{GREENC}{msg}{ENDC}"
def find_libclang():
"""Find libclang in the current Conda/Mamba environment."""
conda_prefix = os.environ.get("CONDA_PREFIX")
if conda_prefix:
lib_dir = os.path.join(conda_prefix, "lib")
# Look for libclang*.so files
for f in os.listdir(lib_dir):
if f.startswith("libclang") and f.endswith(".so"):
return os.path.join(lib_dir, f)
# fallback: system-wide search
path = ctypes.util.find_library("clang")
if path:
return path
raise FileNotFoundError("libclang not found in CONDA_PREFIX or system paths.")
def check_libclang_version(required="12"):
# Use already-loaded libclang, or let cindex resolve it
lib = ctypes.CDLL(cindex.Config.library_file or ctypes.util.find_library("clang"))
@@ -201,7 +220,9 @@ if __name__ == "__main__":
action="store_true",
)
cargs = parser.parse_args()
libclang_path = find_libclang()
cindex.Config.set_library_file(libclang_path)
check_libclang_version("12")
check_clang_format_version(12)
check_for_compile_commands_json(cargs.build_path)

View File

@@ -17,7 +17,6 @@ void init_bit(py::module &m) {
py::class_<RegisterAddress>(m, "RegisterAddress")
.def(py::init())
.def(py::init<const std::string &>())
.def(py::init<uint32_t>())
.def(py::init<const RegisterAddress &>())
.def("__repr__", &RegisterAddress::str)
@@ -29,7 +28,6 @@ void init_bit(py::module &m) {
py::class_<BitAddress>(m, "BitAddress")
.def(py::init())
.def(py::init<RegisterAddress, uint32_t>())
.def(py::init<std::string, std::string>())
.def("__repr__", &BitAddress::str)
.def("str", &BitAddress::str)
.def("address", &BitAddress::address)
@@ -39,7 +37,6 @@ void init_bit(py::module &m) {
py::class_<RegisterValue>(m, "RegisterValue")
.def(py::init<>())
.def(py::init<const std::string &>())
.def(py::init<uint32_t>())
.def(py::init<const RegisterValue &>())
.def("__repr__", &RegisterValue::str)
@@ -47,14 +44,15 @@ void init_bit(py::module &m) {
.def("value", &RegisterValue::value)
.def(py::self == py::self)
.def(py::self != py::self)
.def("__or__", [](const RegisterValue &lhs, const RegisterValue &rhs) {
return lhs | rhs;
})
.def("__or__", [](const RegisterValue& lhs, uint32_t rhs) {
return lhs | rhs;
})
.def("__ior__", [](RegisterValue &lhs, uint32_t rhs) -> RegisterValue& {
lhs |= rhs;
return lhs;
}, py::return_value_policy::reference_internal);
.def("__or__", [](const RegisterValue &lhs,
const RegisterValue &rhs) { return lhs | rhs; })
.def("__or__",
[](const RegisterValue &lhs, uint32_t rhs) { return lhs | rhs; })
.def(
"__ior__",
[](RegisterValue &lhs, uint32_t rhs) -> RegisterValue & {
lhs |= rhs;
return lhs;
},
py::return_value_policy::reference_internal);
}