Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / unittests / TextAPI / TextStubHelpers.h
blobf8409b10912c34b08622bd017ce712411d901dd0
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 //===-----------------------------------------------------------------------===/
9 #include "llvm/ADT/SmallString.h"
10 #include "llvm/Support/MemoryBuffer.h"
11 #include "llvm/TextAPI/InterfaceFile.h"
12 #include <algorithm>
13 #include <string>
15 #ifndef TEXT_STUB_HELPERS_H
16 #define TEXT_STUB_HELPERS_H
18 namespace llvm {
19 struct ExportedSymbol {
20 MachO::SymbolKind Kind = MachO::SymbolKind::GlobalSymbol;
21 std::string Name = {};
22 bool Weak = false;
23 bool ThreadLocalValue = false;
24 bool isData = false;
25 MachO::TargetList Targets = {};
28 using ExportedSymbolSeq = std::vector<ExportedSymbol>;
29 using TargetToAttr = std::vector<std::pair<llvm::MachO::Target, std::string>>;
30 using TBDFile = std::unique_ptr<MachO::InterfaceFile>;
31 using TBDReexportFile = std::shared_ptr<MachO::InterfaceFile>;
33 inline bool operator<(const ExportedSymbol &LHS, const ExportedSymbol &RHS) {
34 return std::tie(LHS.Kind, LHS.Name) < std::tie(RHS.Kind, RHS.Name);
37 inline bool operator==(const ExportedSymbol &LHS, const ExportedSymbol &RHS) {
38 return std::tie(LHS.Kind, LHS.Name, LHS.Weak, LHS.ThreadLocalValue) ==
39 std::tie(RHS.Kind, RHS.Name, RHS.Weak, RHS.ThreadLocalValue);
42 inline std::string stripWhitespace(std::string S) {
43 S.erase(std::remove_if(S.begin(), S.end(), ::isspace), S.end());
44 return S;
47 // This will transform a single InterfaceFile then compare against the other
48 // InterfaceFile then transform the second InterfaceFile in the same way to
49 // regain equality.
50 inline bool
51 checkEqualityOnTransform(MachO::InterfaceFile &FileA,
52 MachO::InterfaceFile &FileB,
53 void (*Transform)(MachO::InterfaceFile *)) {
54 Transform(&FileA);
55 // Files should not be equal.
56 if (FileA == FileB)
57 return false;
58 Transform(&FileB);
59 // Files should be equal.
60 if (FileA != FileB)
61 return false;
62 return true;
65 } // namespace llvm
66 #endif