LLVM 22.0.0git
Symbol.h
Go to the documentation of this file.
1//===- llvm/TextAPI/Symbol.h - TAPI Symbol ----------------------*- 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#ifndef LLVM_TEXTAPI_SYMBOL_H
10#define LLVM_TEXTAPI_SYMBOL_H
11
13#include "llvm/ADT/StringRef.h"
17#include "llvm/TextAPI/Target.h"
18
19namespace llvm {
20namespace MachO {
21
22// clang-format off
23
24/// Symbol flags.
25enum class SymbolFlags : uint8_t {
26 /// No flags
27 None = 0,
28
29 /// Thread-local value symbol
30 ThreadLocalValue = 1U << 0,
31
32 /// Weak defined symbol
33 WeakDefined = 1U << 1,
34
35 /// Weak referenced symbol
36 WeakReferenced = 1U << 2,
37
38 /// Undefined
39 Undefined = 1U << 3,
40
41 /// Rexported
42 Rexported = 1U << 4,
43
44 /// Data Segment
45 Data = 1U << 5,
46
47 /// Text Segment
48 Text = 1U << 6,
49
50 LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Text),
51};
52
53// clang-format on
54
55/// Mapping of entry types in TextStubs.
56enum class EncodeKind : uint8_t {
61};
62
63constexpr StringLiteral ObjC1ClassNamePrefix = ".objc_class_name_";
64constexpr StringLiteral ObjC2ClassNamePrefix = "_OBJC_CLASS_$_";
65constexpr StringLiteral ObjC2MetaClassNamePrefix = "_OBJC_METACLASS_$_";
66constexpr StringLiteral ObjC2EHTypePrefix = "_OBJC_EHTYPE_$_";
67constexpr StringLiteral ObjC2IVarPrefix = "_OBJC_IVAR_$_";
68
69/// ObjC Interface symbol mappings.
71 None = 0,
72 /// Is OBJC_CLASS* symbol.
73 Class = 1U << 0,
74 /// Is OBJC_METACLASS* symbol.
75 MetaClass = 1U << 1,
76 /// Is OBJC_EHTYPE* symbol.
77 EHType = 1U << 2,
78
79 LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/EHType),
80};
81
83
84// Keep containers that hold Targets in sorted order and uniqued.
85template <typename C>
86typename C::iterator addEntry(C &Container, const Target &Targ) {
87 auto Iter =
88 lower_bound(Container, Targ, [](const Target &LHS, const Target &RHS) {
89 return LHS < RHS;
90 });
91 if ((Iter != std::end(Container)) && !(Targ < *Iter))
92 return Iter;
93
94 return Container.insert(Iter, Targ);
95}
96
97class Symbol {
98public:
99 Symbol(EncodeKind Kind, StringRef Name, TargetList Targets, SymbolFlags Flags)
100 : Name(Name), Targets(std::move(Targets)), Kind(Kind), Flags(Flags) {}
101
102 void addTarget(Target InputTarget) { addEntry(Targets, InputTarget); }
103 EncodeKind getKind() const { return Kind; }
104 StringRef getName() const { return Name; }
106 return mapToArchitectureSet(Targets);
107 }
108 SymbolFlags getFlags() const { return Flags; }
109
110 bool isWeakDefined() const {
112 }
113
114 bool isWeakReferenced() const {
116 }
117
118 bool isThreadLocalValue() const {
119 return (Flags & SymbolFlags::ThreadLocalValue) ==
121 }
122
123 bool isUndefined() const {
125 }
126
127 bool isReexported() const {
129 }
130
131 bool isData() const {
132 return (Flags & SymbolFlags::Data) == SymbolFlags::Data;
133 }
134
135 bool isText() const {
136 return (Flags & SymbolFlags::Text) == SymbolFlags::Text;
137 }
138
139 bool hasArchitecture(Architecture Arch) const {
140 return mapToArchitectureSet(Targets).contains(Arch);
141 }
142
143 bool hasTarget(const Target &Targ) const {
144 return llvm::is_contained(Targets, Targ);
145 }
146
149 const_target_range targets() const { return {Targets}; }
150
153 std::function<bool(const Target &)>>;
157 targets(ArchitectureSet architectures) const;
158
159#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
160 void dump(raw_ostream &OS) const;
161 void dump() const { dump(llvm::errs()); }
162#endif
163
164 LLVM_ABI bool operator==(const Symbol &O) const;
165
166 bool operator!=(const Symbol &O) const { return !(*this == O); }
167
168 bool operator<(const Symbol &O) const {
169 return std::tie(Kind, Name) < std::tie(O.Kind, O.Name);
170 }
171
172private:
173 StringRef Name;
174 TargetList Targets;
175 EncodeKind Kind;
176 SymbolFlags Flags;
177};
178
179/// Lightweight struct for passing around symbol information.
184
185 bool operator<(const SimpleSymbol &O) const {
186 return std::tie(Name, Kind, ObjCInterfaceType) <
187 std::tie(O.Name, O.Kind, O.ObjCInterfaceType);
188 }
189};
190
191/// Get symbol classification by parsing the name of a symbol.
192///
193/// \param SymName The name of symbol.
194LLVM_ABI SimpleSymbol parseSymbol(StringRef SymName);
195
196} // end namespace MachO.
197} // end namespace llvm.
198
199#endif // LLVM_TEXTAPI_SYMBOL_H
#define LLVM_ABI
Definition: Compiler.h:213
raw_pwrite_stream & OS
Value * RHS
Value * LHS
bool contains(ArchitectureSet Archs) const
void dump() const
Definition: Symbol.h:161
bool isData() const
Definition: Symbol.h:131
void addTarget(Target InputTarget)
Definition: Symbol.h:102
SymbolFlags getFlags() const
Definition: Symbol.h:108
bool isWeakDefined() const
Definition: Symbol.h:110
bool hasArchitecture(Architecture Arch) const
Definition: Symbol.h:139
bool isUndefined() const
Definition: Symbol.h:123
TargetList::const_iterator const_target_iterator
Definition: Symbol.h:147
bool operator<(const Symbol &O) const
Definition: Symbol.h:168
const_target_range targets() const
Definition: Symbol.h:149
bool isThreadLocalValue() const
Definition: Symbol.h:118
bool operator!=(const Symbol &O) const
Definition: Symbol.h:166
ArchitectureSet getArchitectures() const
Definition: Symbol.h:105
Symbol(EncodeKind Kind, StringRef Name, TargetList Targets, SymbolFlags Flags)
Definition: Symbol.h:99
StringRef getName() const
Definition: Symbol.h:104
bool hasTarget(const Target &Targ) const
Definition: Symbol.h:143
bool isText() const
Definition: Symbol.h:135
EncodeKind getKind() const
Definition: Symbol.h:103
bool isWeakReferenced() const
Definition: Symbol.h:114
bool isReexported() const
Definition: Symbol.h:127
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:862
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Specialization of filter_iterator_base for forward iteration only.
Definition: STLExtras.h:506
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:53
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ LLVM_MARK_AS_BITMASK_ENUM
Definition: FileTypes.h:45
constexpr StringLiteral ObjC2IVarPrefix
Definition: Symbol.h:67
constexpr StringLiteral ObjC1ClassNamePrefix
Definition: Symbol.h:63
C::iterator addEntry(C &Container, StringRef InstallName)
constexpr StringLiteral ObjC2ClassNamePrefix
Definition: Symbol.h:64
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
Definition: Architecture.h:28
ObjCIFSymbolKind
ObjC Interface symbol mappings.
Definition: Symbol.h:70
@ EHType
Is OBJC_EHTYPE* symbol.
@ Class
Is OBJC_CLASS* symbol.
@ MetaClass
Is OBJC_METACLASS* symbol.
EncodeKind
Mapping of entry types in TextStubs.
Definition: Symbol.h:56
LLVM_ABI SimpleSymbol parseSymbol(StringRef SymName)
Get symbol classification by parsing the name of a symbol.
Definition: Symbol.cpp:75
constexpr StringLiteral ObjC2MetaClassNamePrefix
Definition: Symbol.h:65
SymbolFlags
Symbol flags.
Definition: Symbol.h:25
@ ThreadLocalValue
Thread-local value symbol.
@ WeakReferenced
Weak referenced symbol.
@ WeakDefined
Weak defined symbol.
LLVM_ABI ArchitectureSet mapToArchitectureSet(ArrayRef< Target > Targets)
Definition: Target.cpp:69
constexpr StringLiteral ObjC2EHTypePrefix
Definition: Symbol.h:66
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:2013
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1886
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1916
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
Lightweight struct for passing around symbol information.
Definition: Symbol.h:180
bool operator<(const SimpleSymbol &O) const
Definition: Symbol.h:185
ObjCIFSymbolKind ObjCInterfaceType
Definition: Symbol.h:183