1 //===- Symbol.cpp ---------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // Implements the Symbol.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/TextAPI/Symbol.h"
19 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
20 LLVM_DUMP_METHOD
void Symbol::dump(raw_ostream
&OS
) const {
25 Result
+= "(weak-def) ";
26 if (isWeakReferenced())
27 Result
+= "(weak-ref) ";
28 if (isThreadLocalValue())
31 case EncodeKind::GlobalSymbol
:
34 case EncodeKind::ObjectiveCClass
:
35 Result
+= "(ObjC Class) " + Name
.str();
37 case EncodeKind::ObjectiveCClassEHType
:
38 Result
+= "(ObjC Class EH) " + Name
.str();
40 case EncodeKind::ObjectiveCInstanceVariable
:
41 Result
+= "(ObjC IVar) " + Name
.str();
48 Symbol::const_filtered_target_range
49 Symbol::targets(ArchitectureSet Architectures
) const {
50 std::function
<bool(const Target
&)> FN
=
51 [Architectures
](const Target
&Target
) {
52 return Architectures
.has(Target
.Arch
);
54 return make_filter_range(Targets
, FN
);
57 bool 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
) {
62 Flag
&= ~SymbolFlags::Data
;
64 Flag
&= ~SymbolFlags::Text
;
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
);
75 SimpleSymbol
parseSymbol(StringRef SymName
) {
76 if (SymName
.starts_with(ObjC1ClassNamePrefix
))
77 return {SymName
.drop_front(ObjC1ClassNamePrefix
.size()),
78 EncodeKind::ObjectiveCClass
, ObjCIFSymbolKind::Class
};
79 if (SymName
.starts_with(ObjC2ClassNamePrefix
))
80 return {SymName
.drop_front(ObjC2ClassNamePrefix
.size()),
81 EncodeKind::ObjectiveCClass
, ObjCIFSymbolKind::Class
};
82 if (SymName
.starts_with(ObjC2MetaClassNamePrefix
))
83 return {SymName
.drop_front(ObjC2MetaClassNamePrefix
.size()),
84 EncodeKind::ObjectiveCClass
, ObjCIFSymbolKind::MetaClass
};
85 if (SymName
.starts_with(ObjC2EHTypePrefix
))
86 return {SymName
.drop_front(ObjC2EHTypePrefix
.size()),
87 EncodeKind::ObjectiveCClassEHType
, ObjCIFSymbolKind::EHType
};
88 if (SymName
.starts_with(ObjC2IVarPrefix
))
89 return {SymName
.drop_front(ObjC2IVarPrefix
.size()),
90 EncodeKind::ObjectiveCInstanceVariable
, ObjCIFSymbolKind::None
};
91 return {SymName
, EncodeKind::GlobalSymbol
, ObjCIFSymbolKind::None
};
94 } // end namespace MachO.
95 } // end namespace llvm.