Path: blob/main/contrib/llvm-project/llvm/lib/TextAPI/Architecture.cpp
35262 views
//===- Architecture.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 helper functions.9//10//===----------------------------------------------------------------------===//1112#include "llvm/TextAPI/Architecture.h"13#include "llvm/ADT/StringSwitch.h"14#include "llvm/BinaryFormat/MachO.h"15#include "llvm/Support/ErrorHandling.h"16#include "llvm/Support/raw_ostream.h"17#include "llvm/TargetParser/Triple.h"1819namespace llvm {20namespace MachO {2122Architecture getArchitectureFromCpuType(uint32_t CPUType, uint32_t CPUSubType) {23#define ARCHINFO(Arch, Type, Subtype, NumBits) \24if (CPUType == (Type) && \25(CPUSubType & ~MachO::CPU_SUBTYPE_MASK) == (Subtype)) \26return AK_##Arch;27#include "llvm/TextAPI/Architecture.def"28#undef ARCHINFO2930return AK_unknown;31}3233Architecture getArchitectureFromName(StringRef Name) {34return StringSwitch<Architecture>(Name)35#define ARCHINFO(Arch, Type, Subtype, NumBits) .Case(#Arch, AK_##Arch)36#include "llvm/TextAPI/Architecture.def"37#undef ARCHINFO38.Default(AK_unknown);39}4041StringRef getArchitectureName(Architecture Arch) {42switch (Arch) {43#define ARCHINFO(Arch, Type, Subtype, NumBits) \44case AK_##Arch: \45return #Arch;46#include "llvm/TextAPI/Architecture.def"47#undef ARCHINFO48case AK_unknown:49return "unknown";50}5152// Appease some compilers that cannot figure out that this is a fully covered53// switch statement.54return "unknown";55}5657std::pair<uint32_t, uint32_t> getCPUTypeFromArchitecture(Architecture Arch) {58switch (Arch) {59#define ARCHINFO(Arch, Type, Subtype, NumBits) \60case AK_##Arch: \61return std::make_pair(Type, Subtype);62#include "llvm/TextAPI/Architecture.def"63#undef ARCHINFO64case AK_unknown:65return std::make_pair(0, 0);66}6768// Appease some compilers that cannot figure out that this is a fully covered69// switch statement.70return std::make_pair(0, 0);71}7273Architecture mapToArchitecture(const Triple &Target) {74return getArchitectureFromName(Target.getArchName());75}7677bool is64Bit(Architecture Arch) {78switch (Arch) {79#define ARCHINFO(Arch, Type, Subtype, NumBits) \80case AK_##Arch: \81return NumBits == 64;82#include "llvm/TextAPI/Architecture.def"83#undef ARCHINFO84case AK_unknown:85return false;86}8788llvm_unreachable("Fully handled switch case above.");89}9091raw_ostream &operator<<(raw_ostream &OS, Architecture Arch) {92OS << getArchitectureName(Arch);93return OS;94}9596} // end namespace MachO.97} // end namespace llvm.9899100