ArchitectureSet.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //===- llvm/TextAPI/ArchitectureSet.cpp - Architecture Set ------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. ///
  10. /// \file
  11. /// \brief Implements the architecture set.
  12. ///
  13. //===----------------------------------------------------------------------===//
  14. #include "llvm/TextAPI/MachO/ArchitectureSet.h"
  15. namespace llvm {
  16. namespace MachO {
  17. ArchitectureSet::ArchitectureSet(const std::vector<Architecture> &Archs)
  18. : ArchitectureSet() {
  19. for (auto Arch : Archs) {
  20. if (Arch == Architecture::unknown)
  21. continue;
  22. set(Arch);
  23. }
  24. }
  25. size_t ArchitectureSet::count() const {
  26. // popcnt
  27. size_t Cnt = 0;
  28. for (unsigned i = 0; i < sizeof(ArchSetType) * 8; ++i)
  29. if (ArchSet & (1U << i))
  30. ++Cnt;
  31. return Cnt;
  32. }
  33. template <typename Ty>
  34. void ArchitectureSet::arch_iterator<Ty>::findNextSetBit() {
  35. if (Index == EndIndexVal)
  36. return;
  37. do {
  38. if (*ArchSet & (1UL << ++Index))
  39. return;
  40. } while (Index < sizeof(Ty) * 8);
  41. Index = EndIndexVal;
  42. }
  43. ArchitectureSet::operator std::string() const {
  44. if (empty())
  45. return "[(empty)]";
  46. std::string result;
  47. auto size = count();
  48. for (auto arch : *this) {
  49. result.append(getArchitectureName(arch));
  50. size -= 1;
  51. if (size)
  52. result.append(" ");
  53. }
  54. return result;
  55. }
  56. ArchitectureSet::operator std::vector<Architecture>() const {
  57. std::vector<Architecture> archs;
  58. for (auto arch : *this) {
  59. if (arch == Architecture::unknown)
  60. continue;
  61. archs.emplace_back(arch);
  62. }
  63. return archs;
  64. }
  65. void ArchitectureSet::print(raw_ostream &os) const { os << std::string(*this); }
  66. raw_ostream &operator<<(raw_ostream &os, ArchitectureSet set) {
  67. set.print(os);
  68. return os;
  69. }
  70. } // end namespace MachO.
  71. } // end namespace llvm.