File indexing completed on 2026-05-10 08:44:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_TEXTAPI_ARCHITECTURESET_H
0014 #define LLVM_TEXTAPI_ARCHITECTURESET_H
0015
0016 #include "llvm/TextAPI/Architecture.h"
0017 #include <cstddef>
0018 #include <iterator>
0019 #include <limits>
0020 #include <string>
0021 #include <tuple>
0022 #include <vector>
0023
0024 namespace llvm {
0025 class raw_ostream;
0026
0027 namespace MachO {
0028
0029 class ArchitectureSet {
0030 private:
0031 using ArchSetType = uint32_t;
0032
0033 const static ArchSetType EndIndexVal =
0034 std::numeric_limits<ArchSetType>::max();
0035 ArchSetType ArchSet{0};
0036
0037 public:
0038 constexpr ArchitectureSet() = default;
0039 constexpr ArchitectureSet(ArchSetType Raw) : ArchSet(Raw) {}
0040 ArchitectureSet(Architecture Arch) : ArchitectureSet() { set(Arch); }
0041 ArchitectureSet(const std::vector<Architecture> &Archs);
0042
0043 static ArchitectureSet All() { return ArchitectureSet(EndIndexVal); }
0044
0045 void set(Architecture Arch) {
0046 if (Arch == AK_unknown)
0047 return;
0048 ArchSet |= 1U << static_cast<int>(Arch);
0049 }
0050
0051 ArchitectureSet clear(Architecture Arch) {
0052 ArchSet &= ~(1U << static_cast<int>(Arch));
0053 return ArchSet;
0054 }
0055
0056 bool has(Architecture Arch) const {
0057 return ArchSet & (1U << static_cast<int>(Arch));
0058 }
0059
0060 bool contains(ArchitectureSet Archs) const {
0061 return (ArchSet & Archs.ArchSet) == Archs.ArchSet;
0062 }
0063
0064 size_t count() const;
0065
0066 bool empty() const { return ArchSet == 0; }
0067
0068 ArchSetType rawValue() const { return ArchSet; }
0069
0070 bool hasX86() const {
0071 return has(AK_i386) || has(AK_x86_64) || has(AK_x86_64h);
0072 }
0073
0074 template <typename Ty> class arch_iterator {
0075 public:
0076 using iterator_category = std::forward_iterator_tag;
0077 using value_type = Architecture;
0078 using difference_type = std::size_t;
0079 using pointer = value_type *;
0080 using reference = value_type &;
0081
0082 private:
0083 ArchSetType Index;
0084 Ty *ArchSet;
0085
0086 void findNextSetBit() {
0087 if (Index == EndIndexVal)
0088 return;
0089 while (++Index < sizeof(Ty) * 8) {
0090 if (*ArchSet & (1UL << Index))
0091 return;
0092 }
0093
0094 Index = EndIndexVal;
0095 }
0096
0097 public:
0098 arch_iterator(Ty *ArchSet, ArchSetType Index = 0)
0099 : Index(Index), ArchSet(ArchSet) {
0100 if (Index != EndIndexVal && !(*ArchSet & (1UL << Index)))
0101 findNextSetBit();
0102 }
0103
0104 Architecture operator*() const { return static_cast<Architecture>(Index); }
0105
0106 arch_iterator &operator++() {
0107 findNextSetBit();
0108 return *this;
0109 }
0110
0111 arch_iterator operator++(int) {
0112 auto tmp = *this;
0113 findNextSetBit();
0114 return tmp;
0115 }
0116
0117 bool operator==(const arch_iterator &o) const {
0118 return std::tie(Index, ArchSet) == std::tie(o.Index, o.ArchSet);
0119 }
0120
0121 bool operator!=(const arch_iterator &o) const { return !(*this == o); }
0122 };
0123
0124 ArchitectureSet operator&(const ArchitectureSet &o) {
0125 return {ArchSet & o.ArchSet};
0126 }
0127
0128 ArchitectureSet operator|(const ArchitectureSet &o) {
0129 return {ArchSet | o.ArchSet};
0130 }
0131
0132 ArchitectureSet &operator|=(const ArchitectureSet &o) {
0133 ArchSet |= o.ArchSet;
0134 return *this;
0135 }
0136
0137 ArchitectureSet &operator|=(const Architecture &Arch) {
0138 set(Arch);
0139 return *this;
0140 }
0141
0142 bool operator==(const ArchitectureSet &o) const {
0143 return ArchSet == o.ArchSet;
0144 }
0145
0146 bool operator!=(const ArchitectureSet &o) const {
0147 return ArchSet != o.ArchSet;
0148 }
0149
0150 bool operator<(const ArchitectureSet &o) const { return ArchSet < o.ArchSet; }
0151
0152 using iterator = arch_iterator<ArchSetType>;
0153 using const_iterator = arch_iterator<const ArchSetType>;
0154
0155 iterator begin() { return {&ArchSet}; }
0156 iterator end() { return {&ArchSet, EndIndexVal}; }
0157
0158 const_iterator begin() const { return {&ArchSet}; }
0159 const_iterator end() const { return {&ArchSet, EndIndexVal}; }
0160
0161 operator std::string() const;
0162 operator std::vector<Architecture>() const;
0163 void print(raw_ostream &OS) const;
0164 };
0165
0166 inline ArchitectureSet operator|(const Architecture &lhs,
0167 const Architecture &rhs) {
0168 return ArchitectureSet(lhs) | ArchitectureSet(rhs);
0169 }
0170
0171 raw_ostream &operator<<(raw_ostream &OS, ArchitectureSet Set);
0172
0173 }
0174 }
0175
0176 #endif