LLVM 18.0.0git
Symbol.cpp
Go to the documentation of this file.
1//===- Symbol.cpp ---------------------------------------------------------===//
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// Implements the Symbol.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/TextAPI/Symbol.h"
14#include <string>
15
16namespace llvm {
17namespace MachO {
18
19#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
21 std::string Result;
22 if (isUndefined())
23 Result += "(undef) ";
24 if (isWeakDefined())
25 Result += "(weak-def) ";
26 if (isWeakReferenced())
27 Result += "(weak-ref) ";
29 Result += "(tlv) ";
30 switch (Kind) {
32 Result += Name.str();
33 break;
35 Result += "(ObjC Class) " + Name.str();
36 break;
38 Result += "(ObjC Class EH) " + Name.str();
39 break;
41 Result += "(ObjC IVar) " + Name.str();
42 break;
43 }
44 OS << Result;
45}
46#endif
47
49Symbol::targets(ArchitectureSet Architectures) const {
50 std::function<bool(const Target &)> FN =
51 [Architectures](const Target &Target) {
52 return Architectures.has(Target.Arch);
53 };
54 return make_filter_range(Targets, FN);
55}
56
57bool Symbol::operator==(const Symbol &O) const {
58 // Older Tapi files do not express all these symbol flags. In those
59 // cases, ignore those differences.
60 auto RemoveFlag = [](const Symbol &Sym, SymbolFlags &Flag) {
61 if (Sym.isData())
62 Flag &= ~SymbolFlags::Data;
63 if (Sym.isText())
64 Flag &= ~SymbolFlags::Text;
65 };
66 SymbolFlags LHSFlags = Flags;
67 SymbolFlags RHSFlags = O.Flags;
68 // Ignore Text and Data for now.
69 RemoveFlag(*this, LHSFlags);
70 RemoveFlag(O, RHSFlags);
71 return std::tie(Name, Kind, Targets, LHSFlags) ==
72 std::tie(O.Name, O.Kind, O.Targets, RHSFlags);
73}
74
77 return {SymName.drop_front(ObjC1ClassNamePrefix.size()),
80 return {SymName.drop_front(ObjC2ClassNamePrefix.size()),
83 return {SymName.drop_front(ObjC2MetaClassNamePrefix.size()),
85 if (SymName.startswith(ObjC2EHTypePrefix)) {
86 // When classes without ehtype are used in try/catch blocks
87 // a weak-defined symbol is exported. In those cases, treat these as a
88 // global instead.
90 return {SymName, SymbolKind::GlobalSymbol};
91 return {SymName.drop_front(ObjC2EHTypePrefix.size()),
93 }
94
95 if (SymName.startswith(ObjC2IVarPrefix))
96 return {SymName.drop_front(ObjC2IVarPrefix.size()),
98 return {SymName, SymbolKind::GlobalSymbol};
99}
100
101} // end namespace MachO.
102} // end namespace llvm.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:510
Symbol * Sym
Definition: ELF_riscv.cpp:477
raw_pwrite_stream & OS
bool has(Architecture Arch) const
void dump() const
Definition: Symbol.h:145
bool isWeakDefined() const
Definition: Symbol.h:95
bool isUndefined() const
Definition: Symbol.h:108
const_target_range targets() const
Definition: Symbol.h:134
bool operator==(const Symbol &O) const
Definition: Symbol.cpp:57
bool isThreadLocalValue() const
Definition: Symbol.h:103
bool isWeakReferenced() const
Definition: Symbol.h:99
Architecture Arch
Definition: Target.h:42
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:222
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition: StringRef.h:613
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
bool startswith(StringRef Prefix) const
Definition: StringRef.h:261
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
constexpr StringLiteral ObjC2IVarPrefix
Definition: Symbol.h:65
constexpr StringLiteral ObjC1ClassNamePrefix
Definition: Symbol.h:61
constexpr StringLiteral ObjC2ClassNamePrefix
Definition: Symbol.h:62
SimpleSymbol parseSymbol(StringRef SymName, const SymbolFlags Flags=SymbolFlags::None)
Determine SymbolKind from Flags and parsing Name.
Definition: Symbol.cpp:75
constexpr StringLiteral ObjC2MetaClassNamePrefix
Definition: Symbol.h:63
SymbolFlags
Symbol flags.
Definition: Symbol.h:24
@ WeakDefined
Weak defined symbol.
constexpr StringLiteral ObjC2EHTypePrefix
Definition: Symbol.h:64
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition: STLExtras.h:581
Lightweight struct for passing around symbol information.
Definition: Symbol.h:164