[InstCombine] Signed saturation patterns
[llvm-complete.git] / lib / TextAPI / MachO / Architecture.cpp
blob699fb5f4587adb7e4fd28178bfcd71d1ed51321d
1 //===- Architecture.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 helper functions.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/TextAPI/MachO/Architecture.h"
14 #include "llvm/ADT/StringSwitch.h"
15 #include "llvm/BinaryFormat/MachO.h"
17 namespace llvm {
18 namespace MachO {
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)) \
24 return AK_##Arch;
25 #include "llvm/TextAPI/MachO/Architecture.def"
26 #undef ARCHINFO
28 return AK_unknown;
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"
35 #undef ARCHINFO
36 .Default(AK_unknown);
39 StringRef getArchitectureName(Architecture Arch) {
40 switch (Arch) {
41 #define ARCHINFO(Arch, Type, Subtype) \
42 case AK_##Arch: \
43 return #Arch;
44 #include "llvm/TextAPI/MachO/Architecture.def"
45 #undef ARCHINFO
46 case AK_unknown:
47 return "unknown";
50 // Appease some compilers that cannot figure out that this is a fully covered
51 // switch statement.
52 return "unknown";
55 std::pair<uint32_t, uint32_t> getCPUTypeFromArchitecture(Architecture Arch) {
56 switch (Arch) {
57 #define ARCHINFO(Arch, Type, Subtype) \
58 case AK_##Arch: \
59 return std::make_pair(Type, Subtype);
60 #include "llvm/TextAPI/MachO/Architecture.def"
61 #undef ARCHINFO
62 case AK_unknown:
63 return std::make_pair(0, 0);
66 // Appease some compilers that cannot figure out that this is a fully covered
67 // switch statement.
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);
77 return OS;
80 } // end namespace MachO.
81 } // end namespace llvm.