OSDN Git Service

[CallSiteSplitting] Report edge deletion to DomTreeUpdater
[android-x86/external-llvm.git] / lib / TextAPI / MachO / Architecture.cpp
1 //===- llvm/TextAPI/Architecture.cpp - Architecture -------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief Implements the architecture helper functions.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/TextAPI/MachO/Architecture.h"
16 #include "llvm/ADT/StringSwitch.h"
17 #include "llvm/BinaryFormat/MachO.h"
18
19 namespace llvm {
20 namespace MachO {
21
22 Architecture getArchitectureFromCpuType(uint32_t CPUType, uint32_t CPUSubType) {
23 #define ARCHINFO(Arch, Type, Subtype)                                          \
24   if (CPUType == (Type) &&                                                     \
25       (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) == (Subtype))                    \
26     return Architecture::Arch;
27 #include "llvm/TextAPI/MachO/Architecture.def"
28 #undef ARCHINFO
29
30   return Architecture::unknown;
31 }
32
33 Architecture getArchitectureFromName(StringRef Name) {
34   return StringSwitch<Architecture>(Name)
35 #define ARCHINFO(Arch, Type, Subtype) .Case(#Arch, Architecture::Arch)
36 #include "llvm/TextAPI/MachO/Architecture.def"
37 #undef ARCHINFO
38       .Default(Architecture::unknown);
39 }
40
41 StringRef getArchitectureName(Architecture Arch) {
42   switch (Arch) {
43 #define ARCHINFO(Arch, Type, Subtype)                                          \
44   case Architecture::Arch:                                                     \
45     return #Arch;
46 #include "llvm/TextAPI/MachO/Architecture.def"
47 #undef ARCHINFO
48   case Architecture::unknown:
49     return "unknown";
50   }
51
52   // Appease some compilers that cannot figure out that this is a fully covered
53   // switch statement.
54   return "unknown";
55 }
56
57 std::pair<uint32_t, uint32_t> getCPUTypeFromArchitecture(Architecture Arch) {
58   switch (Arch) {
59 #define ARCHINFO(Arch, Type, Subtype)                                          \
60   case Architecture::Arch:                                                     \
61     return std::make_pair(Type, Subtype);
62 #include "llvm/TextAPI/MachO/Architecture.def"
63 #undef ARCHINFO
64   case Architecture::unknown:
65     return std::make_pair(0, 0);
66   }
67
68   // Appease some compilers that cannot figure out that this is a fully covered
69   // switch statement.
70   return std::make_pair(0, 0);
71 }
72
73 raw_ostream &operator<<(raw_ostream &OS, Architecture Arch) {
74   OS << getArchitectureName(Arch);
75   return OS;
76 }
77
78 } // end namespace MachO.
79 } // end namespace llvm.