LLVM  9.0.0svn
Architecture.cpp
Go to the documentation of this file.
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.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include "llvm/ADT/StringSwitch.h"
16 
17 namespace llvm {
18 namespace MachO {
19 
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
27 
28  return AK_unknown;
29 }
30 
33 #define ARCHINFO(Arch, Type, Subtype) .Case(#Arch, AK_##Arch)
34 #include "llvm/TextAPI/MachO/Architecture.def"
35 #undef ARCHINFO
36  .Default(AK_unknown);
37 }
38 
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";
48  }
49 
50  // Appease some compilers that cannot figure out that this is a fully covered
51  // switch statement.
52  return "unknown";
53 }
54 
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);
64  }
65 
66  // Appease some compilers that cannot figure out that this is a fully covered
67  // switch statement.
68  return std::make_pair(0, 0);
69 }
70 
72  OS << getArchitectureName(Arch);
73  return OS;
74 }
75 
76 } // end namespace MachO.
77 } // end namespace llvm.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
#define ARCHINFO(Arch, Type, Subtype)
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
raw_ostream & operator<<(raw_ostream &OS, Architecture Arch)
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
Definition: Architecture.h:23
std::pair< uint32_t, uint32_t > getCPUTypeFromArchitecture(Architecture Arch)
Convert an architecture slice to a CPU Type and Subtype pair.
Architecture getArchitectureFromName(StringRef Name)
Convert a name to an architecture slice.
Architecture getArchitectureFromCpuType(uint32_t CPUType, uint32_t CPUSubType)
Convert a CPU Type and Subtype pair to an architecture slice.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
StringRef getArchitectureName(Architecture Arch)
Convert an architecture slice to a string.