| 1 |
//===-- TextStubHelpers.cpp -------------------------------------*- C++ -*-===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===-----------------------------------------------------------------------===/ |
| 8 |
|
| 9 |
#include "llvm/Support/MemoryBuffer.h" |
| 10 |
#include "llvm/TextAPI/InterfaceFile.h" |
| 11 |
#include <algorithm> |
| 12 |
#include <string> |
| 13 |
|
| 14 |
#ifndef TEXT_STUB_HELPERS_H |
| 15 |
#define TEXT_STUB_HELPERS_H |
| 16 |
|
| 17 |
namespace llvm { |
| 18 |
struct ExportedSymbol { |
| 19 |
llvm::MachO::SymbolKind Kind; |
| 20 |
std::string Name; |
| 21 |
bool WeakDefined; |
| 22 |
bool ThreadLocalValue; |
| 23 |
}; |
| 24 |
|
| 25 |
using ExportedSymbolSeq = std::vector<ExportedSymbol>; |
| 26 |
using UUIDs = std::vector<std::pair<llvm::MachO::Target, std::string>>; |
| 27 |
using TBDFile = std::unique_ptr<MachO::InterfaceFile>; |
| 28 |
using TBDReexportFile = std::shared_ptr<MachO::InterfaceFile>; |
| 29 |
|
| 30 |
inline bool operator<(const ExportedSymbol &LHS, const ExportedSymbol &RHS) { |
| 31 |
return std::tie(LHS.Kind, LHS.Name) < std::tie(RHS.Kind, RHS.Name); |
| 32 |
} |
| 33 |
|
| 34 |
inline bool operator==(const ExportedSymbol &LHS, const ExportedSymbol &RHS) { |
| 35 |
return std::tie(LHS.Kind, LHS.Name, LHS.WeakDefined, LHS.ThreadLocalValue) == |
| 36 |
std::tie(RHS.Kind, RHS.Name, RHS.WeakDefined, RHS.ThreadLocalValue); |
| 37 |
} |
| 38 |
|
| 39 |
inline std::string stripWhitespace(std::string S) { |
| 40 |
S.erase(std::remove_if(S.begin(), S.end(), ::isspace), S.end()); |
| 41 |
return S; |
| 42 |
} |
| 43 |
|
| 44 |
// This will transform a single InterfaceFile then compare against the other |
| 45 |
// InterfaceFile then transform the second InterfaceFile in the same way to |
| 46 |
// regain equality. |
| 47 |
inline bool |
| 48 |
checkEqualityOnTransform(MachO::InterfaceFile &FileA, |
| 49 |
MachO::InterfaceFile &FileB, |
| 50 |
void (*Transform)(MachO::InterfaceFile *)) { |
| 51 |
Transform(&FileA); |
| 52 |
// Files should not be equal. |
| 53 |
if (FileA == FileB) |
| 54 |
return false; |
| 55 |
Transform(&FileB); |
| 56 |
// Files should be equal. |
| 57 |
if (FileA != FileB) |
| 58 |
return false; |
| 59 |
return true; |
| 60 |
} |
| 61 |
|
| 62 |
} // namespace llvm |
| 63 |
#endif |