1 //===- llvm/TextAPI/Architecture.cpp - Architecture -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Implements the architecture helper functions.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/TextAPI/MachO/Architecture.h"
16 #include "llvm/ADT/StringSwitch.h"
17 #include "llvm/BinaryFormat/MachO.h"
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"
30 return Architecture::unknown;
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"
38 .Default(Architecture::unknown);
41 StringRef getArchitectureName(Architecture Arch) {
43 #define ARCHINFO(Arch, Type, Subtype) \
44 case Architecture::Arch: \
46 #include "llvm/TextAPI/MachO/Architecture.def"
48 case Architecture::unknown:
52 // Appease some compilers that cannot figure out that this is a fully covered
57 std::pair<uint32_t, uint32_t> getCPUTypeFromArchitecture(Architecture 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"
64 case Architecture::unknown:
65 return std::make_pair(0, 0);
68 // Appease some compilers that cannot figure out that this is a fully covered
70 return std::make_pair(0, 0);
73 raw_ostream &operator<<(raw_ostream &OS, Architecture Arch) {
74 OS << getArchitectureName(Arch);
78 } // end namespace MachO.
79 } // end namespace llvm.