LLVM 18.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"
16#include "llvm/TextAPI/Target.h"
17
18namespace llvm {
19namespace MachO {
20
21// clang-format off
22
23/// Symbol flags.
24enum class SymbolFlags : uint8_t {
25 /// No flags
26 None = 0,
27
28 /// Thread-local value symbol
29 ThreadLocalValue = 1U << 0,
30
31 /// Weak defined symbol
32 WeakDefined = 1U << 1,
33
34 /// Weak referenced symbol
35 WeakReferenced = 1U << 2,
36
37 /// Undefined
38 Undefined = 1U << 3,
39
40 /// Rexported
41 Rexported = 1U << 4,
42
43 /// Data Segment
44 Data = 1U << 5,
45
46 /// Text Segment
47 Text = 1U << 6,
48
49 LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Text),
50};
51
52// clang-format on
53
54enum class SymbolKind : uint8_t {
59};
60
61constexpr StringLiteral ObjC1ClassNamePrefix = ".objc_class_name_";
62constexpr StringLiteral ObjC2ClassNamePrefix = "_OBJC_CLASS_$_";
63constexpr StringLiteral ObjC2MetaClassNamePrefix = "_OBJC_METACLASS_$_";
64constexpr StringLiteral ObjC2EHTypePrefix = "_OBJC_EHTYPE_$_";
65constexpr StringLiteral ObjC2IVarPrefix = "_OBJC_IVAR_$_";
66
68
69// Keep containers that hold Targets in sorted order and uniqued.
70template <typename C>
71typename C::iterator addEntry(C &Container, const Target &Targ) {
72 auto Iter =
73 lower_bound(Container, Targ, [](const Target &LHS, const Target &RHS) {
74 return LHS < RHS;
75 });
76 if ((Iter != std::end(Container)) && !(Targ < *Iter))
77 return Iter;
78
79 return Container.insert(Iter, Targ);
80}
81
82class Symbol {
83public:
84 Symbol(SymbolKind Kind, StringRef Name, TargetList Targets, SymbolFlags Flags)
85 : Name(Name), Targets(std::move(Targets)), Kind(Kind), Flags(Flags) {}
86
87 void addTarget(Target InputTarget) { addEntry(Targets, InputTarget); }
88 SymbolKind getKind() const { return Kind; }
89 StringRef getName() const { return Name; }
91 return mapToArchitectureSet(Targets);
92 }
93 SymbolFlags getFlags() const { return Flags; }
94
95 bool isWeakDefined() const {
97 }
98
99 bool isWeakReferenced() const {
101 }
102
103 bool isThreadLocalValue() const {
104 return (Flags & SymbolFlags::ThreadLocalValue) ==
106 }
107
108 bool isUndefined() const {
110 }
111
112 bool isReexported() const {
114 }
115
116 bool isData() const {
117 return (Flags & SymbolFlags::Data) == SymbolFlags::Data;
118 }
119
120 bool isText() const {
121 return (Flags & SymbolFlags::Text) == SymbolFlags::Text;
122 }
123
124 bool hasArchitecture(Architecture Arch) const {
125 return mapToArchitectureSet(Targets).contains(Arch);
126 }
127
128 bool hasTarget(const Target &Targ) const {
129 return llvm::is_contained(Targets, Targ);
130 }
131
134 const_target_range targets() const { return {Targets}; }
135
138 std::function<bool(const Target &)>>;
142
143#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
144 void dump(raw_ostream &OS) const;
145 void dump() const { dump(llvm::errs()); }
146#endif
147
148 bool operator==(const Symbol &O) const;
149
150 bool operator!=(const Symbol &O) const { return !(*this == O); }
151
152 bool operator<(const Symbol &O) const {
153 return std::tie(Kind, Name) < std::tie(O.Kind, O.Name);
154 }
155
156private:
157 StringRef Name;
158 TargetList Targets;
159 SymbolKind Kind;
160 SymbolFlags Flags;
161};
162
163} // end namespace MachO.
164} // end namespace llvm.
165
166#endif // LLVM_TEXTAPI_SYMBOL_H
raw_pwrite_stream & OS
Value * RHS
Value * LHS
bool contains(ArchitectureSet Archs) const
void dump() const
Definition: Symbol.h:145
bool isData() const
Definition: Symbol.h:116
void addTarget(Target InputTarget)
Definition: Symbol.h:87
SymbolFlags getFlags() const
Definition: Symbol.h:93
bool isWeakDefined() const
Definition: Symbol.h:95
bool hasArchitecture(Architecture Arch) const
Definition: Symbol.h:124
bool isUndefined() const
Definition: Symbol.h:108
TargetList::const_iterator const_target_iterator
Definition: Symbol.h:132
bool operator<(const Symbol &O) const
Definition: Symbol.h:152
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
SymbolKind getKind() const
Definition: Symbol.h:88
Symbol(SymbolKind Kind, StringRef Name, TargetList Targets, SymbolFlags Flags)
Definition: Symbol.h:84
bool operator!=(const Symbol &O) const
Definition: Symbol.h:150
ArchitectureSet getArchitectures() const
Definition: Symbol.h:90
StringRef getName() const
Definition: Symbol.h:89
bool hasTarget(const Target &Targ) const
Definition: Symbol.h:128
bool isText() const
Definition: Symbol.h:120
bool isWeakReferenced() const
Definition: Symbol.h:99
bool isReexported() const
Definition: Symbol.h:112
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:857
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Specialization of filter_iterator_base for forward iteration only.
Definition: STLExtras.h:507
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
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ LLVM_MARK_AS_BITMASK_ENUM
Definition: InterfaceFile.h:84
constexpr StringLiteral ObjC2IVarPrefix
Definition: Symbol.h:65
constexpr StringLiteral ObjC1ClassNamePrefix
Definition: Symbol.h:61
C::iterator addEntry(C &Container, StringRef InstallName)
constexpr StringLiteral ObjC2ClassNamePrefix
Definition: Symbol.h:62
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
Definition: Architecture.h:27
constexpr StringLiteral ObjC2MetaClassNamePrefix
Definition: Symbol.h:63
SymbolFlags
Symbol flags.
Definition: Symbol.h:24
@ ThreadLocalValue
Thread-local value symbol.
@ WeakReferenced
Weak referenced symbol.
@ WeakDefined
Weak defined symbol.
ArchitectureSet mapToArchitectureSet(ArrayRef< Target > Targets)
Definition: Target.cpp:75
constexpr StringLiteral ObjC2EHTypePrefix
Definition: Symbol.h:64
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:1946
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:1854
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1884
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858