Path: blob/main/contrib/llvm-project/llvm/lib/TextAPI/ArchitectureSet.cpp
35262 views
//===- ArchitectureSet.cpp ------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// Implements the architecture set.9//10//===----------------------------------------------------------------------===//1112#include "llvm/TextAPI/ArchitectureSet.h"13#include "llvm/Support/raw_ostream.h"1415namespace llvm {16namespace MachO {1718ArchitectureSet::ArchitectureSet(const std::vector<Architecture> &Archs)19: ArchitectureSet() {20for (auto Arch : Archs) {21if (Arch == AK_unknown)22continue;23set(Arch);24}25}2627size_t ArchitectureSet::count() const {28// popcnt29size_t Cnt = 0;30for (unsigned i = 0; i < sizeof(ArchSetType) * 8; ++i)31if (ArchSet & (1U << i))32++Cnt;33return Cnt;34}3536ArchitectureSet::operator std::string() const {37if (empty())38return "[(empty)]";3940std::string result;41auto size = count();42for (auto arch : *this) {43result.append(std::string(getArchitectureName(arch)));44size -= 1;45if (size)46result.append(" ");47}48return result;49}5051ArchitectureSet::operator std::vector<Architecture>() const {52std::vector<Architecture> archs;53for (auto arch : *this) {54if (arch == AK_unknown)55continue;56archs.emplace_back(arch);57}58return archs;59}6061void ArchitectureSet::print(raw_ostream &os) const { os << std::string(*this); }6263raw_ostream &operator<<(raw_ostream &os, ArchitectureSet set) {64set.print(os);65return os;66}6768} // end namespace MachO.69} // end namespace llvm.707172