LLVM 17.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
13using 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();
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
71static 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())
82 if (T.isX86() && T.isArch64Bit())
84 if (T.isARM() || T.isThumb())
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}
This header is deprecated in favour of llvm/TargetParser/Triple.h.
static Error unsupported(const char *Str, const Triple &T)
Definition: MachO.cpp:71
static MachO::CPUSubTypeX86 getX86SubType(const Triple &T)
Definition: MachO.cpp:15
static MachO::CPUSubTypeARM64 getARM64SubType(const Triple &T)
Definition: MachO.cpp:57
static MachO::CPUSubTypePowerPC getPowerPCSubType(const Triple &T)
Definition: MachO.cpp:67
static MachO::CPUSubTypeARM getARMSubType(const Triple &T)
Definition: MachO.cpp:26
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This header is deprecated in favour of llvm/TargetParser/ARMTargetParser.h.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
Tagged union holding either a T or a Error.
Definition: Error.h:470
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
@ aarch64_32
Definition: Triple.h:53
ArchKind parseArch(StringRef Arch)
CPUSubTypeARM64
Definition: MachO.h:1638
@ CPU_SUBTYPE_ARM64E
Definition: MachO.h:1641
@ CPU_SUBTYPE_ARM64_ALL
Definition: MachO.h:1639
Expected< uint32_t > getCPUSubType(const Triple &T)
Definition: MachO.cpp:95
CPUSubTypePowerPC
Definition: MachO.h:1648
@ CPU_SUBTYPE_POWERPC_ALL
Definition: MachO.h:1649
@ CPU_SUBTYPE_ARM_V7
Definition: MachO.h:1629
@ CPU_SUBTYPE_ARM_V7M
Definition: MachO.h:1634
@ CPU_SUBTYPE_ARM_V6
Definition: MachO.h:1625
@ CPU_SUBTYPE_ARM_V7K
Definition: MachO.h:1632
@ CPU_SUBTYPE_ARM_V6M
Definition: MachO.h:1633
@ CPU_SUBTYPE_ARM_V5
Definition: MachO.h:1626
@ CPU_SUBTYPE_ARM_V7EM
Definition: MachO.h:1635
@ CPU_SUBTYPE_ARM_V7S
Definition: MachO.h:1631
@ CPU_SUBTYPE_ARM_V4T
Definition: MachO.h:1624
@ CPU_SUBTYPE_ARM64_32_V8
Definition: MachO.h:1644
Expected< uint32_t > getCPUType(const Triple &T)
Definition: MachO.cpp:77
@ CPU_SUBTYPE_I386_ALL
Definition: MachO.h:1586
@ CPU_SUBTYPE_X86_64_H
Definition: MachO.h:1611
@ CPU_SUBTYPE_X86_64_ALL
Definition: MachO.h:1609
@ CPU_TYPE_ARM64_32
Definition: MachO.h:1569
@ CPU_TYPE_ARM64
Definition: MachO.h:1568
@ CPU_TYPE_POWERPC
Definition: MachO.h:1571
@ CPU_TYPE_X86_64
Definition: MachO.h:1564
@ CPU_TYPE_POWERPC64
Definition: MachO.h:1572
@ CPU_TYPE_X86
Definition: MachO.h:1562
@ CPU_TYPE_ARM
Definition: MachO.h:1567
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1246