From bb6a3421d27b19d8caa203cca96f47210a670070 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Mon, 9 Sep 2019 16:46:46 -0300 Subject: [PATCH] Fix declarations hashing --- include/sirit/sirit.h | 11 ++++++++++- src/sirit.cpp | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index 1a0def9..71f8699 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -920,6 +920,15 @@ public: Id OpImageQuerySamples(Id result_type, Id image); private: + struct HashOp { + std::size_t operator()(const std::unique_ptr& op) const noexcept; + }; + + struct EqualOp { + bool operator()(const std::unique_ptr& lhs, const std::unique_ptr& rhs) const + noexcept; + }; + Id AddCode(std::unique_ptr op); Id AddCode(spv::Op opcode, std::optional id = {}); @@ -945,7 +954,7 @@ private: std::vector> execution_modes; std::vector> debug; std::vector> annotations; - std::unordered_set> declarations; + std::unordered_set, HashOp, EqualOp> declarations; std::vector sorted_declarations; std::vector global_variables; diff --git a/src/sirit.cpp b/src/sirit.cpp index 50135e3..f65e9a5 100644 --- a/src/sirit.cpp +++ b/src/sirit.cpp @@ -20,6 +20,15 @@ static void WriteSet(Stream& stream, const T& set) { } } +std::size_t Module::HashOp::operator()(const std::unique_ptr& op) const noexcept { + return op->Hash(); +} + +bool Module::EqualOp::operator()(const std::unique_ptr& lhs, + const std::unique_ptr& rhs) const noexcept { + return *lhs == *rhs; +} + Module::Module(u32 version) : version(version) {} Module::~Module() = default;