serene/include/serene/llvm/patches.h

57 lines
1.6 KiB
C
Raw Normal View History

/* -*- C++ -*-
2021-10-12 20:51:03 +01:00
* Serene Programming Language
*
2021-10-12 20:51:03 +01:00
* Copyright (c) 2019-2021 Sameer Rahmani <lxsameer@gnu.org>
*
2021-10-12 20:51:03 +01:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
2021-10-12 20:51:03 +01:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
2021-10-12 20:51:03 +01:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2021-10-17 20:12:17 +01:00
#ifndef LLVM_PATCHES_H
#define LLVM_PATCHES_H
2021-10-12 20:51:03 +01:00
#include <llvm/ADT/DenseMap.h>
namespace llvm {
// Our specialization of DensMapInfo for string type. This will allow use to use
// string
template <>
struct DenseMapInfo<std::string> {
static inline std::string getEmptyKey() { return ""; }
static inline std::string getTombstoneKey() {
// Maybe we need to use something else beside strings ????
return "0TOMBED";
}
2021-10-17 20:12:17 +01:00
static unsigned getHashValue(const std::string &Val) {
assert(Val != getEmptyKey() && "Cannot hash the empty key!");
assert(Val != getTombstoneKey() && "Cannot hash the tombstone key!");
return (unsigned)(llvm::hash_value(Val));
}
2021-10-17 20:12:17 +01:00
static bool isEqual(const std::string &LHS, const std::string &RHS) {
if (RHS == getEmptyKey()) {
return LHS == getEmptyKey();
2021-10-17 20:12:17 +01:00
}
if (RHS == getTombstoneKey()) {
return LHS == getTombstoneKey();
2021-10-17 20:12:17 +01:00
}
return LHS == RHS;
}
};
} // namespace llvm
#endif