]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/TextAPI/MachO/ArchitectureSet.cpp
Fix a memory leak in if_delgroups() introduced in r334118.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / TextAPI / MachO / ArchitectureSet.cpp
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
13 #include "llvm/TextAPI/MachO/ArchitectureSet.h"
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
63 raw_ostream &operator<<(raw_ostream &os, ArchitectureSet set) {
64   set.print(os);
65   return os;
66 }
67
68 } // end namespace MachO.
69 } // end namespace llvm.