LLVM 17.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
68class Symbol {
69public:
70 Symbol(SymbolKind Kind, StringRef Name, TargetList Targets, SymbolFlags Flags)
71 : Name(Name), Targets(std::move(Targets)), Kind(Kind), Flags(Flags) {}
72
73 void addTarget(Target target) { Targets.emplace_back(target); }
74 SymbolKind getKind() const { return Kind; }
75 StringRef getName() const { return Name; }
77 return mapToArchitectureSet(Targets);
78 }
79 SymbolFlags getFlags() const { return Flags; }
80
81 bool isWeakDefined() const {
83 }
84
85 bool isWeakReferenced() const {
87 }
88
89 bool isThreadLocalValue() const {
90 return (Flags & SymbolFlags::ThreadLocalValue) ==
92 }
93
94 bool isUndefined() const {
96 }
97
98 bool isReexported() const {
100 }
101
102 bool isData() const {
103 return (Flags & SymbolFlags::Data) == SymbolFlags::Data;
104 }
105
106 bool isText() const {
107 return (Flags & SymbolFlags::Text) == SymbolFlags::Text;
108 }
109
112 const_target_range targets() const { return {Targets}; }
113
116 std::function<bool(const Target &)>>;
120
121#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
122 void dump(raw_ostream &OS) const;
123 void dump() const { dump(llvm::errs()); }
124#endif
125
126 bool operator==(const Symbol &O) const;
127
128 bool operator!=(const Symbol &O) const { return !(*this == O); }
129
130 bool operator<(const Symbol &O) const {
131 return std::tie(Name, Kind, Targets, Flags) <
132 std::tie(O.Name, O.Kind, O.Targets, O.Flags);
133 }
134
135private:
136 StringRef Name;
137 TargetList Targets;
138 SymbolKind Kind;
139 SymbolFlags Flags;
140};
141
142} // end namespace MachO.
143} // end namespace llvm.
144
145#endif // LLVM_TEXTAPI_SYMBOL_H
raw_pwrite_stream & OS
@ Targets
Definition: TextStubV5.cpp:90
@ Flags
Definition: TextStubV5.cpp:93
void dump() const
Definition: Symbol.h:123
bool isData() const
Definition: Symbol.h:102
SymbolFlags getFlags() const
Definition: Symbol.h:79
bool isWeakDefined() const
Definition: Symbol.h:81
bool isUndefined() const
Definition: Symbol.h:94
TargetList::const_iterator const_target_iterator
Definition: Symbol.h:110
bool operator<(const Symbol &O) const
Definition: Symbol.h:130
const_target_range targets() const
Definition: Symbol.h:112
bool operator==(const Symbol &O) const
Definition: Symbol.cpp:57
bool isThreadLocalValue() const
Definition: Symbol.h:89
SymbolKind getKind() const
Definition: Symbol.h:74
Symbol(SymbolKind Kind, StringRef Name, TargetList Targets, SymbolFlags Flags)
Definition: Symbol.h:70
bool operator!=(const Symbol &O) const
Definition: Symbol.h:128
void addTarget(Target target)
Definition: Symbol.h:73
ArchitectureSet getArchitectures() const
Definition: Symbol.h:76
StringRef getName() const
Definition: Symbol.h:75
bool isText() const
Definition: Symbol.h:106
bool isWeakReferenced() const
Definition: Symbol.h:85
bool isReexported() const
Definition: Symbol.h:98
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:941
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:840
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:589
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
@ LLVM_MARK_AS_BITMASK_ENUM
Definition: InterfaceFile.h:74
constexpr StringLiteral ObjC2IVarPrefix
Definition: Symbol.h:65
constexpr StringLiteral ObjC1ClassNamePrefix
Definition: Symbol.h:61
constexpr StringLiteral ObjC2ClassNamePrefix
Definition: Symbol.h:62
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:68
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.
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:1946
Definition: BitVector.h:858