/src/llvm-project/llvm/lib/TextAPI/ArchitectureSet.cpp
Line | Count | Source (jump to first uncovered line) |
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/ArchitectureSet.h" |
14 | | #include "llvm/Support/raw_ostream.h" |
15 | | |
16 | | namespace llvm { |
17 | | namespace MachO { |
18 | | |
19 | | ArchitectureSet::ArchitectureSet(const std::vector<Architecture> &Archs) |
20 | 0 | : ArchitectureSet() { |
21 | 0 | for (auto Arch : Archs) { |
22 | 0 | if (Arch == AK_unknown) |
23 | 0 | continue; |
24 | 0 | set(Arch); |
25 | 0 | } |
26 | 0 | } |
27 | | |
28 | 0 | size_t ArchitectureSet::count() const { |
29 | | // popcnt |
30 | 0 | size_t Cnt = 0; |
31 | 0 | for (unsigned i = 0; i < sizeof(ArchSetType) * 8; ++i) |
32 | 0 | if (ArchSet & (1U << i)) |
33 | 0 | ++Cnt; |
34 | 0 | return Cnt; |
35 | 0 | } |
36 | | |
37 | 0 | ArchitectureSet::operator std::string() const { |
38 | 0 | if (empty()) |
39 | 0 | return "[(empty)]"; |
40 | | |
41 | 0 | std::string result; |
42 | 0 | auto size = count(); |
43 | 0 | for (auto arch : *this) { |
44 | 0 | result.append(std::string(getArchitectureName(arch))); |
45 | 0 | size -= 1; |
46 | 0 | if (size) |
47 | 0 | result.append(" "); |
48 | 0 | } |
49 | 0 | return result; |
50 | 0 | } |
51 | | |
52 | 0 | ArchitectureSet::operator std::vector<Architecture>() const { |
53 | 0 | std::vector<Architecture> archs; |
54 | 0 | for (auto arch : *this) { |
55 | 0 | if (arch == AK_unknown) |
56 | 0 | continue; |
57 | 0 | archs.emplace_back(arch); |
58 | 0 | } |
59 | 0 | return archs; |
60 | 0 | } |
61 | | |
62 | 0 | void ArchitectureSet::print(raw_ostream &os) const { os << std::string(*this); } |
63 | | |
64 | 0 | raw_ostream &operator<<(raw_ostream &os, ArchitectureSet set) { |
65 | 0 | set.print(os); |
66 | 0 | return os; |
67 | 0 | } |
68 | | |
69 | | } // end namespace MachO. |
70 | | } // end namespace llvm. |