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 | MachO::EncodeKind Kind = MachO::EncodeKind::GlobalSymbol; |
20 | std::string Name = {}; |
21 | bool Weak = false; |
22 | bool ThreadLocalValue = false; |
23 | bool isData = false; |
24 | MachO::TargetList Targets = {}; |
25 | }; |
26 | |
27 | using ExportedSymbolSeq = std::vector<ExportedSymbol>; |
28 | using TargetToAttr = std::vector<std::pair<llvm::MachO::Target, std::string>>; |
29 | using TBDFile = std::unique_ptr<MachO::InterfaceFile>; |
30 | using TBDReexportFile = std::shared_ptr<MachO::InterfaceFile>; |
31 | |
32 | inline bool operator<(const ExportedSymbol &LHS, const ExportedSymbol &RHS) { |
33 | return std::tie(args: LHS.Kind, args: LHS.Name) < std::tie(args: RHS.Kind, args: RHS.Name); |
34 | } |
35 | |
36 | inline bool operator==(const ExportedSymbol &LHS, const ExportedSymbol &RHS) { |
37 | return std::tie(args: LHS.Kind, args: LHS.Name, args: LHS.Weak, args: LHS.ThreadLocalValue) == |
38 | std::tie(args: RHS.Kind, args: RHS.Name, args: RHS.Weak, args: RHS.ThreadLocalValue); |
39 | } |
40 | |
41 | inline std::string stripWhitespace(std::string S) { |
42 | S.erase(first: std::remove_if(first: S.begin(), last: S.end(), pred: ::isspace), last: S.end()); |
43 | return S; |
44 | } |
45 | |
46 | // This will transform a single InterfaceFile then compare against the other |
47 | // InterfaceFile then transform the second InterfaceFile in the same way to |
48 | // regain equality. |
49 | inline bool |
50 | checkEqualityOnTransform(MachO::InterfaceFile &FileA, |
51 | MachO::InterfaceFile &FileB, |
52 | void (*Transform)(MachO::InterfaceFile *)) { |
53 | Transform(&FileA); |
54 | // Files should not be equal. |
55 | if (FileA == FileB) |
56 | return false; |
57 | Transform(&FileB); |
58 | // Files should be equal. |
59 | if (FileA != FileB) |
60 | return false; |
61 | return true; |
62 | } |
63 | |
64 | } // namespace llvm |
65 | #endif |
66 | |