LLVM  14.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_MACHO_SYMBOL_H
10 #define LLVM_TEXTAPI_MACHO_SYMBOL_H
11 
12 #include "llvm/ADT/BitmaskEnum.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/Error.h"
17 #include "llvm/TextAPI/Target.h"
18 
19 namespace llvm {
20 namespace MachO {
21 
22 // clang-format off
23 
24 /// Symbol flags.
25 enum 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  LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Rexported),
45 };
46 
47 // clang-format on
48 
49 enum class SymbolKind : uint8_t {
54 };
55 
56 constexpr StringLiteral ObjC1ClassNamePrefix = ".objc_class_name_";
57 constexpr StringLiteral ObjC2ClassNamePrefix = "_OBJC_CLASS_$_";
58 constexpr StringLiteral ObjC2MetaClassNamePrefix = "_OBJC_METACLASS_$_";
59 constexpr StringLiteral ObjC2EHTypePrefix = "_OBJC_EHTYPE_$_";
60 constexpr StringLiteral ObjC2IVarPrefix = "_OBJC_IVAR_$_";
61 
63 class Symbol {
64 public:
65  Symbol(SymbolKind Kind, StringRef Name, TargetList Targets, SymbolFlags Flags)
66  : Name(Name), Targets(std::move(Targets)), Kind(Kind), Flags(Flags) {}
67 
68  void addTarget(Target target) { Targets.emplace_back(target); }
69  SymbolKind getKind() const { return Kind; }
70  StringRef getName() const { return Name; }
72  return mapToArchitectureSet(Targets);
73  }
74  SymbolFlags getFlags() const { return Flags; }
75 
76  bool isWeakDefined() const {
78  }
79 
80  bool isWeakReferenced() const {
82  }
83 
84  bool isThreadLocalValue() const {
85  return (Flags & SymbolFlags::ThreadLocalValue) ==
87  }
88 
89  bool isUndefined() const {
91  }
92 
93  bool isReexported() const {
95  }
96 
99  const_target_range targets() const { return {Targets}; }
100 
103  std::function<bool(const Target &)>>;
107 
108 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
109  void dump(raw_ostream &OS) const;
110  void dump() const { dump(llvm::errs()); }
111 #endif
112 
113  bool operator==(const Symbol &O) const {
114  return std::tie(Name, Kind, Targets, Flags) ==
115  std::tie(O.Name, O.Kind, O.Targets, O.Flags);
116  }
117 
118  bool operator!=(const Symbol &O) const { return !(*this == O); }
119 
120  bool operator<(const Symbol &O) const {
121  return std::tie(Name, Kind, Targets, Flags) <
122  std::tie(O.Name, O.Kind, O.Targets, O.Flags);
123  }
124 
125 private:
126  StringRef Name;
127  TargetList Targets;
128  SymbolKind Kind;
129  SymbolFlags Flags;
130 };
131 
132 } // end namespace MachO.
133 } // end namespace llvm.
134 
135 #endif // LLVM_TEXTAPI_MACHO_SYMBOL_H
llvm::MachO::ObjC2EHTypePrefix
constexpr StringLiteral ObjC2EHTypePrefix
Definition: Symbol.h:59
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MachO::SymbolFlags::WeakReferenced
@ WeakReferenced
Weak referenced symbol.
llvm::MachO::mapToArchitectureSet
ArchitectureSet mapToArchitectureSet(ArrayRef< Target > Targets)
Definition: Target.cpp:68
StringRef.h
llvm::SmallVector< Target, 5 >
llvm::MachO::Target
Definition: Target.h:24
llvm::MachO::Symbol::getFlags
SymbolFlags getFlags() const
Definition: Symbol.h:74
Error.h
llvm::MachO::Symbol::isWeakDefined
bool isWeakDefined() const
Definition: Symbol.h:76
llvm::MachO::SymbolKind
SymbolKind
Definition: Symbol.h:49
llvm::filter_iterator_impl
Specialization of filter_iterator_base for forward iteration only.
Definition: STLExtras.h:412
llvm::MachO::SymbolFlags::WeakDefined
@ WeakDefined
Weak defined symbol.
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
llvm::MachO::SymbolFlags
SymbolFlags
Symbol flags.
Definition: Symbol.h:25
Target.h
llvm::MachO::Symbol::operator!=
bool operator!=(const Symbol &O) const
Definition: Symbol.h:118
llvm::StringLiteral
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:891
llvm::MachO::Symbol::Symbol
Symbol(SymbolKind Kind, StringRef Name, TargetList Targets, SymbolFlags Flags)
Definition: Symbol.h:65
llvm::MachO::ObjC2ClassNamePrefix
constexpr StringLiteral ObjC2ClassNamePrefix
Definition: Symbol.h:57
llvm::MachO::SymbolFlags::Undefined
@ Undefined
Undefined.
llvm::MachO::SymbolKind::GlobalSymbol
@ GlobalSymbol
llvm::MachO::SymbolKind::ObjectiveCClass
@ ObjectiveCClass
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MachO::SymbolFlags::ThreadLocalValue
@ ThreadLocalValue
Thread-local value symbol.
llvm::MachO::Symbol::const_target_iterator
TargetList::const_iterator const_target_iterator
Definition: Symbol.h:97
llvm::MachO::ArchitectureSet
Definition: ArchitectureSet.h:29
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:179
llvm::MachO::SymbolKind::ObjectiveCInstanceVariable
@ ObjectiveCInstanceVariable
llvm::MachO::Symbol::isWeakReferenced
bool isWeakReferenced() const
Definition: Symbol.h:80
llvm::MachO::ObjC2MetaClassNamePrefix
constexpr StringLiteral ObjC2MetaClassNamePrefix
Definition: Symbol.h:58
llvm::MachO::SymbolFlags::Rexported
@ Rexported
Rexported.
llvm::SmallVectorImpl< Target >::const_iterator
typename SuperClass::const_iterator const_iterator
Definition: SmallVector.h:563
llvm::move
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:1605
llvm::MachO::ObjC1ClassNamePrefix
constexpr StringLiteral ObjC1ClassNamePrefix
Definition: Symbol.h:56
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::MachO::Symbol::isReexported
bool isReexported() const
Definition: Symbol.h:93
llvm::MachO::SymbolFlags::LLVM_MARK_AS_BITMASK_ENUM
@ LLVM_MARK_AS_BITMASK_ENUM
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
BitmaskEnum.h
llvm::MachO::Symbol
Definition: Symbol.h:63
llvm::MachO::Symbol::const_filtered_target_iterator
llvm::filter_iterator< const_target_iterator, std::function< bool(const Target &)> > const_filtered_target_iterator
Definition: Symbol.h:103
llvm::MachO::Symbol::addTarget
void addTarget(Target target)
Definition: Symbol.h:68
std
Definition: BitVector.h:838
llvm::MachO::Symbol::operator==
bool operator==(const Symbol &O) const
Definition: Symbol.h:113
llvm::MachO::ObjC2IVarPrefix
constexpr StringLiteral ObjC2IVarPrefix
Definition: Symbol.h:60
llvm::MachO::Symbol::getKind
SymbolKind getKind() const
Definition: Symbol.h:69
llvm::MachO::Symbol::targets
const_target_range targets() const
Definition: Symbol.h:99
llvm::MachO::Symbol::operator<
bool operator<(const Symbol &O) const
Definition: Symbol.h:120
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
ArchitectureSet.h
llvm::MachO::Symbol::getName
StringRef getName() const
Definition: Symbol.h:70
llvm::MachO::SymbolKind::ObjectiveCClassEHType
@ ObjectiveCClassEHType
llvm::MachO::Symbol::isThreadLocalValue
bool isThreadLocalValue() const
Definition: Symbol.h:84
llvm::MachO::SymbolFlags::None
@ None
No flags.
raw_ostream.h
llvm::MachO::Symbol::getArchitectures
ArchitectureSet getArchitectures() const
Definition: Symbol.h:71
llvm::MachO::Symbol::isUndefined
bool isUndefined() const
Definition: Symbol.h:89
llvm::MachO::Symbol::dump
void dump() const
Definition: Symbol.h:110
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:908