xref: /llvm-project/llvm/unittests/TextAPI/TextStubHelpers.h (revision d9a9872ec4760762fdc467ef283cea302a3742e5)
15810ed51SJonas Devlieghere //===-- TextStubHelpers.cpp -------------------------------------*- C++ -*-===//
25810ed51SJonas Devlieghere //
35810ed51SJonas Devlieghere // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45810ed51SJonas Devlieghere // See https://llvm.org/LICENSE.txt for license information.
55810ed51SJonas Devlieghere // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65810ed51SJonas Devlieghere //
75810ed51SJonas Devlieghere //===-----------------------------------------------------------------------===/
85810ed51SJonas Devlieghere 
9c5b9fa1cSSimon Pilgrim #include "llvm/Support/MemoryBuffer.h"
100116d04dSCyndy Ishida #include "llvm/TextAPI/InterfaceFile.h"
115810ed51SJonas Devlieghere #include <algorithm>
125810ed51SJonas Devlieghere #include <string>
135810ed51SJonas Devlieghere 
145810ed51SJonas Devlieghere #ifndef TEXT_STUB_HELPERS_H
155810ed51SJonas Devlieghere #define TEXT_STUB_HELPERS_H
165810ed51SJonas Devlieghere 
175810ed51SJonas Devlieghere namespace llvm {
185810ed51SJonas Devlieghere struct ExportedSymbol {
19*d9a9872eSCyndy Ishida   MachO::EncodeKind Kind = MachO::EncodeKind::GlobalSymbol;
2079320a0cSCyndy Ishida   std::string Name = {};
2179320a0cSCyndy Ishida   bool Weak = false;
2279320a0cSCyndy Ishida   bool ThreadLocalValue = false;
23b70d87bcSCyndy Ishida   bool isData = false;
2479320a0cSCyndy Ishida   MachO::TargetList Targets = {};
255810ed51SJonas Devlieghere };
265810ed51SJonas Devlieghere 
275810ed51SJonas Devlieghere using ExportedSymbolSeq = std::vector<ExportedSymbol>;
28b70d87bcSCyndy Ishida using TargetToAttr = std::vector<std::pair<llvm::MachO::Target, std::string>>;
292ba32084SCyndy Ishida using TBDFile = std::unique_ptr<MachO::InterfaceFile>;
300b15cb70SCyndy Ishida using TBDReexportFile = std::shared_ptr<MachO::InterfaceFile>;
315810ed51SJonas Devlieghere 
325810ed51SJonas Devlieghere inline bool operator<(const ExportedSymbol &LHS, const ExportedSymbol &RHS) {
335810ed51SJonas Devlieghere   return std::tie(LHS.Kind, LHS.Name) < std::tie(RHS.Kind, RHS.Name);
345810ed51SJonas Devlieghere }
355810ed51SJonas Devlieghere 
365810ed51SJonas Devlieghere inline bool operator==(const ExportedSymbol &LHS, const ExportedSymbol &RHS) {
3779320a0cSCyndy Ishida   return std::tie(LHS.Kind, LHS.Name, LHS.Weak, LHS.ThreadLocalValue) ==
3879320a0cSCyndy Ishida          std::tie(RHS.Kind, RHS.Name, RHS.Weak, RHS.ThreadLocalValue);
395810ed51SJonas Devlieghere }
405810ed51SJonas Devlieghere 
stripWhitespace(std::string S)415810ed51SJonas Devlieghere inline std::string stripWhitespace(std::string S) {
425810ed51SJonas Devlieghere   S.erase(std::remove_if(S.begin(), S.end(), ::isspace), S.end());
435810ed51SJonas Devlieghere   return S;
445810ed51SJonas Devlieghere }
45eb2eeeb7SSam Powell 
46eb2eeeb7SSam Powell // This will transform a single InterfaceFile then compare against the other
47eb2eeeb7SSam Powell // InterfaceFile then transform the second InterfaceFile in the same way to
48eb2eeeb7SSam Powell // regain equality.
49eb2eeeb7SSam Powell inline bool
checkEqualityOnTransform(MachO::InterfaceFile & FileA,MachO::InterfaceFile & FileB,void (* Transform)(MachO::InterfaceFile *))50eb2eeeb7SSam Powell checkEqualityOnTransform(MachO::InterfaceFile &FileA,
51eb2eeeb7SSam Powell                          MachO::InterfaceFile &FileB,
52eb2eeeb7SSam Powell                          void (*Transform)(MachO::InterfaceFile *)) {
53eb2eeeb7SSam Powell   Transform(&FileA);
54eb2eeeb7SSam Powell   // Files should not be equal.
55eb2eeeb7SSam Powell   if (FileA == FileB)
56eb2eeeb7SSam Powell     return false;
57eb2eeeb7SSam Powell   Transform(&FileB);
58eb2eeeb7SSam Powell   // Files should be equal.
59eb2eeeb7SSam Powell   if (FileA != FileB)
60eb2eeeb7SSam Powell     return false;
61eb2eeeb7SSam Powell   return true;
62eb2eeeb7SSam Powell }
63eb2eeeb7SSam Powell 
645810ed51SJonas Devlieghere } // namespace llvm
655810ed51SJonas Devlieghere #endif
66