#pragma once // // This file is distributed under the MIT License. See LICENSE.md for details. // #include "revng/Model/Binary.h" #include "revng/PipeboxCommon/Common.h" #include "revng/Support/MetaAddress.h" class ModelDiff { private: TupleTreeDiff Diff; public: ModelDiff(TupleTreeDiff Diff) : Diff(Diff) {} std::set paths() const { std::set Result; for (auto &Entry : Diff.Changes) { auto MaybePath = pathAsString(Entry.Path); Result.insert(MaybePath.value()); } return Result; } llvm::SmallVector serialize() const { llvm::SmallVector Out; llvm::raw_svector_ostream OS(Out); ::serialize(OS, Diff); return Out; } public: TupleTreeDiff &get() { return Diff; } const TupleTreeDiff &get() const { return Diff; } }; class Model { private: TupleTree TheModel; public: ModelDiff diff(const Model &Other) const { return ModelDiff(::diff(*TheModel.get(), *Other.TheModel.get())); } Model clone() const { return *this; } std::set children(const ObjectID &Obj, Kind Kind) const { if (Obj.kind() == Kinds::Binary and Kind == Kinds::Function) { std::set Result; for (const model::Function &F : TheModel->Functions()) Result.insert(ObjectID(F.Entry())); return Result; } if (Obj.kind() == Kinds::Binary and Kind == Kinds::TypeDefinition) { std::set Result; for (const UpcastablePointer &TD : TheModel->TypeDefinitions()) Result.insert(ObjectID(TD->key())); return Result; } revng_abort(); } llvm::SmallVector serialize() const { llvm::SmallVector Out; llvm::raw_svector_ostream OS(Out); TheModel.serialize(OS); return Out; } static llvm::Expected deserialize(llvm::ArrayRef Input) { llvm::StringRef String{ reinterpret_cast(Input.data()), Input.size() }; auto MaybeModel = TupleTree::fromString(String); if (not MaybeModel) return MaybeModel.takeError(); Model Result; Result.TheModel = std::move(*MaybeModel); return Result; } bool operator==(const Model &Other) const { if (this == &Other) return true; return *this->get().get() == *Other.get().get(); } void enableCaching() { TheModel.enableReferenceCaching(); } void disableCaching() { TheModel.disableReferenceCaching(); } public: TupleTree &get() { return TheModel; } const TupleTree &get() const { return TheModel; } };