blob: 9d80222be6a6bf2b016df6d9c0c929ce178b78d0 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ArchSpec.cpp --------------------------------------------*- 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#include "lldb/Core/ArchSpec.h"
11
Eli Friedman50fac2f2010-06-11 04:26:08 +000012#include <stdio.h>
Jason Molendadfa424c2012-09-18 23:27:18 +000013#include <errno.h>
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014
15#include <string>
16
Saleem Abdulrasool28606952014-06-27 05:17:41 +000017#include "llvm/ADT/STLExtras.h"
Charles Davis237ad972013-08-27 05:04:33 +000018#include "llvm/Support/COFF.h"
Greg Clayton41f92322010-06-11 03:25:34 +000019#include "llvm/Support/ELF.h"
Stephen Wilsonfacebfc2011-02-24 19:13:58 +000020#include "llvm/Support/Host.h"
Jim Ingham46d005d2014-04-02 22:53:21 +000021#include "lldb/Utility/SafeMachO.h"
Greg Claytone795f1b2012-08-08 01:19:34 +000022#include "lldb/Core/RegularExpression.h"
Zachary Turner13b18262014-08-20 16:42:51 +000023#include "lldb/Core/StringList.h"
Greg Clayton514487e2011-02-15 21:59:32 +000024#include "lldb/Host/Endian.h"
Zachary Turner13b18262014-08-20 16:42:51 +000025#include "lldb/Host/HostInfo.h"
Greg Claytoneb0103f2011-04-07 22:46:35 +000026#include "lldb/Target/Platform.h"
Greg Clayton41f92322010-06-11 03:25:34 +000027
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028using namespace lldb;
29using namespace lldb_private;
30
Greg Clayton64195a22011-02-23 00:35:02 +000031#define ARCH_SPEC_SEPARATOR_CHAR '-'
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
Jason Molendaba813dc2012-11-04 03:20:05 +000033
34static bool cores_match (const ArchSpec::Core core1, const ArchSpec::Core core2, bool try_inverse, bool enforce_exact_match);
35
Greg Clayton64195a22011-02-23 00:35:02 +000036namespace lldb_private {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037
Greg Clayton64195a22011-02-23 00:35:02 +000038 struct CoreDefinition
39 {
40 ByteOrder default_byte_order;
41 uint32_t addr_byte_size;
Greg Clayton357132e2011-03-26 19:14:58 +000042 uint32_t min_opcode_byte_size;
43 uint32_t max_opcode_byte_size;
Greg Clayton64195a22011-02-23 00:35:02 +000044 llvm::Triple::ArchType machine;
45 ArchSpec::Core core;
Greg Clayton56b79682014-07-23 18:12:06 +000046 const char * const name;
Greg Clayton64195a22011-02-23 00:35:02 +000047 };
48
49}
50
51// This core information can be looked using the ArchSpec::Core as the index
Greg Clayton56b79682014-07-23 18:12:06 +000052static const CoreDefinition g_core_definitions[] =
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053{
Greg Clayton357132e2011-03-26 19:14:58 +000054 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_generic , "arm" },
55 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv4 , "armv4" },
56 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv4t , "armv4t" },
57 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv5 , "armv5" },
Greg Claytonb5c39fe2011-12-16 18:15:52 +000058 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv5e , "armv5e" },
Greg Clayton357132e2011-03-26 19:14:58 +000059 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv5t , "armv5t" },
60 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv6 , "armv6" },
Jason Molendaa3a04522013-09-27 23:21:54 +000061 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv6m , "armv6m" },
Greg Clayton357132e2011-03-26 19:14:58 +000062 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7 , "armv7" },
63 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7f , "armv7f" },
Greg Clayton357132e2011-03-26 19:14:58 +000064 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7s , "armv7s" },
Jason Molenda7a1559c2013-03-08 01:20:17 +000065 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7k , "armv7k" },
66 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7m , "armv7m" },
67 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7em , "armv7em" },
Greg Clayton357132e2011-03-26 19:14:58 +000068 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_xscale , "xscale" },
Greg Claytonb5c39fe2011-12-16 18:15:52 +000069 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumb , "thumb" },
70 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv4t , "thumbv4t" },
71 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv5 , "thumbv5" },
72 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv5e , "thumbv5e" },
73 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv6 , "thumbv6" },
Jason Molendaa3a04522013-09-27 23:21:54 +000074 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv6m , "thumbv6m" },
Greg Claytonb5c39fe2011-12-16 18:15:52 +000075 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7 , "thumbv7" },
76 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7f , "thumbv7f" },
Greg Claytonb5c39fe2011-12-16 18:15:52 +000077 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7s , "thumbv7s" },
Jason Molenda7a1559c2013-03-08 01:20:17 +000078 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7k , "thumbv7k" },
79 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7m , "thumbv7m" },
80 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7em , "thumbv7em" },
Todd Fialad8eaa172014-07-23 14:37:35 +000081 { eByteOrderLittle, 8, 4, 4, llvm::Triple::aarch64, ArchSpec::eCore_arm_arm64 , "arm64" },
Todd Fiala02e71812014-08-28 14:32:43 +000082 { eByteOrderLittle, 8, 4, 4, llvm::Triple::aarch64, ArchSpec::eCore_arm_armv8 , "armv8" },
83 { eByteOrderLittle, 8, 4, 4, llvm::Triple::aarch64, ArchSpec::eCore_arm_aarch64 , "aarch64" },
Ed Masteb73f8442013-10-10 00:59:47 +000084
85 { eByteOrderBig , 8, 4, 4, llvm::Triple::mips64 , ArchSpec::eCore_mips64 , "mips64" },
Greg Clayton64195a22011-02-23 00:35:02 +000086
Greg Clayton83b162d2013-08-12 18:34:04 +000087 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_generic , "ppc" },
88 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc601 , "ppc601" },
89 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc602 , "ppc602" },
90 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc603 , "ppc603" },
91 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc603e , "ppc603e" },
92 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc603ev , "ppc603ev" },
93 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc604 , "ppc604" },
94 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc604e , "ppc604e" },
95 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc620 , "ppc620" },
96 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc750 , "ppc750" },
97 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc7400 , "ppc7400" },
98 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc7450 , "ppc7450" },
99 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc970 , "ppc970" },
Greg Clayton64195a22011-02-23 00:35:02 +0000100
Greg Clayton83b162d2013-08-12 18:34:04 +0000101 { eByteOrderBig , 8, 4, 4, llvm::Triple::ppc64 , ArchSpec::eCore_ppc64_generic , "ppc64" },
102 { eByteOrderBig , 8, 4, 4, llvm::Triple::ppc64 , ArchSpec::eCore_ppc64_ppc970_64 , "ppc970-64" },
Greg Clayton64195a22011-02-23 00:35:02 +0000103
Greg Clayton357132e2011-03-26 19:14:58 +0000104 { eByteOrderLittle, 4, 4, 4, llvm::Triple::sparc , ArchSpec::eCore_sparc_generic , "sparc" },
105 { eByteOrderLittle, 8, 4, 4, llvm::Triple::sparcv9, ArchSpec::eCore_sparc9_generic , "sparcv9" },
Greg Clayton64195a22011-02-23 00:35:02 +0000106
Greg Claytonab65b342011-04-13 22:47:15 +0000107 { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i386 , "i386" },
108 { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i486 , "i486" },
109 { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i486sx , "i486sx" },
Virgile Bello97a70e42014-04-08 14:48:48 +0000110 { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i686 , "i686" },
Greg Clayton64195a22011-02-23 00:35:02 +0000111
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000112 { eByteOrderLittle, 8, 1, 15, llvm::Triple::x86_64 , ArchSpec::eCore_x86_64_x86_64 , "x86_64" },
Greg Claytona86dc432014-01-22 23:42:03 +0000113 { eByteOrderLittle, 8, 1, 15, llvm::Triple::x86_64 , ArchSpec::eCore_x86_64_x86_64h , "x86_64h" },
Deepak Panickal6d3df422014-02-19 11:16:46 +0000114 { eByteOrderLittle, 4, 4, 4, llvm::Triple::hexagon , ArchSpec::eCore_hexagon_generic, "hexagon" },
115 { eByteOrderLittle, 4, 4, 4, llvm::Triple::hexagon , ArchSpec::eCore_hexagon_hexagonv4, "hexagonv4" },
116 { eByteOrderLittle, 4, 4, 4, llvm::Triple::hexagon , ArchSpec::eCore_hexagon_hexagonv5, "hexagonv5" },
117
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000118 { eByteOrderLittle, 4, 4, 4 , llvm::Triple::UnknownArch , ArchSpec::eCore_uknownMach32 , "unknown-mach-32" },
Todd Fiala14bbef52014-07-01 23:33:32 +0000119 { eByteOrderLittle, 8, 4, 4 , llvm::Triple::UnknownArch , ArchSpec::eCore_uknownMach64 , "unknown-mach-64" },
120
Matthew Gardiner5f675792014-08-27 12:09:39 +0000121 { eByteOrderLittle, 4, 1, 1 , llvm::Triple::kalimba , ArchSpec::eCore_kalimba , "kalimba" },
122 { eByteOrderBig , 4, 1, 1 , llvm::Triple::kalimba , ArchSpec::eCore_kalimba3 , "kalimba3" },
123 { eByteOrderLittle, 4, 1, 1 , llvm::Triple::kalimba , ArchSpec::eCore_kalimba4 , "kalimba4" },
124 { eByteOrderLittle, 4, 1, 1 , llvm::Triple::kalimba , ArchSpec::eCore_kalimba5 , "kalimba5" }
Greg Clayton64195a22011-02-23 00:35:02 +0000125};
126
Greg Clayton56b79682014-07-23 18:12:06 +0000127// Ensure that we have an entry in the g_core_definitions for each core. If you comment out an entry above,
128// you will need to comment out the corresponding ArchSpec::Core enumeration.
Zachary Turner3b2065f2014-07-28 16:44:28 +0000129static_assert(sizeof(g_core_definitions) / sizeof(CoreDefinition) == ArchSpec::kNumCores, "make sure we have one core definition for each core");
Greg Clayton56b79682014-07-23 18:12:06 +0000130
131
Greg Clayton64195a22011-02-23 00:35:02 +0000132struct ArchDefinitionEntry
133{
134 ArchSpec::Core core;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000135 uint32_t cpu;
136 uint32_t sub;
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000137 uint32_t cpu_mask;
138 uint32_t sub_mask;
Greg Clayton64195a22011-02-23 00:35:02 +0000139};
140
141struct ArchDefinition
142{
143 ArchitectureType type;
144 size_t num_entries;
145 const ArchDefinitionEntry *entries;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000146 const char *name;
147};
148
Greg Clayton41f92322010-06-11 03:25:34 +0000149
Greg Claytonc7bece562013-01-25 18:06:21 +0000150size_t
Greg Claytonab65b342011-04-13 22:47:15 +0000151ArchSpec::AutoComplete (const char *name, StringList &matches)
152{
153 uint32_t i;
154 if (name && name[0])
155 {
Greg Clayton56b79682014-07-23 18:12:06 +0000156 for (i = 0; i < llvm::array_lengthof(g_core_definitions); ++i)
Greg Claytonab65b342011-04-13 22:47:15 +0000157 {
158 if (NameMatches(g_core_definitions[i].name, eNameMatchStartsWith, name))
159 matches.AppendString (g_core_definitions[i].name);
160 }
161 }
162 else
163 {
Greg Clayton56b79682014-07-23 18:12:06 +0000164 for (i = 0; i < llvm::array_lengthof(g_core_definitions); ++i)
Greg Claytonab65b342011-04-13 22:47:15 +0000165 matches.AppendString (g_core_definitions[i].name);
166 }
167 return matches.GetSize();
168}
169
170
171
Greg Clayton64195a22011-02-23 00:35:02 +0000172#define CPU_ANY (UINT32_MAX)
173
174//===----------------------------------------------------------------------===//
175// A table that gets searched linearly for matches. This table is used to
176// convert cpu type and subtypes to architecture names, and to convert
177// architecture names to cpu types and subtypes. The ordering is important and
178// allows the precedence to be set when the table is built.
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000179#define SUBTYPE_MASK 0x00FFFFFFu
Greg Clayton64195a22011-02-23 00:35:02 +0000180static const ArchDefinitionEntry g_macho_arch_entries[] =
Greg Clayton41f92322010-06-11 03:25:34 +0000181{
Charles Davis510938e2013-08-27 05:04:57 +0000182 { ArchSpec::eCore_arm_generic , llvm::MachO::CPU_TYPE_ARM , CPU_ANY, UINT32_MAX , UINT32_MAX },
183 { ArchSpec::eCore_arm_generic , llvm::MachO::CPU_TYPE_ARM , 0 , UINT32_MAX , SUBTYPE_MASK },
184 { ArchSpec::eCore_arm_armv4 , llvm::MachO::CPU_TYPE_ARM , 5 , UINT32_MAX , SUBTYPE_MASK },
185 { ArchSpec::eCore_arm_armv4t , llvm::MachO::CPU_TYPE_ARM , 5 , UINT32_MAX , SUBTYPE_MASK },
186 { ArchSpec::eCore_arm_armv6 , llvm::MachO::CPU_TYPE_ARM , 6 , UINT32_MAX , SUBTYPE_MASK },
Jason Molenda64a11732013-10-08 03:01:08 +0000187 { ArchSpec::eCore_arm_armv6m , llvm::MachO::CPU_TYPE_ARM , 14 , UINT32_MAX , SUBTYPE_MASK },
Charles Davis510938e2013-08-27 05:04:57 +0000188 { ArchSpec::eCore_arm_armv5 , llvm::MachO::CPU_TYPE_ARM , 7 , UINT32_MAX , SUBTYPE_MASK },
189 { ArchSpec::eCore_arm_armv5e , llvm::MachO::CPU_TYPE_ARM , 7 , UINT32_MAX , SUBTYPE_MASK },
190 { ArchSpec::eCore_arm_armv5t , llvm::MachO::CPU_TYPE_ARM , 7 , UINT32_MAX , SUBTYPE_MASK },
191 { ArchSpec::eCore_arm_xscale , llvm::MachO::CPU_TYPE_ARM , 8 , UINT32_MAX , SUBTYPE_MASK },
192 { ArchSpec::eCore_arm_armv7 , llvm::MachO::CPU_TYPE_ARM , 9 , UINT32_MAX , SUBTYPE_MASK },
193 { ArchSpec::eCore_arm_armv7f , llvm::MachO::CPU_TYPE_ARM , 10 , UINT32_MAX , SUBTYPE_MASK },
194 { ArchSpec::eCore_arm_armv7s , llvm::MachO::CPU_TYPE_ARM , 11 , UINT32_MAX , SUBTYPE_MASK },
195 { ArchSpec::eCore_arm_armv7k , llvm::MachO::CPU_TYPE_ARM , 12 , UINT32_MAX , SUBTYPE_MASK },
196 { ArchSpec::eCore_arm_armv7m , llvm::MachO::CPU_TYPE_ARM , 15 , UINT32_MAX , SUBTYPE_MASK },
197 { ArchSpec::eCore_arm_armv7em , llvm::MachO::CPU_TYPE_ARM , 16 , UINT32_MAX , SUBTYPE_MASK },
Jason Molendaa3329782014-03-29 18:54:20 +0000198 { ArchSpec::eCore_arm_arm64 , llvm::MachO::CPU_TYPE_ARM64 , CPU_ANY, UINT32_MAX , SUBTYPE_MASK },
199 { ArchSpec::eCore_arm_arm64 , llvm::MachO::CPU_TYPE_ARM64 , 0 , UINT32_MAX , SUBTYPE_MASK },
200 { ArchSpec::eCore_arm_arm64 , llvm::MachO::CPU_TYPE_ARM64 , 1 , UINT32_MAX , SUBTYPE_MASK },
201 { ArchSpec::eCore_arm_arm64 , llvm::MachO::CPU_TYPE_ARM64 , 13 , UINT32_MAX , SUBTYPE_MASK },
Charles Davis510938e2013-08-27 05:04:57 +0000202 { ArchSpec::eCore_thumb , llvm::MachO::CPU_TYPE_ARM , 0 , UINT32_MAX , SUBTYPE_MASK },
203 { ArchSpec::eCore_thumbv4t , llvm::MachO::CPU_TYPE_ARM , 5 , UINT32_MAX , SUBTYPE_MASK },
204 { ArchSpec::eCore_thumbv5 , llvm::MachO::CPU_TYPE_ARM , 7 , UINT32_MAX , SUBTYPE_MASK },
205 { ArchSpec::eCore_thumbv5e , llvm::MachO::CPU_TYPE_ARM , 7 , UINT32_MAX , SUBTYPE_MASK },
206 { ArchSpec::eCore_thumbv6 , llvm::MachO::CPU_TYPE_ARM , 6 , UINT32_MAX , SUBTYPE_MASK },
Jason Molenda64a11732013-10-08 03:01:08 +0000207 { ArchSpec::eCore_thumbv6m , llvm::MachO::CPU_TYPE_ARM , 14 , UINT32_MAX , SUBTYPE_MASK },
Charles Davis510938e2013-08-27 05:04:57 +0000208 { ArchSpec::eCore_thumbv7 , llvm::MachO::CPU_TYPE_ARM , 9 , UINT32_MAX , SUBTYPE_MASK },
209 { ArchSpec::eCore_thumbv7f , llvm::MachO::CPU_TYPE_ARM , 10 , UINT32_MAX , SUBTYPE_MASK },
210 { ArchSpec::eCore_thumbv7s , llvm::MachO::CPU_TYPE_ARM , 11 , UINT32_MAX , SUBTYPE_MASK },
211 { ArchSpec::eCore_thumbv7k , llvm::MachO::CPU_TYPE_ARM , 12 , UINT32_MAX , SUBTYPE_MASK },
212 { ArchSpec::eCore_thumbv7m , llvm::MachO::CPU_TYPE_ARM , 15 , UINT32_MAX , SUBTYPE_MASK },
213 { ArchSpec::eCore_thumbv7em , llvm::MachO::CPU_TYPE_ARM , 16 , UINT32_MAX , SUBTYPE_MASK },
214 { ArchSpec::eCore_ppc_generic , llvm::MachO::CPU_TYPE_POWERPC , CPU_ANY, UINT32_MAX , UINT32_MAX },
215 { ArchSpec::eCore_ppc_generic , llvm::MachO::CPU_TYPE_POWERPC , 0 , UINT32_MAX , SUBTYPE_MASK },
216 { ArchSpec::eCore_ppc_ppc601 , llvm::MachO::CPU_TYPE_POWERPC , 1 , UINT32_MAX , SUBTYPE_MASK },
217 { ArchSpec::eCore_ppc_ppc602 , llvm::MachO::CPU_TYPE_POWERPC , 2 , UINT32_MAX , SUBTYPE_MASK },
218 { ArchSpec::eCore_ppc_ppc603 , llvm::MachO::CPU_TYPE_POWERPC , 3 , UINT32_MAX , SUBTYPE_MASK },
219 { ArchSpec::eCore_ppc_ppc603e , llvm::MachO::CPU_TYPE_POWERPC , 4 , UINT32_MAX , SUBTYPE_MASK },
220 { ArchSpec::eCore_ppc_ppc603ev , llvm::MachO::CPU_TYPE_POWERPC , 5 , UINT32_MAX , SUBTYPE_MASK },
221 { ArchSpec::eCore_ppc_ppc604 , llvm::MachO::CPU_TYPE_POWERPC , 6 , UINT32_MAX , SUBTYPE_MASK },
222 { ArchSpec::eCore_ppc_ppc604e , llvm::MachO::CPU_TYPE_POWERPC , 7 , UINT32_MAX , SUBTYPE_MASK },
223 { ArchSpec::eCore_ppc_ppc620 , llvm::MachO::CPU_TYPE_POWERPC , 8 , UINT32_MAX , SUBTYPE_MASK },
224 { ArchSpec::eCore_ppc_ppc750 , llvm::MachO::CPU_TYPE_POWERPC , 9 , UINT32_MAX , SUBTYPE_MASK },
225 { ArchSpec::eCore_ppc_ppc7400 , llvm::MachO::CPU_TYPE_POWERPC , 10 , UINT32_MAX , SUBTYPE_MASK },
226 { ArchSpec::eCore_ppc_ppc7450 , llvm::MachO::CPU_TYPE_POWERPC , 11 , UINT32_MAX , SUBTYPE_MASK },
227 { ArchSpec::eCore_ppc_ppc970 , llvm::MachO::CPU_TYPE_POWERPC , 100 , UINT32_MAX , SUBTYPE_MASK },
228 { ArchSpec::eCore_ppc64_generic , llvm::MachO::CPU_TYPE_POWERPC64 , 0 , UINT32_MAX , SUBTYPE_MASK },
229 { ArchSpec::eCore_ppc64_ppc970_64 , llvm::MachO::CPU_TYPE_POWERPC64 , 100 , UINT32_MAX , SUBTYPE_MASK },
230 { ArchSpec::eCore_x86_32_i386 , llvm::MachO::CPU_TYPE_I386 , 3 , UINT32_MAX , SUBTYPE_MASK },
231 { ArchSpec::eCore_x86_32_i486 , llvm::MachO::CPU_TYPE_I386 , 4 , UINT32_MAX , SUBTYPE_MASK },
232 { ArchSpec::eCore_x86_32_i486sx , llvm::MachO::CPU_TYPE_I386 , 0x84 , UINT32_MAX , SUBTYPE_MASK },
Greg Claytona86dc432014-01-22 23:42:03 +0000233 { ArchSpec::eCore_x86_32_i386 , llvm::MachO::CPU_TYPE_I386 , CPU_ANY, UINT32_MAX , UINT32_MAX },
Charles Davis510938e2013-08-27 05:04:57 +0000234 { ArchSpec::eCore_x86_64_x86_64 , llvm::MachO::CPU_TYPE_X86_64 , 3 , UINT32_MAX , SUBTYPE_MASK },
235 { ArchSpec::eCore_x86_64_x86_64 , llvm::MachO::CPU_TYPE_X86_64 , 4 , UINT32_MAX , SUBTYPE_MASK },
Greg Claytona86dc432014-01-22 23:42:03 +0000236 { ArchSpec::eCore_x86_64_x86_64h , llvm::MachO::CPU_TYPE_X86_64 , 8 , UINT32_MAX , SUBTYPE_MASK },
237 { ArchSpec::eCore_x86_64_x86_64 , llvm::MachO::CPU_TYPE_X86_64 , CPU_ANY, UINT32_MAX , UINT32_MAX },
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000238 // Catch any unknown mach architectures so we can always use the object and symbol mach-o files
Charles Davis510938e2013-08-27 05:04:57 +0000239 { ArchSpec::eCore_uknownMach32 , 0 , 0 , 0xFF000000u, 0x00000000u },
240 { ArchSpec::eCore_uknownMach64 , llvm::MachO::CPU_ARCH_ABI64 , 0 , 0xFF000000u, 0x00000000u }
Greg Clayton64195a22011-02-23 00:35:02 +0000241};
242static const ArchDefinition g_macho_arch_def = {
243 eArchTypeMachO,
Saleem Abdulrasool28606952014-06-27 05:17:41 +0000244 llvm::array_lengthof(g_macho_arch_entries),
Greg Clayton64195a22011-02-23 00:35:02 +0000245 g_macho_arch_entries,
Greg Clayton64195a22011-02-23 00:35:02 +0000246 "mach-o"
Greg Clayton41f92322010-06-11 03:25:34 +0000247};
248
Greg Clayton64195a22011-02-23 00:35:02 +0000249//===----------------------------------------------------------------------===//
250// A table that gets searched linearly for matches. This table is used to
251// convert cpu type and subtypes to architecture names, and to convert
252// architecture names to cpu types and subtypes. The ordering is important and
253// allows the precedence to be set when the table is built.
254static const ArchDefinitionEntry g_elf_arch_entries[] =
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000255{
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000256 { ArchSpec::eCore_sparc_generic , llvm::ELF::EM_SPARC , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // Sparc
257 { ArchSpec::eCore_x86_32_i386 , llvm::ELF::EM_386 , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // Intel 80386
258 { ArchSpec::eCore_x86_32_i486 , llvm::ELF::EM_486 , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // Intel 486 (deprecated)
259 { ArchSpec::eCore_ppc_generic , llvm::ELF::EM_PPC , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // PowerPC
260 { ArchSpec::eCore_ppc64_generic , llvm::ELF::EM_PPC64 , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // PowerPC64
261 { ArchSpec::eCore_arm_generic , llvm::ELF::EM_ARM , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // ARM
Todd Fiala02e71812014-08-28 14:32:43 +0000262 { ArchSpec::eCore_arm_aarch64 , llvm::ELF::EM_AARCH64, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // ARM64
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000263 { ArchSpec::eCore_sparc9_generic , llvm::ELF::EM_SPARCV9, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // SPARC V9
Ed Masteb73f8442013-10-10 00:59:47 +0000264 { ArchSpec::eCore_x86_64_x86_64 , llvm::ELF::EM_X86_64 , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // AMD64
Deepak Panickal6d3df422014-02-19 11:16:46 +0000265 { ArchSpec::eCore_mips64 , llvm::ELF::EM_MIPS , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // MIPS
Todd Fiala14bbef52014-07-01 23:33:32 +0000266 { ArchSpec::eCore_hexagon_generic , llvm::ELF::EM_HEXAGON, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // HEXAGON
Matthew Gardiner5f675792014-08-27 12:09:39 +0000267 { ArchSpec::eCore_kalimba , llvm::ELF::EM_CSR_KALIMBA, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // KALIMBA
268 { ArchSpec::eCore_kalimba3 , llvm::ELF::EM_CSR_KALIMBA, 3, 0xFFFFFFFFu, 0xFFFFFFFFu }, // KALIMBA
269 { ArchSpec::eCore_kalimba4 , llvm::ELF::EM_CSR_KALIMBA, 4, 0xFFFFFFFFu, 0xFFFFFFFFu }, // KALIMBA
270 { ArchSpec::eCore_kalimba5 , llvm::ELF::EM_CSR_KALIMBA, 5, 0xFFFFFFFFu, 0xFFFFFFFFu } // KALIMBA
Todd Fiala14bbef52014-07-01 23:33:32 +0000271
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000272};
273
Greg Clayton64195a22011-02-23 00:35:02 +0000274static const ArchDefinition g_elf_arch_def = {
275 eArchTypeELF,
Saleem Abdulrasool28606952014-06-27 05:17:41 +0000276 llvm::array_lengthof(g_elf_arch_entries),
Greg Clayton64195a22011-02-23 00:35:02 +0000277 g_elf_arch_entries,
Greg Clayton64195a22011-02-23 00:35:02 +0000278 "elf",
Greg Clayton41f92322010-06-11 03:25:34 +0000279};
280
Charles Davis237ad972013-08-27 05:04:33 +0000281static const ArchDefinitionEntry g_coff_arch_entries[] =
282{
Zachary Turnerad587ae42014-07-28 16:44:49 +0000283 { ArchSpec::eCore_x86_32_i386 , llvm::COFF::IMAGE_FILE_MACHINE_I386 , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // Intel 80x86
Charles Davis237ad972013-08-27 05:04:33 +0000284 { ArchSpec::eCore_ppc_generic , llvm::COFF::IMAGE_FILE_MACHINE_POWERPC , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // PowerPC
285 { ArchSpec::eCore_ppc_generic , llvm::COFF::IMAGE_FILE_MACHINE_POWERPCFP, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // PowerPC (with FPU)
286 { ArchSpec::eCore_arm_generic , llvm::COFF::IMAGE_FILE_MACHINE_ARM , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // ARM
Saleem Abdulrasool1108cb32014-03-11 03:09:08 +0000287 { ArchSpec::eCore_arm_armv7 , llvm::COFF::IMAGE_FILE_MACHINE_ARMNT , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // ARMv7
Charles Davis237ad972013-08-27 05:04:33 +0000288 { ArchSpec::eCore_thumb , llvm::COFF::IMAGE_FILE_MACHINE_THUMB , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // ARMv7
289 { ArchSpec::eCore_x86_64_x86_64, llvm::COFF::IMAGE_FILE_MACHINE_AMD64 , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu } // AMD64
290};
291
292static const ArchDefinition g_coff_arch_def = {
293 eArchTypeCOFF,
Saleem Abdulrasool28606952014-06-27 05:17:41 +0000294 llvm::array_lengthof(g_coff_arch_entries),
Charles Davis237ad972013-08-27 05:04:33 +0000295 g_coff_arch_entries,
296 "pe-coff",
297};
298
Greg Clayton64195a22011-02-23 00:35:02 +0000299//===----------------------------------------------------------------------===//
300// Table of all ArchDefinitions
301static const ArchDefinition *g_arch_definitions[] = {
302 &g_macho_arch_def,
Charles Davis237ad972013-08-27 05:04:33 +0000303 &g_elf_arch_def,
304 &g_coff_arch_def
Greg Clayton64195a22011-02-23 00:35:02 +0000305};
Greg Clayton41f92322010-06-11 03:25:34 +0000306
Saleem Abdulrasool28606952014-06-27 05:17:41 +0000307static const size_t k_num_arch_definitions = llvm::array_lengthof(g_arch_definitions);
Greg Clayton64195a22011-02-23 00:35:02 +0000308
309//===----------------------------------------------------------------------===//
310// Static helper functions.
311
312
313// Get the architecture definition for a given object type.
314static const ArchDefinition *
315FindArchDefinition (ArchitectureType arch_type)
316{
317 for (unsigned int i = 0; i < k_num_arch_definitions; ++i)
318 {
319 const ArchDefinition *def = g_arch_definitions[i];
320 if (def->type == arch_type)
321 return def;
322 }
323 return NULL;
324}
325
326// Get an architecture definition by name.
327static const CoreDefinition *
328FindCoreDefinition (llvm::StringRef name)
329{
Greg Clayton56b79682014-07-23 18:12:06 +0000330 for (unsigned int i = 0; i < llvm::array_lengthof(g_core_definitions); ++i)
Greg Clayton64195a22011-02-23 00:35:02 +0000331 {
332 if (name.equals_lower(g_core_definitions[i].name))
333 return &g_core_definitions[i];
334 }
335 return NULL;
336}
337
338static inline const CoreDefinition *
339FindCoreDefinition (ArchSpec::Core core)
340{
Greg Clayton56b79682014-07-23 18:12:06 +0000341 if (core >= 0 && core < llvm::array_lengthof(g_core_definitions))
Greg Clayton64195a22011-02-23 00:35:02 +0000342 return &g_core_definitions[core];
343 return NULL;
344}
345
346// Get a definition entry by cpu type and subtype.
347static const ArchDefinitionEntry *
348FindArchDefinitionEntry (const ArchDefinition *def, uint32_t cpu, uint32_t sub)
349{
350 if (def == NULL)
351 return NULL;
352
Greg Clayton64195a22011-02-23 00:35:02 +0000353 const ArchDefinitionEntry *entries = def->entries;
354 for (size_t i = 0; i < def->num_entries; ++i)
355 {
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000356 if (entries[i].cpu == (cpu & entries[i].cpu_mask))
357 if (entries[i].sub == (sub & entries[i].sub_mask))
358 return &entries[i];
Greg Clayton64195a22011-02-23 00:35:02 +0000359 }
360 return NULL;
361}
362
363static const ArchDefinitionEntry *
364FindArchDefinitionEntry (const ArchDefinition *def, ArchSpec::Core core)
365{
366 if (def == NULL)
367 return NULL;
368
369 const ArchDefinitionEntry *entries = def->entries;
370 for (size_t i = 0; i < def->num_entries; ++i)
371 {
372 if (entries[i].core == core)
373 return &entries[i];
374 }
375 return NULL;
376}
377
378//===----------------------------------------------------------------------===//
379// Constructors and destructors.
380
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381ArchSpec::ArchSpec() :
Greg Clayton514487e2011-02-15 21:59:32 +0000382 m_triple (),
Greg Clayton64195a22011-02-23 00:35:02 +0000383 m_core (kCore_invalid),
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000384 m_byte_order (eByteOrderInvalid),
385 m_distribution_id ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000386{
387}
388
Greg Claytoneb0103f2011-04-07 22:46:35 +0000389ArchSpec::ArchSpec (const char *triple_cstr, Platform *platform) :
Greg Clayton514487e2011-02-15 21:59:32 +0000390 m_triple (),
Greg Clayton64195a22011-02-23 00:35:02 +0000391 m_core (kCore_invalid),
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000392 m_byte_order (eByteOrderInvalid),
393 m_distribution_id ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000394{
Greg Clayton64195a22011-02-23 00:35:02 +0000395 if (triple_cstr)
Greg Claytoneb0103f2011-04-07 22:46:35 +0000396 SetTriple(triple_cstr, platform);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000397}
398
Greg Clayton70512312012-05-08 01:45:38 +0000399
400ArchSpec::ArchSpec (const char *triple_cstr) :
401 m_triple (),
402 m_core (kCore_invalid),
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000403 m_byte_order (eByteOrderInvalid),
404 m_distribution_id ()
Greg Clayton70512312012-05-08 01:45:38 +0000405{
406 if (triple_cstr)
407 SetTriple(triple_cstr);
408}
409
Greg Clayton64195a22011-02-23 00:35:02 +0000410ArchSpec::ArchSpec(const llvm::Triple &triple) :
Greg Clayton514487e2011-02-15 21:59:32 +0000411 m_triple (),
Greg Clayton64195a22011-02-23 00:35:02 +0000412 m_core (kCore_invalid),
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000413 m_byte_order (eByteOrderInvalid),
414 m_distribution_id ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415{
Greg Clayton64195a22011-02-23 00:35:02 +0000416 SetTriple(triple);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417}
418
Greg Claytone0d378b2011-03-24 21:19:54 +0000419ArchSpec::ArchSpec (ArchitectureType arch_type, uint32_t cpu, uint32_t subtype) :
Greg Clayton64195a22011-02-23 00:35:02 +0000420 m_triple (),
421 m_core (kCore_invalid),
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000422 m_byte_order (eByteOrderInvalid),
423 m_distribution_id ()
Greg Clayton64195a22011-02-23 00:35:02 +0000424{
425 SetArchitecture (arch_type, cpu, subtype);
426}
427
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428ArchSpec::~ArchSpec()
429{
430}
431
Greg Clayton64195a22011-02-23 00:35:02 +0000432//===----------------------------------------------------------------------===//
433// Assignment and initialization.
434
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435const ArchSpec&
436ArchSpec::operator= (const ArchSpec& rhs)
437{
438 if (this != &rhs)
439 {
Greg Clayton514487e2011-02-15 21:59:32 +0000440 m_triple = rhs.m_triple;
Greg Clayton64195a22011-02-23 00:35:02 +0000441 m_core = rhs.m_core;
Greg Clayton514487e2011-02-15 21:59:32 +0000442 m_byte_order = rhs.m_byte_order;
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000443 m_distribution_id = rhs.m_distribution_id;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000444 }
445 return *this;
446}
447
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000448void
449ArchSpec::Clear()
450{
Greg Clayton514487e2011-02-15 21:59:32 +0000451 m_triple = llvm::Triple();
Greg Clayton64195a22011-02-23 00:35:02 +0000452 m_core = kCore_invalid;
453 m_byte_order = eByteOrderInvalid;
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000454 m_distribution_id.Clear ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455}
456
Greg Clayton64195a22011-02-23 00:35:02 +0000457//===----------------------------------------------------------------------===//
458// Predicates.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459
Greg Clayton41f92322010-06-11 03:25:34 +0000460
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000461const char *
Greg Clayton64195a22011-02-23 00:35:02 +0000462ArchSpec::GetArchitectureName () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000463{
Greg Clayton64195a22011-02-23 00:35:02 +0000464 const CoreDefinition *core_def = FindCoreDefinition (m_core);
465 if (core_def)
466 return core_def->name;
467 return "unknown";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468}
469
Greg Clayton64195a22011-02-23 00:35:02 +0000470uint32_t
471ArchSpec::GetMachOCPUType () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472{
Greg Clayton64195a22011-02-23 00:35:02 +0000473 const CoreDefinition *core_def = FindCoreDefinition (m_core);
474 if (core_def)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000475 {
Greg Clayton64195a22011-02-23 00:35:02 +0000476 const ArchDefinitionEntry *arch_def = FindArchDefinitionEntry (&g_macho_arch_def, core_def->core);
477 if (arch_def)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000478 {
Greg Clayton64195a22011-02-23 00:35:02 +0000479 return arch_def->cpu;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480 }
481 }
Greg Clayton64195a22011-02-23 00:35:02 +0000482 return LLDB_INVALID_CPUTYPE;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483}
484
Greg Clayton64195a22011-02-23 00:35:02 +0000485uint32_t
486ArchSpec::GetMachOCPUSubType () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487{
Greg Clayton64195a22011-02-23 00:35:02 +0000488 const CoreDefinition *core_def = FindCoreDefinition (m_core);
489 if (core_def)
490 {
491 const ArchDefinitionEntry *arch_def = FindArchDefinitionEntry (&g_macho_arch_def, core_def->core);
492 if (arch_def)
493 {
Greg Clayton1cb64962011-03-24 04:28:38 +0000494 return arch_def->sub;
Greg Clayton64195a22011-02-23 00:35:02 +0000495 }
496 }
497 return LLDB_INVALID_CPUTYPE;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000498}
499
Greg Clayton64195a22011-02-23 00:35:02 +0000500llvm::Triple::ArchType
501ArchSpec::GetMachine () const
502{
503 const CoreDefinition *core_def = FindCoreDefinition (m_core);
504 if (core_def)
505 return core_def->machine;
506
507 return llvm::Triple::UnknownArch;
508}
509
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000510const ConstString&
511ArchSpec::GetDistributionId () const
512{
513 return m_distribution_id;
514}
515
516void
517ArchSpec::SetDistributionId (const char* distribution_id)
518{
519 m_distribution_id.SetCString (distribution_id);
520}
521
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000522uint32_t
523ArchSpec::GetAddressByteSize() const
524{
Greg Clayton64195a22011-02-23 00:35:02 +0000525 const CoreDefinition *core_def = FindCoreDefinition (m_core);
526 if (core_def)
527 return core_def->addr_byte_size;
Greg Clayton41f92322010-06-11 03:25:34 +0000528 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000529}
530
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531ByteOrder
532ArchSpec::GetDefaultEndian () const
533{
Greg Clayton64195a22011-02-23 00:35:02 +0000534 const CoreDefinition *core_def = FindCoreDefinition (m_core);
535 if (core_def)
536 return core_def->default_byte_order;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000537 return eByteOrderInvalid;
538}
539
Greg Clayton64195a22011-02-23 00:35:02 +0000540lldb::ByteOrder
541ArchSpec::GetByteOrder () const
542{
543 if (m_byte_order == eByteOrderInvalid)
544 return GetDefaultEndian();
545 return m_byte_order;
546}
547
548//===----------------------------------------------------------------------===//
549// Mutators.
550
551bool
552ArchSpec::SetTriple (const llvm::Triple &triple)
553{
554 m_triple = triple;
555
556 llvm::StringRef arch_name (m_triple.getArchName());
557 const CoreDefinition *core_def = FindCoreDefinition (arch_name);
558 if (core_def)
559 {
560 m_core = core_def->core;
Greg Claytoneb0103f2011-04-07 22:46:35 +0000561 // Set the byte order to the default byte order for an architecture.
562 // This can be modified if needed for cases when cores handle both
563 // big and little endian
564 m_byte_order = core_def->default_byte_order;
Greg Clayton64195a22011-02-23 00:35:02 +0000565 }
566 else
567 {
568 Clear();
569 }
570
571
572 return IsValid();
573}
574
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000575static bool
576ParseMachCPUDashSubtypeTriple (const char *triple_cstr, ArchSpec &arch)
577{
578 // Accept "12-10" or "12.10" as cpu type/subtype
579 if (isdigit(triple_cstr[0]))
580 {
581 char *end = NULL;
582 errno = 0;
Greg Claytonc7bece562013-01-25 18:06:21 +0000583 uint32_t cpu = (uint32_t)::strtoul (triple_cstr, &end, 0);
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000584 if (errno == 0 && cpu != 0 && end && ((*end == '-') || (*end == '.')))
585 {
586 errno = 0;
Greg Claytonc7bece562013-01-25 18:06:21 +0000587 uint32_t sub = (uint32_t)::strtoul (end + 1, &end, 0);
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000588 if (errno == 0 && end && ((*end == '-') || (*end == '.') || (*end == '\0')))
589 {
590 if (arch.SetArchitecture (eArchTypeMachO, cpu, sub))
591 {
592 if (*end == '-')
593 {
594 llvm::StringRef vendor_os (end + 1);
595 size_t dash_pos = vendor_os.find('-');
596 if (dash_pos != llvm::StringRef::npos)
597 {
598 llvm::StringRef vendor_str(vendor_os.substr(0, dash_pos));
599 arch.GetTriple().setVendorName(vendor_str);
600 const size_t vendor_start_pos = dash_pos+1;
Greg Claytonc7bece562013-01-25 18:06:21 +0000601 dash_pos = vendor_os.find('-', vendor_start_pos);
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000602 if (dash_pos == llvm::StringRef::npos)
603 {
604 if (vendor_start_pos < vendor_os.size())
605 arch.GetTriple().setOSName(vendor_os.substr(vendor_start_pos));
606 }
607 else
608 {
609 arch.GetTriple().setOSName(vendor_os.substr(vendor_start_pos, dash_pos - vendor_start_pos));
610 }
611 }
612 }
613 return true;
614 }
615 }
616 }
617 }
618 return false;
619}
Greg Clayton64195a22011-02-23 00:35:02 +0000620bool
Greg Clayton70512312012-05-08 01:45:38 +0000621ArchSpec::SetTriple (const char *triple_cstr)
Greg Clayton64195a22011-02-23 00:35:02 +0000622{
Greg Clayton23aca092011-08-12 23:32:52 +0000623 if (triple_cstr && triple_cstr[0])
Greg Clayton64195a22011-02-23 00:35:02 +0000624 {
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000625 if (ParseMachCPUDashSubtypeTriple (triple_cstr, *this))
626 return true;
627
Greg Clayton64195a22011-02-23 00:35:02 +0000628 llvm::StringRef triple_stref (triple_cstr);
629 if (triple_stref.startswith (LLDB_ARCH_DEFAULT))
630 {
631 // Special case for the current host default architectures...
632 if (triple_stref.equals (LLDB_ARCH_DEFAULT_32BIT))
Zachary Turner13b18262014-08-20 16:42:51 +0000633 *this = HostInfo::GetArchitecture(HostInfo::eArchKind32);
Greg Clayton64195a22011-02-23 00:35:02 +0000634 else if (triple_stref.equals (LLDB_ARCH_DEFAULT_64BIT))
Zachary Turner13b18262014-08-20 16:42:51 +0000635 *this = HostInfo::GetArchitecture(HostInfo::eArchKind64);
Greg Clayton64195a22011-02-23 00:35:02 +0000636 else if (triple_stref.equals (LLDB_ARCH_DEFAULT))
Zachary Turner13b18262014-08-20 16:42:51 +0000637 *this = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
Greg Clayton64195a22011-02-23 00:35:02 +0000638 }
639 else
640 {
641 std::string normalized_triple_sstr (llvm::Triple::normalize(triple_stref));
642 triple_stref = normalized_triple_sstr;
Greg Clayton70512312012-05-08 01:45:38 +0000643 SetTriple (llvm::Triple (triple_stref));
644 }
645 }
646 else
647 Clear();
648 return IsValid();
649}
650
651bool
652ArchSpec::SetTriple (const char *triple_cstr, Platform *platform)
653{
654 if (triple_cstr && triple_cstr[0])
655 {
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000656 if (ParseMachCPUDashSubtypeTriple (triple_cstr, *this))
657 return true;
658
Greg Clayton70512312012-05-08 01:45:38 +0000659 llvm::StringRef triple_stref (triple_cstr);
660 if (triple_stref.startswith (LLDB_ARCH_DEFAULT))
661 {
662 // Special case for the current host default architectures...
663 if (triple_stref.equals (LLDB_ARCH_DEFAULT_32BIT))
Zachary Turner13b18262014-08-20 16:42:51 +0000664 *this = HostInfo::GetArchitecture(HostInfo::eArchKind32);
Greg Clayton70512312012-05-08 01:45:38 +0000665 else if (triple_stref.equals (LLDB_ARCH_DEFAULT_64BIT))
Zachary Turner13b18262014-08-20 16:42:51 +0000666 *this = HostInfo::GetArchitecture(HostInfo::eArchKind64);
Greg Clayton70512312012-05-08 01:45:38 +0000667 else if (triple_stref.equals (LLDB_ARCH_DEFAULT))
Zachary Turner13b18262014-08-20 16:42:51 +0000668 *this = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
Greg Clayton70512312012-05-08 01:45:38 +0000669 }
670 else
671 {
672 ArchSpec raw_arch (triple_cstr);
673
674 std::string normalized_triple_sstr (llvm::Triple::normalize(triple_stref));
675 triple_stref = normalized_triple_sstr;
Greg Claytoneb0103f2011-04-07 22:46:35 +0000676 llvm::Triple normalized_triple (triple_stref);
677
678 const bool os_specified = normalized_triple.getOSName().size() > 0;
679 const bool vendor_specified = normalized_triple.getVendorName().size() > 0;
680 const bool env_specified = normalized_triple.getEnvironmentName().size() > 0;
681
682 // If we got an arch only, then default the vendor, os, environment
683 // to match the platform if one is supplied
684 if (!(os_specified || vendor_specified || env_specified))
685 {
686 if (platform)
687 {
688 // If we were given a platform, use the platform's system
689 // architecture. If this is not available (might not be
690 // connected) use the first supported architecture.
Greg Clayton70512312012-05-08 01:45:38 +0000691 ArchSpec compatible_arch;
Greg Clayton1e0c8842013-01-11 20:49:54 +0000692 if (platform->IsCompatibleArchitecture (raw_arch, false, &compatible_arch))
Greg Claytoneb0103f2011-04-07 22:46:35 +0000693 {
Greg Clayton70512312012-05-08 01:45:38 +0000694 if (compatible_arch.IsValid())
695 {
696 const llvm::Triple &compatible_triple = compatible_arch.GetTriple();
697 if (!vendor_specified)
698 normalized_triple.setVendor(compatible_triple.getVendor());
699 if (!os_specified)
700 normalized_triple.setOS(compatible_triple.getOS());
701 if (!env_specified && compatible_triple.getEnvironmentName().size())
702 normalized_triple.setEnvironment(compatible_triple.getEnvironment());
703 }
Greg Claytoneb0103f2011-04-07 22:46:35 +0000704 }
Greg Clayton70512312012-05-08 01:45:38 +0000705 else
Greg Claytoneb0103f2011-04-07 22:46:35 +0000706 {
Greg Clayton70512312012-05-08 01:45:38 +0000707 *this = raw_arch;
708 return IsValid();
Greg Claytoneb0103f2011-04-07 22:46:35 +0000709 }
710 }
711 else
712 {
713 // No platform specified, fall back to the host system for
714 // the default vendor, os, and environment.
Sean Callananbfb237bc2011-11-04 22:46:46 +0000715 llvm::Triple host_triple(llvm::sys::getDefaultTargetTriple());
Greg Clayton70512312012-05-08 01:45:38 +0000716 if (!vendor_specified)
717 normalized_triple.setVendor(host_triple.getVendor());
718 if (!vendor_specified)
719 normalized_triple.setOS(host_triple.getOS());
720 if (!env_specified && host_triple.getEnvironmentName().size())
721 normalized_triple.setEnvironment(host_triple.getEnvironment());
Greg Claytoneb0103f2011-04-07 22:46:35 +0000722 }
723 }
724 SetTriple (normalized_triple);
Greg Clayton64195a22011-02-23 00:35:02 +0000725 }
726 }
727 else
728 Clear();
729 return IsValid();
730}
731
Greg Clayton64195a22011-02-23 00:35:02 +0000732bool
Greg Claytone0d378b2011-03-24 21:19:54 +0000733ArchSpec::SetArchitecture (ArchitectureType arch_type, uint32_t cpu, uint32_t sub)
Greg Clayton64195a22011-02-23 00:35:02 +0000734{
735 m_core = kCore_invalid;
736 bool update_triple = true;
737 const ArchDefinition *arch_def = FindArchDefinition(arch_type);
738 if (arch_def)
739 {
740 const ArchDefinitionEntry *arch_def_entry = FindArchDefinitionEntry (arch_def, cpu, sub);
741 if (arch_def_entry)
742 {
743 const CoreDefinition *core_def = FindCoreDefinition (arch_def_entry->core);
744 if (core_def)
745 {
746 m_core = core_def->core;
747 update_triple = false;
Greg Clayton593577a2011-09-21 03:57:31 +0000748 // Always use the architecture name because it might be more descriptive
749 // than the architecture enum ("armv7" -> llvm::Triple::arm).
750 m_triple.setArchName(llvm::StringRef(core_def->name));
Greg Clayton64195a22011-02-23 00:35:02 +0000751 if (arch_type == eArchTypeMachO)
752 {
753 m_triple.setVendor (llvm::Triple::Apple);
Greg Clayton70512312012-05-08 01:45:38 +0000754
755 switch (core_def->machine)
756 {
Todd Fialad8eaa172014-07-23 14:37:35 +0000757 case llvm::Triple::aarch64:
Greg Clayton70512312012-05-08 01:45:38 +0000758 case llvm::Triple::arm:
759 case llvm::Triple::thumb:
760 m_triple.setOS (llvm::Triple::IOS);
761 break;
762
763 case llvm::Triple::x86:
764 case llvm::Triple::x86_64:
Greg Claytona3a6c122014-07-29 18:04:57 +0000765 // Don't set the OS for x86_64 or for x86 as we want to leave it as an "unspecified unknown"
766 // which means if we ask for the OS from the llvm::Triple we get back llvm::Triple::UnknownOS, but
767 // if we ask for the string value for the OS it will come back empty (unspecified).
768 // We do this because we now have iOS and MacOSX as the OS values for x86 and x86_64 for
769 // normal desktop and simulator binaries. And if we compare a "x86_64-apple-ios" to a "x86_64-apple-"
770 // triple, it will say it is compatible (because the OS is unspecified in the second one and will match
771 // anything in the first
772 break;
773
Greg Clayton70512312012-05-08 01:45:38 +0000774 default:
775 m_triple.setOS (llvm::Triple::MacOSX);
776 break;
777 }
Greg Clayton64195a22011-02-23 00:35:02 +0000778 }
779 else
780 {
781 m_triple.setVendor (llvm::Triple::UnknownVendor);
782 m_triple.setOS (llvm::Triple::UnknownOS);
783 }
Greg Clayton593577a2011-09-21 03:57:31 +0000784 // Fall back onto setting the machine type if the arch by name failed...
785 if (m_triple.getArch () == llvm::Triple::UnknownArch)
786 m_triple.setArch (core_def->machine);
Greg Clayton64195a22011-02-23 00:35:02 +0000787 }
788 }
789 }
790 CoreUpdated(update_triple);
791 return IsValid();
792}
793
Greg Clayton357132e2011-03-26 19:14:58 +0000794uint32_t
795ArchSpec::GetMinimumOpcodeByteSize() const
Greg Clayton64195a22011-02-23 00:35:02 +0000796{
Greg Clayton357132e2011-03-26 19:14:58 +0000797 const CoreDefinition *core_def = FindCoreDefinition (m_core);
798 if (core_def)
799 return core_def->min_opcode_byte_size;
800 return 0;
801}
802
803uint32_t
804ArchSpec::GetMaximumOpcodeByteSize() const
805{
806 const CoreDefinition *core_def = FindCoreDefinition (m_core);
807 if (core_def)
808 return core_def->max_opcode_byte_size;
809 return 0;
Greg Clayton64195a22011-02-23 00:35:02 +0000810}
811
Jason Molendaba813dc2012-11-04 03:20:05 +0000812bool
813ArchSpec::IsExactMatch (const ArchSpec& rhs) const
814{
Sean Callananbf4b7be2012-12-13 22:07:14 +0000815 return IsEqualTo (rhs, true);
Jason Molendaba813dc2012-11-04 03:20:05 +0000816}
817
818bool
819ArchSpec::IsCompatibleMatch (const ArchSpec& rhs) const
820{
Sean Callananbf4b7be2012-12-13 22:07:14 +0000821 return IsEqualTo (rhs, false);
Jason Molendaba813dc2012-11-04 03:20:05 +0000822}
823
824bool
Sean Callananbf4b7be2012-12-13 22:07:14 +0000825ArchSpec::IsEqualTo (const ArchSpec& rhs, bool exact_match) const
Jason Molendaba813dc2012-11-04 03:20:05 +0000826{
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000827 // explicitly ignoring m_distribution_id in this method.
828
Jason Molendaba813dc2012-11-04 03:20:05 +0000829 if (GetByteOrder() != rhs.GetByteOrder())
830 return false;
831
832 const ArchSpec::Core lhs_core = GetCore ();
833 const ArchSpec::Core rhs_core = rhs.GetCore ();
834
835 const bool core_match = cores_match (lhs_core, rhs_core, true, exact_match);
836
837 if (core_match)
838 {
839 const llvm::Triple &lhs_triple = GetTriple();
840 const llvm::Triple &rhs_triple = rhs.GetTriple();
841
842 const llvm::Triple::VendorType lhs_triple_vendor = lhs_triple.getVendor();
843 const llvm::Triple::VendorType rhs_triple_vendor = rhs_triple.getVendor();
844 if (lhs_triple_vendor != rhs_triple_vendor)
845 {
Sean Callananbf4b7be2012-12-13 22:07:14 +0000846 if (exact_match)
847 {
848 const bool rhs_vendor_specified = rhs.TripleVendorWasSpecified();
849 const bool lhs_vendor_specified = TripleVendorWasSpecified();
850 // Both architectures had the vendor specified, so if they aren't
851 // equal then we return false
852 if (rhs_vendor_specified && lhs_vendor_specified)
853 return false;
854 }
Jason Molendaba813dc2012-11-04 03:20:05 +0000855
856 // Only fail if both vendor types are not unknown
857 if (lhs_triple_vendor != llvm::Triple::UnknownVendor &&
858 rhs_triple_vendor != llvm::Triple::UnknownVendor)
859 return false;
860 }
861
862 const llvm::Triple::OSType lhs_triple_os = lhs_triple.getOS();
863 const llvm::Triple::OSType rhs_triple_os = rhs_triple.getOS();
864 if (lhs_triple_os != rhs_triple_os)
865 {
Sean Callananbf4b7be2012-12-13 22:07:14 +0000866 if (exact_match)
867 {
868 const bool rhs_os_specified = rhs.TripleOSWasSpecified();
869 const bool lhs_os_specified = TripleOSWasSpecified();
870 // Both architectures had the OS specified, so if they aren't
871 // equal then we return false
872 if (rhs_os_specified && lhs_os_specified)
873 return false;
874 }
Greg Clayton7ab7f892014-05-29 21:33:45 +0000875
Greg Clayton3f19ada2014-07-10 23:33:37 +0000876 // Only fail if both os types are not unknown
877 if (lhs_triple_os != llvm::Triple::UnknownOS &&
878 rhs_triple_os != llvm::Triple::UnknownOS)
879 return false;
Jason Molendaba813dc2012-11-04 03:20:05 +0000880 }
881
882 const llvm::Triple::EnvironmentType lhs_triple_env = lhs_triple.getEnvironment();
883 const llvm::Triple::EnvironmentType rhs_triple_env = rhs_triple.getEnvironment();
884
885 if (lhs_triple_env != rhs_triple_env)
886 {
887 // Only fail if both environment types are not unknown
888 if (lhs_triple_env != llvm::Triple::UnknownEnvironment &&
889 rhs_triple_env != llvm::Triple::UnknownEnvironment)
890 return false;
891 }
892 return true;
893 }
894 return false;
895}
896
Greg Clayton64195a22011-02-23 00:35:02 +0000897//===----------------------------------------------------------------------===//
898// Helper methods.
899
900void
901ArchSpec::CoreUpdated (bool update_triple)
902{
903 const CoreDefinition *core_def = FindCoreDefinition (m_core);
904 if (core_def)
905 {
906 if (update_triple)
907 m_triple = llvm::Triple(core_def->name, "unknown", "unknown");
908 m_byte_order = core_def->default_byte_order;
909 }
910 else
911 {
912 if (update_triple)
913 m_triple = llvm::Triple();
914 m_byte_order = eByteOrderInvalid;
915 }
916}
917
918//===----------------------------------------------------------------------===//
919// Operators.
920
Greg Clayton70512312012-05-08 01:45:38 +0000921static bool
Jason Molendaba813dc2012-11-04 03:20:05 +0000922cores_match (const ArchSpec::Core core1, const ArchSpec::Core core2, bool try_inverse, bool enforce_exact_match)
Greg Clayton70512312012-05-08 01:45:38 +0000923{
Jason Molendaba813dc2012-11-04 03:20:05 +0000924 if (core1 == core2)
925 return true;
926
Greg Clayton70512312012-05-08 01:45:38 +0000927 switch (core1)
928 {
Greg Clayton70512312012-05-08 01:45:38 +0000929 case ArchSpec::kCore_any:
930 return true;
931
Greg Clayton44362e02014-07-12 00:11:34 +0000932 case ArchSpec::eCore_arm_generic:
933 if (enforce_exact_match)
934 break;
935 // Fall through to case below
Greg Clayton70512312012-05-08 01:45:38 +0000936 case ArchSpec::kCore_arm_any:
937 if (core2 >= ArchSpec::kCore_arm_first && core2 <= ArchSpec::kCore_arm_last)
938 return true;
939 if (core2 >= ArchSpec::kCore_thumb_first && core2 <= ArchSpec::kCore_thumb_last)
940 return true;
941 if (core2 == ArchSpec::kCore_arm_any)
942 return true;
943 break;
Sylvestre Ledru1c9e0642014-08-18 14:53:42 +0000944
Greg Clayton70512312012-05-08 01:45:38 +0000945 case ArchSpec::kCore_x86_32_any:
946 if ((core2 >= ArchSpec::kCore_x86_32_first && core2 <= ArchSpec::kCore_x86_32_last) || (core2 == ArchSpec::kCore_x86_32_any))
947 return true;
948 break;
Zachary Turnerad587ae42014-07-28 16:44:49 +0000949
950 case ArchSpec::kCore_x86_64_any:
951 if ((core2 >= ArchSpec::kCore_x86_64_first && core2 <= ArchSpec::kCore_x86_64_last) || (core2 == ArchSpec::kCore_x86_64_any))
952 return true;
Sylvestre Ledru1c9e0642014-08-18 14:53:42 +0000953 break;
Zachary Turnerad587ae42014-07-28 16:44:49 +0000954
Greg Clayton70512312012-05-08 01:45:38 +0000955 case ArchSpec::kCore_ppc_any:
956 if ((core2 >= ArchSpec::kCore_ppc_first && core2 <= ArchSpec::kCore_ppc_last) || (core2 == ArchSpec::kCore_ppc_any))
957 return true;
958 break;
Sylvestre Ledru1c9e0642014-08-18 14:53:42 +0000959
Greg Clayton70512312012-05-08 01:45:38 +0000960 case ArchSpec::kCore_ppc64_any:
961 if ((core2 >= ArchSpec::kCore_ppc64_first && core2 <= ArchSpec::kCore_ppc64_last) || (core2 == ArchSpec::kCore_ppc64_any))
962 return true;
963 break;
964
Jason Molendaa3a04522013-09-27 23:21:54 +0000965 case ArchSpec::eCore_arm_armv6m:
966 if (!enforce_exact_match)
967 {
Greg Clayton44362e02014-07-12 00:11:34 +0000968 if (core2 == ArchSpec::eCore_arm_generic)
969 return true;
Jason Molendaa3a04522013-09-27 23:21:54 +0000970 try_inverse = false;
Jason Molendac7cda272013-09-27 23:29:10 +0000971 if (core2 == ArchSpec::eCore_arm_armv7)
Jason Molendaa3a04522013-09-27 23:21:54 +0000972 return true;
973 }
Sylvestre Ledru1c9e0642014-08-18 14:53:42 +0000974 break;
Deepak Panickal6d3df422014-02-19 11:16:46 +0000975
976 case ArchSpec::kCore_hexagon_any:
977 if ((core2 >= ArchSpec::kCore_hexagon_first && core2 <= ArchSpec::kCore_hexagon_last) || (core2 == ArchSpec::kCore_hexagon_any))
978 return true;
Jason Molendaa3a04522013-09-27 23:21:54 +0000979 break;
980
Jason Molenda7a1559c2013-03-08 01:20:17 +0000981 case ArchSpec::eCore_arm_armv7m:
982 case ArchSpec::eCore_arm_armv7em:
Johnny Chen1083b0d2012-08-28 22:53:40 +0000983 case ArchSpec::eCore_arm_armv7f:
984 case ArchSpec::eCore_arm_armv7k:
985 case ArchSpec::eCore_arm_armv7s:
Jason Molendaba813dc2012-11-04 03:20:05 +0000986 if (!enforce_exact_match)
987 {
Greg Clayton44362e02014-07-12 00:11:34 +0000988 if (core2 == ArchSpec::eCore_arm_generic)
989 return true;
Jason Molendaba813dc2012-11-04 03:20:05 +0000990 if (core2 == ArchSpec::eCore_arm_armv7)
991 return true;
Greg Clayton44362e02014-07-12 00:11:34 +0000992 try_inverse = false;
Jason Molendaba813dc2012-11-04 03:20:05 +0000993 }
Johnny Chen1083b0d2012-08-28 22:53:40 +0000994 break;
Sylvestre Ledru1c9e0642014-08-18 14:53:42 +0000995
Greg Clayton52edb362014-07-14 22:53:02 +0000996 case ArchSpec::eCore_x86_64_x86_64h:
997 if (!enforce_exact_match)
998 {
999 try_inverse = false;
1000 if (core2 == ArchSpec::eCore_x86_64_x86_64)
1001 return true;
1002 }
1003 break;
Johnny Chen1083b0d2012-08-28 22:53:40 +00001004
Matthew Gardiner5f675792014-08-27 12:09:39 +00001005 case ArchSpec::eCore_kalimba:
1006 case ArchSpec::eCore_kalimba3:
1007 case ArchSpec::eCore_kalimba4:
1008 case ArchSpec::eCore_kalimba5:
1009 if (core2 >= ArchSpec::kCore_kalimba_first && core2 <= ArchSpec::kCore_kalimba_last)
1010 {
1011 return true;
1012 }
1013 break;
1014
Todd Fiala02e71812014-08-28 14:32:43 +00001015 case ArchSpec::eCore_arm_armv8:
1016 if (!enforce_exact_match)
1017 {
1018 if (core2 == ArchSpec::eCore_arm_arm64)
1019 return true;
1020 if (core2 == ArchSpec::eCore_arm_aarch64)
1021 return true;
1022 try_inverse = false;
1023 }
1024 break;
1025
1026 case ArchSpec::eCore_arm_aarch64:
1027 if (!enforce_exact_match)
1028 {
1029 if (core2 == ArchSpec::eCore_arm_arm64)
1030 return true;
1031 if (core2 == ArchSpec::eCore_arm_armv8)
1032 return true;
1033 try_inverse = false;
1034 }
1035 break;
1036
1037 case ArchSpec::eCore_arm_arm64:
1038 if (!enforce_exact_match)
1039 {
1040 if (core2 == ArchSpec::eCore_arm_aarch64)
1041 return true;
1042 if (core2 == ArchSpec::eCore_arm_armv8)
1043 return true;
1044 try_inverse = false;
1045 }
1046 break;
1047
Greg Clayton70512312012-05-08 01:45:38 +00001048 default:
1049 break;
1050 }
1051 if (try_inverse)
Jason Molendaba813dc2012-11-04 03:20:05 +00001052 return cores_match (core2, core1, false, enforce_exact_match);
Greg Clayton70512312012-05-08 01:45:38 +00001053 return false;
1054}
1055
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001056bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001057lldb_private::operator<(const ArchSpec& lhs, const ArchSpec& rhs)
1058{
Greg Clayton64195a22011-02-23 00:35:02 +00001059 const ArchSpec::Core lhs_core = lhs.GetCore ();
1060 const ArchSpec::Core rhs_core = rhs.GetCore ();
1061 return lhs_core < rhs_core;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001062}