blob: 3c7ff5e0f4ea3c8cc1d38fc20382e8617bd56235 [file] [log] [blame]
Andrew Walbran3d2c1972020-04-07 12:24:26 +01001//===- 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"
15#include "llvm/Support/raw_ostream.h"
16#include "llvm/TextAPI/MachO/ArchitectureSet.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 LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Undefined),
41};
42
43// clang-format on
44
45enum class SymbolKind : uint8_t {
46 GlobalSymbol,
47 ObjectiveCClass,
48 ObjectiveCClassEHType,
49 ObjectiveCInstanceVariable,
50};
51
52class Symbol {
53public:
54 constexpr Symbol(SymbolKind Kind, StringRef Name,
55 ArchitectureSet Architectures, SymbolFlags Flags)
56 : Name(Name), Architectures(Architectures), Kind(Kind), Flags(Flags) {}
57
58 SymbolKind getKind() const { return Kind; }
59 StringRef getName() const { return Name; }
60 ArchitectureSet getArchitectures() const { return Architectures; }
61 void addArchitectures(ArchitectureSet Archs) { Architectures |= Archs; }
62 SymbolFlags getFlags() const { return Flags; }
63
64 bool isWeakDefined() const {
65 return (Flags & SymbolFlags::WeakDefined) == SymbolFlags::WeakDefined;
66 }
67
68 bool isWeakReferenced() const {
69 return (Flags & SymbolFlags::WeakReferenced) == SymbolFlags::WeakReferenced;
70 }
71
72 bool isThreadLocalValue() const {
73 return (Flags & SymbolFlags::ThreadLocalValue) ==
74 SymbolFlags::ThreadLocalValue;
75 }
76
77 bool isUndefined() const {
78 return (Flags & SymbolFlags::Undefined) == SymbolFlags::Undefined;
79 }
80
81#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
82 void dump(raw_ostream &OS) const;
83 void dump() const { dump(llvm::errs()); }
84#endif
85
86private:
87 StringRef Name;
88 ArchitectureSet Architectures;
89 SymbolKind Kind;
90 SymbolFlags Flags;
91};
92
93} // end namespace MachO.
94} // end namespace llvm.
95
96#endif // LLVM_TEXTAPI_MACHO_SYMBOL_H