1 //===- Architecture.cpp ---------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // Implements the architecture helper functions.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/TextAPI/Architecture.h"
14 #include "llvm/ADT/StringSwitch.h"
15 #include "llvm/BinaryFormat/MachO.h"
16 #include "llvm/Support/ErrorHandling.h"
17 #include "llvm/Support/raw_ostream.h"
18 #include "llvm/TargetParser/Triple.h"
23 Architecture
getArchitectureFromCpuType(uint32_t CPUType
, uint32_t CPUSubType
) {
24 #define ARCHINFO(Arch, Type, Subtype, NumBits) \
25 if (CPUType == (Type) && \
26 (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) == (Subtype)) \
28 #include "llvm/TextAPI/Architecture.def"
34 Architecture
getArchitectureFromName(StringRef Name
) {
35 return StringSwitch
<Architecture
>(Name
)
36 #define ARCHINFO(Arch, Type, Subtype, NumBits) .Case(#Arch, AK_##Arch)
37 #include "llvm/TextAPI/Architecture.def"
42 StringRef
getArchitectureName(Architecture Arch
) {
44 #define ARCHINFO(Arch, Type, Subtype, NumBits) \
47 #include "llvm/TextAPI/Architecture.def"
53 // Appease some compilers that cannot figure out that this is a fully covered
58 std::pair
<uint32_t, uint32_t> getCPUTypeFromArchitecture(Architecture Arch
) {
60 #define ARCHINFO(Arch, Type, Subtype, NumBits) \
62 return std::make_pair(Type, Subtype);
63 #include "llvm/TextAPI/Architecture.def"
66 return std::make_pair(0, 0);
69 // Appease some compilers that cannot figure out that this is a fully covered
71 return std::make_pair(0, 0);
74 Architecture
mapToArchitecture(const Triple
&Target
) {
75 return getArchitectureFromName(Target
.getArchName());
78 bool is64Bit(Architecture Arch
) {
80 #define ARCHINFO(Arch, Type, Subtype, NumBits) \
83 #include "llvm/TextAPI/Architecture.def"
89 llvm_unreachable("Fully handled switch case above.");
92 raw_ostream
&operator<<(raw_ostream
&OS
, Architecture Arch
) {
93 OS
<< getArchitectureName(Arch
);
97 } // end namespace MachO.
98 } // end namespace llvm.