LLVM  16.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 
12 #include "llvm/ADT/BitmaskEnum.h"
13 #include "llvm/ADT/StringRef.h"
16 #include "llvm/TextAPI/Target.h"
17 
18 namespace llvm {
19 namespace MachO {
20 
21 // clang-format off
22 
23 /// Symbol flags.
24 enum 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  LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Rexported),
44 };
45 
46 // clang-format on
47 
48 enum class SymbolKind : uint8_t {
53 };
54 
55 constexpr StringLiteral ObjC1ClassNamePrefix = ".objc_class_name_";
56 constexpr StringLiteral ObjC2ClassNamePrefix = "_OBJC_CLASS_$_";
57 constexpr StringLiteral ObjC2MetaClassNamePrefix = "_OBJC_METACLASS_$_";
58 constexpr StringLiteral ObjC2EHTypePrefix = "_OBJC_EHTYPE_$_";
59 constexpr StringLiteral ObjC2IVarPrefix = "_OBJC_IVAR_$_";
60 
62 class Symbol {
63 public:
64  Symbol(SymbolKind Kind, StringRef Name, TargetList Targets, SymbolFlags Flags)
65  : Name(Name), Targets(std::move(Targets)), Kind(Kind), Flags(Flags) {}
66 
67  void addTarget(Target target) { Targets.emplace_back(target); }
68  SymbolKind getKind() const { return Kind; }
69  StringRef getName() const { return Name; }
71  return mapToArchitectureSet(Targets);
72  }
73  SymbolFlags getFlags() const { return Flags; }
74 
75  bool isWeakDefined() const {
77  }
78 
79  bool isWeakReferenced() const {
81  }
82 
83  bool isThreadLocalValue() const {
84  return (Flags & SymbolFlags::ThreadLocalValue) ==
86  }
87 
88  bool isUndefined() const {
90  }
91 
92  bool isReexported() const {
94  }
95 
98  const_target_range targets() const { return {Targets}; }
99 
102  std::function<bool(const Target &)>>;
106 
107 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
108  void dump(raw_ostream &OS) const;
109  void dump() const { dump(llvm::errs()); }
110 #endif
111 
112  bool operator==(const Symbol &O) const {
113  return std::tie(Name, Kind, Targets, Flags) ==
114  std::tie(O.Name, O.Kind, O.Targets, O.Flags);
115  }
116 
117  bool operator!=(const Symbol &O) const { return !(*this == O); }
118 
119  bool operator<(const Symbol &O) const {
120  return std::tie(Name, Kind, Targets, Flags) <
121  std::tie(O.Name, O.Kind, O.Targets, O.Flags);
122  }
123 
124 private:
125  StringRef Name;
126  TargetList Targets;
127  SymbolKind Kind;
128  SymbolFlags Flags;
129 };
130 
131 } // end namespace MachO.
132 } // end namespace llvm.
133 
134 #endif // LLVM_TEXTAPI_SYMBOL_H
llvm::MachO::ObjC2EHTypePrefix
constexpr StringLiteral ObjC2EHTypePrefix
Definition: Symbol.h:58
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::MachO::SymbolFlags::WeakReferenced
@ WeakReferenced
Weak referenced symbol.
llvm::MachO::mapToArchitectureSet
ArchitectureSet mapToArchitectureSet(ArrayRef< Target > Targets)
Definition: Target.cpp:65
StringRef.h
llvm::SmallVector< Target, 5 >
llvm::MachO::Target
Definition: Target.h:26
llvm::MachO::Symbol::getFlags
SymbolFlags getFlags() const
Definition: Symbol.h:73
llvm::MachO::Symbol::isWeakDefined
bool isWeakDefined() const
Definition: Symbol.h:75
llvm::MachO::SymbolKind
SymbolKind
Definition: Symbol.h:48
llvm::filter_iterator_impl
Specialization of filter_iterator_base for forward iteration only.
Definition: STLExtras.h:560
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:891
llvm::MachO::SymbolFlags
SymbolFlags
Symbol flags.
Definition: Symbol.h:24
Target.h
llvm::MachO::Symbol::operator!=
bool operator!=(const Symbol &O) const
Definition: Symbol.h:117
llvm::StringLiteral
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:845
llvm::MachO::Symbol::Symbol
Symbol(SymbolKind Kind, StringRef Name, TargetList Targets, SymbolFlags Flags)
Definition: Symbol.h:64
llvm::MachO::ObjC2ClassNamePrefix
constexpr StringLiteral ObjC2ClassNamePrefix
Definition: Symbol.h:56
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:96
llvm::MachO::ArchitectureSet
Definition: ArchitectureSet.h:29
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:264
llvm::MachO::SymbolKind::ObjectiveCInstanceVariable
@ ObjectiveCInstanceVariable
llvm::MachO::Symbol::isWeakReferenced
bool isWeakReferenced() const
Definition: Symbol.h:79
llvm::MachO::ObjC2MetaClassNamePrefix
constexpr StringLiteral ObjC2MetaClassNamePrefix
Definition: Symbol.h:57
llvm::MachO::SymbolFlags::Rexported
@ Rexported
Rexported.
llvm::SmallVectorImpl< Target >::const_iterator
typename SuperClass::const_iterator const_iterator
Definition: SmallVector.h:582
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:1836
llvm::MachO::ObjC1ClassNamePrefix
constexpr StringLiteral ObjC1ClassNamePrefix
Definition: Symbol.h:55
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::MachO::Symbol::isReexported
bool isReexported() const
Definition: Symbol.h:92
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:50
BitmaskEnum.h
llvm::MachO::Symbol
Definition: Symbol.h:62
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:102
llvm::MachO::Symbol::addTarget
void addTarget(Target target)
Definition: Symbol.h:67
std
Definition: BitVector.h:851
llvm::MachO::Symbol::operator==
bool operator==(const Symbol &O) const
Definition: Symbol.h:112
llvm::MachO::ObjC2IVarPrefix
constexpr StringLiteral ObjC2IVarPrefix
Definition: Symbol.h:59
llvm::MachO::Symbol::getKind
SymbolKind getKind() const
Definition: Symbol.h:68
llvm::MachO::Symbol::targets
const_target_range targets() const
Definition: Symbol.h:98
llvm::MachO::Symbol::operator<
bool operator<(const Symbol &O) const
Definition: Symbol.h:119
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:69
llvm::MachO::SymbolKind::ObjectiveCClassEHType
@ ObjectiveCClassEHType
llvm::MachO::Symbol::isThreadLocalValue
bool isThreadLocalValue() const
Definition: Symbol.h:83
llvm::MachO::SymbolFlags::None
@ None
No flags.
raw_ostream.h
llvm::MachO::Symbol::getArchitectures
ArchitectureSet getArchitectures() const
Definition: Symbol.h:70
llvm::MachO::Symbol::isUndefined
bool isUndefined() const
Definition: Symbol.h:88
llvm::MachO::Symbol::dump
void dump() const
Definition: Symbol.h:109
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:941