1 //===- llvm/TextAPI/Symbol.h - TAPI Symbol ----------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_TEXTAPI_MACHO_SYMBOL_H
10 #define LLVM_TEXTAPI_MACHO_SYMBOL_H
12 #include "llvm/ADT/BitmaskEnum.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/Error.h"
15 #include "llvm/Support/raw_ostream.h"
16 #include "llvm/TextAPI/MachO/ArchitectureSet.h"
17 #include "llvm/TextAPI/MachO/Target.h"
25 enum class SymbolFlags
: uint8_t {
29 /// Thread-local value symbol
30 ThreadLocalValue
= 1U << 0,
32 /// Weak defined symbol
33 WeakDefined
= 1U << 1,
35 /// Weak referenced symbol
36 WeakReferenced
= 1U << 2,
41 LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Undefined
),
46 enum class SymbolKind
: uint8_t {
49 ObjectiveCClassEHType
,
50 ObjectiveCInstanceVariable
,
53 using TargetList
= SmallVector
<Target
, 20>;
56 Symbol(SymbolKind Kind
, StringRef Name
, TargetList Targets
, SymbolFlags Flags
)
57 : Name(Name
), Targets(std::move(Targets
)), Kind(Kind
), Flags(Flags
) {}
59 void addTarget(Target target
) { Targets
.emplace_back(target
); }
60 SymbolKind
getKind() const { return Kind
; }
61 StringRef
getName() const { return Name
; }
62 ArchitectureSet
getArchitectures() const {
63 return mapToArchitectureSet(Targets
);
65 SymbolFlags
getFlags() const { return Flags
; }
67 bool isWeakDefined() const {
68 return (Flags
& SymbolFlags::WeakDefined
) == SymbolFlags::WeakDefined
;
71 bool isWeakReferenced() const {
72 return (Flags
& SymbolFlags::WeakReferenced
) == SymbolFlags::WeakReferenced
;
75 bool isThreadLocalValue() const {
76 return (Flags
& SymbolFlags::ThreadLocalValue
) ==
77 SymbolFlags::ThreadLocalValue
;
80 bool isUndefined() const {
81 return (Flags
& SymbolFlags::Undefined
) == SymbolFlags::Undefined
;
84 using const_target_iterator
= TargetList::const_iterator
;
85 using const_target_range
= llvm::iterator_range
<const_target_iterator
>;
86 const_target_range
targets() const { return {Targets
}; }
88 using const_filtered_target_iterator
=
89 llvm::filter_iterator
<const_target_iterator
,
90 std::function
<bool(const Target
&)>>;
91 using const_filtered_target_range
=
92 llvm::iterator_range
<const_filtered_target_iterator
>;
93 const_filtered_target_range
targets(ArchitectureSet architectures
) const;
95 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
96 void dump(raw_ostream
&OS
) const;
97 void dump() const { dump(llvm::errs()); }
107 } // end namespace MachO.
108 } // end namespace llvm.
110 #endif // LLVM_TEXTAPI_MACHO_SYMBOL_H