blob: a05d3ebd67bc9c6c0a53096922e9fba8edd48bc7 [file] [log] [blame]
Juergen Ributzka32cb5942019-03-22 22:46:52 +00001//===- 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
15namespace llvm {
16namespace MachO {
17
18ArchitectureSet::ArchitectureSet(const std::vector<Architecture> &Archs)
19 : ArchitectureSet() {
20 for (auto Arch : Archs) {
Juergen Ributzka875565e2019-04-04 22:56:50 +000021 if (Arch == AK_unknown)
Juergen Ributzka32cb5942019-03-22 22:46:52 +000022 continue;
23 set(Arch);
24 }
25}
26
27size_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
36ArchitectureSet::operator std::string() const {
37 if (empty())
38 return "[(empty)]";
39
40 std::string result;
41 auto size = count();
42 for (auto arch : *this) {
Benjamin Krameradcd0262020-01-28 20:23:46 +010043 result.append(std::string(getArchitectureName(arch)));
Juergen Ributzka32cb5942019-03-22 22:46:52 +000044 size -= 1;
45 if (size)
46 result.append(" ");
47 }
48 return result;
49}
50
51ArchitectureSet::operator std::vector<Architecture>() const {
52 std::vector<Architecture> archs;
53 for (auto arch : *this) {
Juergen Ributzka875565e2019-04-04 22:56:50 +000054 if (arch == AK_unknown)
Juergen Ributzka32cb5942019-03-22 22:46:52 +000055 continue;
56 archs.emplace_back(arch);
57 }
58 return archs;
59}
60
61void ArchitectureSet::print(raw_ostream &os) const { os << std::string(*this); }
62
63raw_ostream &operator<<(raw_ostream &os, ArchitectureSet set) {
64 set.print(os);
65 return os;
66}
67
68} // end namespace MachO.
69} // end namespace llvm.