LLVM  13.0.0git
MachO.cpp
Go to the documentation of this file.
1 //===-- llvm/BinaryFormat/MachO.cpp - The MachO file format -----*- C++/-*-===//
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 
10 #include "llvm/ADT/Triple.h"
12 
13 using namespace llvm;
14 
16  assert(T.isX86());
17  if (T.isArch32Bit())
19 
20  assert(T.isArch64Bit());
21  if (T.getArchName() == "x86_64h")
24 }
25 
27  assert(T.isARM() || T.isThumb());
28  StringRef Arch = T.getArchName();
29  ARM::ArchKind AK = ARM::parseArch(Arch);
30  switch (AK) {
31  default:
33  case ARM::ArchKind::ARMV4T:
35  case ARM::ArchKind::ARMV5T:
36  case ARM::ArchKind::ARMV5TE:
37  case ARM::ArchKind::ARMV5TEJ:
39  case ARM::ArchKind::ARMV6:
40  case ARM::ArchKind::ARMV6K:
42  case ARM::ArchKind::ARMV7A:
44  case ARM::ArchKind::ARMV7S:
46  case ARM::ArchKind::ARMV7K:
48  case ARM::ArchKind::ARMV6M:
50  case ARM::ArchKind::ARMV7M:
52  case ARM::ArchKind::ARMV7EM:
54  }
55 }
56 
58  assert(T.isAArch64());
59  if (T.isArch32Bit())
61  if (T.isArm64e())
63 
65 }
66 
69 }
70 
71 static Error unsupported(const char *Str, const Triple &T) {
72  return createStringError(std::errc::invalid_argument,
73  "Unsupported triple for mach-o cpu %s: %s", Str,
74  T.str().c_str());
75 }
76 
78  if (!T.isOSBinFormatMachO())
79  return unsupported("type", T);
80  if (T.isX86() && T.isArch32Bit())
81  return MachO::CPU_TYPE_X86;
82  if (T.isX86() && T.isArch64Bit())
84  if (T.isARM() || T.isThumb())
85  return MachO::CPU_TYPE_ARM;
86  if (T.isAArch64())
87  return T.isArch32Bit() ? MachO::CPU_TYPE_ARM64_32 : MachO::CPU_TYPE_ARM64;
88  if (T.getArch() == Triple::ppc)
90  if (T.getArch() == Triple::ppc64)
92  return unsupported("type", T);
93 }
94 
96  if (!T.isOSBinFormatMachO())
97  return unsupported("subtype", T);
98  if (T.isX86())
99  return getX86SubType(T);
100  if (T.isARM() || T.isThumb())
101  return getARMSubType(T);
102  if (T.isAArch64() || T.getArch() == Triple::aarch64_32)
103  return getARM64SubType(T);
104  if (T.getArch() == Triple::ppc || T.getArch() == Triple::ppc64)
105  return getPowerPCSubType(T);
106  return unsupported("subtype", T);
107 }
llvm::MachO::CPU_SUBTYPE_ARM_V5
@ CPU_SUBTYPE_ARM_V5
Definition: MachO.h:1484
llvm::MachO::CPUSubTypeX86
CPUSubTypeX86
Definition: MachO.h:1443
llvm
Definition: AllocatorList.h:23
getARMSubType
static MachO::CPUSubTypeARM getARMSubType(const Triple &T)
Definition: MachO.cpp:26
llvm::MachO::CPU_SUBTYPE_ARM_V7M
@ CPU_SUBTYPE_ARM_V7M
Definition: MachO.h:1492
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::MachO::CPU_TYPE_ARM
@ CPU_TYPE_ARM
Definition: MachO.h:1425
llvm::Triple::ppc
@ ppc
Definition: Triple.h:67
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::MachO::CPU_SUBTYPE_I386_ALL
@ CPU_SUBTYPE_I386_ALL
Definition: MachO.h:1444
getARM64SubType
static MachO::CPUSubTypeARM64 getARM64SubType(const Triple &T)
Definition: MachO.cpp:57
llvm::Triple::aarch64_32
@ aarch64_32
Definition: Triple.h:54
llvm::MachO::CPU_TYPE_X86_64
@ CPU_TYPE_X86_64
Definition: MachO.h:1422
llvm::MachO::getCPUType
Expected< uint32_t > getCPUType(const Triple &T)
Definition: MachO.cpp:77
llvm::MachO::CPU_TYPE_POWERPC64
@ CPU_TYPE_POWERPC64
Definition: MachO.h:1430
llvm::MachO::CPU_SUBTYPE_ARM_V7K
@ CPU_SUBTYPE_ARM_V7K
Definition: MachO.h:1490
llvm::MachO::CPU_TYPE_POWERPC
@ CPU_TYPE_POWERPC
Definition: MachO.h:1429
llvm::Triple::ppc64
@ ppc64
Definition: Triple.h:69
llvm::MachO::CPU_SUBTYPE_POWERPC_ALL
@ CPU_SUBTYPE_POWERPC_ALL
Definition: MachO.h:1507
llvm::ARM::parseArch
ArchKind parseArch(StringRef Arch)
Definition: ARMTargetParser.cpp:28
llvm::MachO::getCPUSubType
Expected< uint32_t > getCPUSubType(const Triple &T)
Definition: MachO.cpp:95
llvm::MachO::CPU_SUBTYPE_ARM_V6
@ CPU_SUBTYPE_ARM_V6
Definition: MachO.h:1483
llvm::MachO::CPU_SUBTYPE_ARM_V4T
@ CPU_SUBTYPE_ARM_V4T
Definition: MachO.h:1482
llvm::MachO::CPU_SUBTYPE_ARM_V6M
@ CPU_SUBTYPE_ARM_V6M
Definition: MachO.h:1491
llvm::MachO::CPU_SUBTYPE_ARM_V7S
@ CPU_SUBTYPE_ARM_V7S
Definition: MachO.h:1489
llvm::MachO::CPU_TYPE_X86
@ CPU_TYPE_X86
Definition: MachO.h:1420
llvm::MachO::CPU_SUBTYPE_X86_64_H
@ CPU_SUBTYPE_X86_64_H
Definition: MachO.h:1469
llvm::MachO::CPU_TYPE_ARM64
@ CPU_TYPE_ARM64
Definition: MachO.h:1426
ARMTargetParser.h
llvm::MachO::CPU_SUBTYPE_ARM64_ALL
@ CPU_SUBTYPE_ARM64_ALL
Definition: MachO.h:1497
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Triple.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::MachO::CPUSubTypeARM64
CPUSubTypeARM64
Definition: MachO.h:1496
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1202
llvm::MachO::CPUSubTypePowerPC
CPUSubTypePowerPC
Definition: MachO.h:1506
llvm::MachO::CPU_SUBTYPE_ARM64_32_V8
@ CPU_SUBTYPE_ARM64_32_V8
Definition: MachO.h:1502
llvm::ARM::ArchKind
ArchKind
Definition: ARMTargetParser.h:104
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::MachO::CPU_TYPE_ARM64_32
@ CPU_TYPE_ARM64_32
Definition: MachO.h:1427
getPowerPCSubType
static MachO::CPUSubTypePowerPC getPowerPCSubType(const Triple &T)
Definition: MachO.cpp:67
unsupported
static Error unsupported(const char *Str, const Triple &T)
Definition: MachO.cpp:71
llvm::MachO::CPU_SUBTYPE_X86_64_ALL
@ CPU_SUBTYPE_X86_64_ALL
Definition: MachO.h:1467
llvm::MachO::CPUSubTypeARM
CPUSubTypeARM
Definition: MachO.h:1480
llvm::MachO::CPU_SUBTYPE_ARM_V7EM
@ CPU_SUBTYPE_ARM_V7EM
Definition: MachO.h:1493
MachO.h
llvm::MachO::CPU_SUBTYPE_ARM64E
@ CPU_SUBTYPE_ARM64E
Definition: MachO.h:1499
getX86SubType
static MachO::CPUSubTypeX86 getX86SubType(const Triple &T)
Definition: MachO.cpp:15
llvm::MachO::CPU_SUBTYPE_ARM_V7
@ CPU_SUBTYPE_ARM_V7
Definition: MachO.h:1487