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/MachO/Architecture.h"
14 #include "llvm/ADT/StringSwitch.h"
15 #include "llvm/BinaryFormat/MachO.h"
20 Architecture
getArchitectureFromCpuType(uint32_t CPUType
, uint32_t CPUSubType
) {
21 #define ARCHINFO(Arch, Type, Subtype) \
22 if (CPUType == (Type) && \
23 (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) == (Subtype)) \
25 #include "llvm/TextAPI/MachO/Architecture.def"
31 Architecture
getArchitectureFromName(StringRef Name
) {
32 return StringSwitch
<Architecture
>(Name
)
33 #define ARCHINFO(Arch, Type, Subtype) .Case(#Arch, AK_##Arch)
34 #include "llvm/TextAPI/MachO/Architecture.def"
39 StringRef
getArchitectureName(Architecture Arch
) {
41 #define ARCHINFO(Arch, Type, Subtype) \
44 #include "llvm/TextAPI/MachO/Architecture.def"
50 // Appease some compilers that cannot figure out that this is a fully covered
55 std::pair
<uint32_t, uint32_t> getCPUTypeFromArchitecture(Architecture Arch
) {
57 #define ARCHINFO(Arch, Type, Subtype) \
59 return std::make_pair(Type, Subtype);
60 #include "llvm/TextAPI/MachO/Architecture.def"
63 return std::make_pair(0, 0);
66 // Appease some compilers that cannot figure out that this is a fully covered
68 return std::make_pair(0, 0);
71 Architecture
mapToArchitecture(const Triple
&Target
) {
72 return getArchitectureFromName(Target
.getArchName());
75 raw_ostream
&operator<<(raw_ostream
&OS
, Architecture Arch
) {
76 OS
<< getArchitectureName(Arch
);
80 } // end namespace MachO.
81 } // end namespace llvm.