#pragma once // // This file is distributed under the MIT License. See LICENSE.md for details. // #include "nanobind/nanobind.h" #include "revng/PipeboxCommon/Common.h" #include "revng/PipeboxCommon/Concepts.h" #include "revng/PipeboxCommon/Helpers/Python/Helpers.h" #include "revng/PipeboxCommon/Model.h" namespace revng::pypeline::helpers::python { template inline nanobind::object invalidate(T &Handle, nanobind::list PyInvalidationData, nanobind::handle_t Diff) { // Convert the invalidation data from python to C++ InvalidationData Data; for (nanobind::handle List : PyInvalidationData) { auto &CppList = Data.emplace_back(); for (nanobind::handle Entry : nanobind::cast(List)) { nanobind::tuple Tuple = nanobind::cast(Entry); nanobind::bytes Bytes = nanobind::cast(Tuple[1]); CppList.push_back({ nanobind::cast(Tuple[0]), { reinterpret_cast(Bytes.data()), Bytes.size() } }); } } // Run the actual invalidate method ModelDiff *CppDiff = nanobind::cast(Diff); std::vector> CppResult = Handle.invalidate(Data, *CppDiff); // Convert the result to a list[ObjectSet] using Traits = PipeRunTraits; nanobind::object ObjectSetCls = importObject("revng.pypeline.object." "ObjectSet"); nanobind::list Result; for (size_t I = 0; I < CppResult.size(); I++) { compile_time::repeat([&]() { if (I != J) return; using CT = std::tuple_element_t; nanobind::object PyKind = nanobind::cast(CT::Kind); nanobind::list ObjectList; for (const ObjectID &Object : CppResult[I]) ObjectList.append(Object); nanobind::object ObjectSet = ObjectSetCls(PyKind, nanobind::set(ObjectList)); Result.append(ObjectSet); }); } return Result; } } // namespace revng::pypeline::helpers::python