LLVM  10.0.0svn
ArchitectureSet.cpp
Go to the documentation of this file.
1 //===- ArchitectureSet.cpp ------------------------------------------------===//
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 // Implements the architecture set.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 
15 namespace llvm {
16 namespace MachO {
17 
18 ArchitectureSet::ArchitectureSet(const std::vector<Architecture> &Archs)
19  : ArchitectureSet() {
20  for (auto Arch : Archs) {
21  if (Arch == AK_unknown)
22  continue;
23  set(Arch);
24  }
25 }
26 
27 size_t ArchitectureSet::count() const {
28  // popcnt
29  size_t Cnt = 0;
30  for (unsigned i = 0; i < sizeof(ArchSetType) * 8; ++i)
31  if (ArchSet & (1U << i))
32  ++Cnt;
33  return Cnt;
34 }
35 
36 ArchitectureSet::operator std::string() const {
37  if (empty())
38  return "[(empty)]";
39 
40  std::string result;
41  auto size = count();
42  for (auto arch : *this) {
43  result.append(getArchitectureName(arch));
44  size -= 1;
45  if (size)
46  result.append(" ");
47  }
48  return result;
49 }
50 
51 ArchitectureSet::operator std::vector<Architecture>() const {
52  std::vector<Architecture> archs;
53  for (auto arch : *this) {
54  if (arch == AK_unknown)
55  continue;
56  archs.emplace_back(arch);
57  }
58  return archs;
59 }
60 
61 void ArchitectureSet::print(raw_ostream &os) const { os << std::string(*this); }
62 
64  set.print(os);
65  return os;
66 }
67 
68 } // end namespace MachO.
69 } // end namespace llvm.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
constexpr ArchitectureSet()=default
raw_ostream & operator<<(raw_ostream &OS, Architecture Arch)
void print(raw_ostream &OS) const
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Definition: STLExtras.h:1146
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef getArchitectureName(Architecture Arch)
Convert an architecture slice to a string.