blob: 043e16b504eddab96c72295ab15a4fb0713f3629 [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
Greg Clayton41f92322010-06-11 03:25:34 +000017#include "llvm/Support/ELF.h"
Stephen Wilsonfacebfc2011-02-24 19:13:58 +000018#include "llvm/Support/Host.h"
Greg Clayton41f92322010-06-11 03:25:34 +000019#include "llvm/Support/MachO.h"
Greg Claytone795f1b2012-08-08 01:19:34 +000020#include "lldb/Core/RegularExpression.h"
Greg Clayton514487e2011-02-15 21:59:32 +000021#include "lldb/Host/Endian.h"
22#include "lldb/Host/Host.h"
Greg Claytoneb0103f2011-04-07 22:46:35 +000023#include "lldb/Target/Platform.h"
Greg Clayton41f92322010-06-11 03:25:34 +000024
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025using namespace lldb;
26using namespace lldb_private;
27
Greg Clayton64195a22011-02-23 00:35:02 +000028#define ARCH_SPEC_SEPARATOR_CHAR '-'
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029
Greg Clayton64195a22011-02-23 00:35:02 +000030namespace lldb_private {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031
Greg Clayton64195a22011-02-23 00:35:02 +000032 struct CoreDefinition
33 {
34 ByteOrder default_byte_order;
35 uint32_t addr_byte_size;
Greg Clayton357132e2011-03-26 19:14:58 +000036 uint32_t min_opcode_byte_size;
37 uint32_t max_opcode_byte_size;
Greg Clayton64195a22011-02-23 00:35:02 +000038 llvm::Triple::ArchType machine;
39 ArchSpec::Core core;
40 const char *name;
41 };
42
43}
44
45// This core information can be looked using the ArchSpec::Core as the index
46static const CoreDefinition g_core_definitions[ArchSpec::kNumCores] =
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047{
Greg Clayton357132e2011-03-26 19:14:58 +000048 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_generic , "arm" },
49 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv4 , "armv4" },
50 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv4t , "armv4t" },
51 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv5 , "armv5" },
Greg Claytonb5c39fe2011-12-16 18:15:52 +000052 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv5e , "armv5e" },
Greg Clayton357132e2011-03-26 19:14:58 +000053 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv5t , "armv5t" },
54 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv6 , "armv6" },
55 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7 , "armv7" },
56 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7f , "armv7f" },
57 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7k , "armv7k" },
58 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7s , "armv7s" },
59 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_xscale , "xscale" },
Greg Claytonb5c39fe2011-12-16 18:15:52 +000060 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumb , "thumb" },
61 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv4t , "thumbv4t" },
62 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv5 , "thumbv5" },
63 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv5e , "thumbv5e" },
64 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv6 , "thumbv6" },
65 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7 , "thumbv7" },
66 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7f , "thumbv7f" },
67 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7k , "thumbv7k" },
68 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7s , "thumbv7s" },
69
Greg Clayton64195a22011-02-23 00:35:02 +000070
Greg Clayton357132e2011-03-26 19:14:58 +000071 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_generic , "ppc" },
72 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc601 , "ppc601" },
73 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc602 , "ppc602" },
74 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc603 , "ppc603" },
75 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc603e , "ppc603e" },
76 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc603ev , "ppc603ev" },
77 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc604 , "ppc604" },
78 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc604e , "ppc604e" },
79 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc620 , "ppc620" },
80 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc750 , "ppc750" },
81 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc7400 , "ppc7400" },
82 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc7450 , "ppc7450" },
83 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc970 , "ppc970" },
Greg Clayton64195a22011-02-23 00:35:02 +000084
Greg Clayton357132e2011-03-26 19:14:58 +000085 { eByteOrderLittle, 8, 4, 4, llvm::Triple::ppc64 , ArchSpec::eCore_ppc64_generic , "ppc64" },
86 { eByteOrderLittle, 8, 4, 4, llvm::Triple::ppc64 , ArchSpec::eCore_ppc64_ppc970_64 , "ppc970-64" },
Greg Clayton64195a22011-02-23 00:35:02 +000087
Greg Clayton357132e2011-03-26 19:14:58 +000088 { eByteOrderLittle, 4, 4, 4, llvm::Triple::sparc , ArchSpec::eCore_sparc_generic , "sparc" },
89 { eByteOrderLittle, 8, 4, 4, llvm::Triple::sparcv9, ArchSpec::eCore_sparc9_generic , "sparcv9" },
Greg Clayton64195a22011-02-23 00:35:02 +000090
Greg Claytonab65b342011-04-13 22:47:15 +000091 { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i386 , "i386" },
92 { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i486 , "i486" },
93 { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i486sx , "i486sx" },
Greg Clayton64195a22011-02-23 00:35:02 +000094
Greg Claytonab65b342011-04-13 22:47:15 +000095 { eByteOrderLittle, 8, 1, 15, llvm::Triple::x86_64 , ArchSpec::eCore_x86_64_x86_64 , "x86_64" }
Greg Clayton64195a22011-02-23 00:35:02 +000096};
97
98struct ArchDefinitionEntry
99{
100 ArchSpec::Core core;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101 uint32_t cpu;
102 uint32_t sub;
Greg Clayton64195a22011-02-23 00:35:02 +0000103};
104
105struct ArchDefinition
106{
107 ArchitectureType type;
108 size_t num_entries;
109 const ArchDefinitionEntry *entries;
110 uint32_t cpu_mask;
111 uint32_t sub_mask;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112 const char *name;
113};
114
Greg Clayton41f92322010-06-11 03:25:34 +0000115
Greg Claytonab65b342011-04-13 22:47:15 +0000116uint32_t
117ArchSpec::AutoComplete (const char *name, StringList &matches)
118{
119 uint32_t i;
120 if (name && name[0])
121 {
122 for (i = 0; i < ArchSpec::kNumCores; ++i)
123 {
124 if (NameMatches(g_core_definitions[i].name, eNameMatchStartsWith, name))
125 matches.AppendString (g_core_definitions[i].name);
126 }
127 }
128 else
129 {
130 for (i = 0; i < ArchSpec::kNumCores; ++i)
131 matches.AppendString (g_core_definitions[i].name);
132 }
133 return matches.GetSize();
134}
135
136
137
Greg Clayton64195a22011-02-23 00:35:02 +0000138#define CPU_ANY (UINT32_MAX)
139
140//===----------------------------------------------------------------------===//
141// A table that gets searched linearly for matches. This table is used to
142// convert cpu type and subtypes to architecture names, and to convert
143// architecture names to cpu types and subtypes. The ordering is important and
144// allows the precedence to be set when the table is built.
145static const ArchDefinitionEntry g_macho_arch_entries[] =
Greg Clayton41f92322010-06-11 03:25:34 +0000146{
Greg Clayton64195a22011-02-23 00:35:02 +0000147 { ArchSpec::eCore_arm_generic , llvm::MachO::CPUTypeARM , CPU_ANY },
148 { ArchSpec::eCore_arm_generic , llvm::MachO::CPUTypeARM , 0 },
149 { ArchSpec::eCore_arm_armv4 , llvm::MachO::CPUTypeARM , 5 },
Greg Claytonb5c39fe2011-12-16 18:15:52 +0000150 { ArchSpec::eCore_arm_armv4t , llvm::MachO::CPUTypeARM , 5 },
Greg Clayton64195a22011-02-23 00:35:02 +0000151 { ArchSpec::eCore_arm_armv6 , llvm::MachO::CPUTypeARM , 6 },
152 { ArchSpec::eCore_arm_armv5 , llvm::MachO::CPUTypeARM , 7 },
Greg Claytonb5c39fe2011-12-16 18:15:52 +0000153 { ArchSpec::eCore_arm_armv5e , llvm::MachO::CPUTypeARM , 7 },
154 { ArchSpec::eCore_arm_armv5t , llvm::MachO::CPUTypeARM , 7 },
Greg Clayton64195a22011-02-23 00:35:02 +0000155 { ArchSpec::eCore_arm_xscale , llvm::MachO::CPUTypeARM , 8 },
156 { ArchSpec::eCore_arm_armv7 , llvm::MachO::CPUTypeARM , 9 },
Greg Claytonded470d2011-03-19 01:12:21 +0000157 { ArchSpec::eCore_arm_armv7f , llvm::MachO::CPUTypeARM , 10 },
158 { ArchSpec::eCore_arm_armv7k , llvm::MachO::CPUTypeARM , 12 },
159 { ArchSpec::eCore_arm_armv7s , llvm::MachO::CPUTypeARM , 11 },
Greg Claytonb5c39fe2011-12-16 18:15:52 +0000160 { ArchSpec::eCore_thumb , llvm::MachO::CPUTypeARM , 0 },
161 { ArchSpec::eCore_thumbv4t , llvm::MachO::CPUTypeARM , 5 },
162 { ArchSpec::eCore_thumbv5 , llvm::MachO::CPUTypeARM , 7 },
163 { ArchSpec::eCore_thumbv5e , llvm::MachO::CPUTypeARM , 7 },
164 { ArchSpec::eCore_thumbv6 , llvm::MachO::CPUTypeARM , 6 },
165 { ArchSpec::eCore_thumbv7 , llvm::MachO::CPUTypeARM , 9 },
166 { ArchSpec::eCore_thumbv7f , llvm::MachO::CPUTypeARM , 10 },
167 { ArchSpec::eCore_thumbv7k , llvm::MachO::CPUTypeARM , 12 },
168 { ArchSpec::eCore_thumbv7s , llvm::MachO::CPUTypeARM , 11 },
Greg Clayton64195a22011-02-23 00:35:02 +0000169 { ArchSpec::eCore_ppc_generic , llvm::MachO::CPUTypePowerPC , CPU_ANY },
170 { ArchSpec::eCore_ppc_generic , llvm::MachO::CPUTypePowerPC , 0 },
171 { ArchSpec::eCore_ppc_ppc601 , llvm::MachO::CPUTypePowerPC , 1 },
172 { ArchSpec::eCore_ppc_ppc602 , llvm::MachO::CPUTypePowerPC , 2 },
173 { ArchSpec::eCore_ppc_ppc603 , llvm::MachO::CPUTypePowerPC , 3 },
174 { ArchSpec::eCore_ppc_ppc603e , llvm::MachO::CPUTypePowerPC , 4 },
175 { ArchSpec::eCore_ppc_ppc603ev , llvm::MachO::CPUTypePowerPC , 5 },
176 { ArchSpec::eCore_ppc_ppc604 , llvm::MachO::CPUTypePowerPC , 6 },
177 { ArchSpec::eCore_ppc_ppc604e , llvm::MachO::CPUTypePowerPC , 7 },
178 { ArchSpec::eCore_ppc_ppc620 , llvm::MachO::CPUTypePowerPC , 8 },
179 { ArchSpec::eCore_ppc_ppc750 , llvm::MachO::CPUTypePowerPC , 9 },
180 { ArchSpec::eCore_ppc_ppc7400 , llvm::MachO::CPUTypePowerPC , 10 },
181 { ArchSpec::eCore_ppc_ppc7450 , llvm::MachO::CPUTypePowerPC , 11 },
182 { ArchSpec::eCore_ppc_ppc970 , llvm::MachO::CPUTypePowerPC , 100 },
183 { ArchSpec::eCore_ppc64_generic , llvm::MachO::CPUTypePowerPC64 , 0 },
184 { ArchSpec::eCore_ppc64_ppc970_64 , llvm::MachO::CPUTypePowerPC64 , 100 },
185 { ArchSpec::eCore_x86_32_i386 , llvm::MachO::CPUTypeI386 , 3 },
186 { ArchSpec::eCore_x86_32_i486 , llvm::MachO::CPUTypeI386 , 4 },
187 { ArchSpec::eCore_x86_32_i486sx , llvm::MachO::CPUTypeI386 , 0x84 },
188 { ArchSpec::eCore_x86_32_i386 , llvm::MachO::CPUTypeI386 , CPU_ANY },
189 { ArchSpec::eCore_x86_64_x86_64 , llvm::MachO::CPUTypeX86_64 , 3 },
Jason Molenda311186a2011-08-16 01:23:22 +0000190 { ArchSpec::eCore_x86_64_x86_64 , llvm::MachO::CPUTypeX86_64 , 4 },
Greg Clayton64195a22011-02-23 00:35:02 +0000191 { ArchSpec::eCore_x86_64_x86_64 , llvm::MachO::CPUTypeX86_64 , CPU_ANY }
192};
193static const ArchDefinition g_macho_arch_def = {
194 eArchTypeMachO,
195 sizeof(g_macho_arch_entries)/sizeof(g_macho_arch_entries[0]),
196 g_macho_arch_entries,
197 UINT32_MAX, // CPU type mask
198 0x00FFFFFFu, // CPU subtype mask
199 "mach-o"
Greg Clayton41f92322010-06-11 03:25:34 +0000200};
201
Greg Clayton64195a22011-02-23 00:35:02 +0000202//===----------------------------------------------------------------------===//
203// A table that gets searched linearly for matches. This table is used to
204// convert cpu type and subtypes to architecture names, and to convert
205// architecture names to cpu types and subtypes. The ordering is important and
206// allows the precedence to be set when the table is built.
207static const ArchDefinitionEntry g_elf_arch_entries[] =
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208{
Greg Clayton64195a22011-02-23 00:35:02 +0000209 { ArchSpec::eCore_sparc_generic , llvm::ELF::EM_SPARC , LLDB_INVALID_CPUTYPE }, // Sparc
210 { ArchSpec::eCore_x86_32_i386 , llvm::ELF::EM_386 , LLDB_INVALID_CPUTYPE }, // Intel 80386
211 { ArchSpec::eCore_x86_32_i486 , llvm::ELF::EM_486 , LLDB_INVALID_CPUTYPE }, // Intel 486 (deprecated)
212 { ArchSpec::eCore_ppc_generic , llvm::ELF::EM_PPC , LLDB_INVALID_CPUTYPE }, // PowerPC
213 { ArchSpec::eCore_ppc64_generic , llvm::ELF::EM_PPC64 , LLDB_INVALID_CPUTYPE }, // PowerPC64
214 { ArchSpec::eCore_arm_generic , llvm::ELF::EM_ARM , LLDB_INVALID_CPUTYPE }, // ARM
Greg Clayton64195a22011-02-23 00:35:02 +0000215 { ArchSpec::eCore_sparc9_generic , llvm::ELF::EM_SPARCV9, LLDB_INVALID_CPUTYPE }, // SPARC V9
216 { ArchSpec::eCore_x86_64_x86_64 , llvm::ELF::EM_X86_64 , LLDB_INVALID_CPUTYPE }, // AMD64
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000217};
218
Greg Clayton64195a22011-02-23 00:35:02 +0000219static const ArchDefinition g_elf_arch_def = {
220 eArchTypeELF,
221 sizeof(g_elf_arch_entries)/sizeof(g_elf_arch_entries[0]),
222 g_elf_arch_entries,
223 UINT32_MAX, // CPU type mask
224 UINT32_MAX, // CPU subtype mask
225 "elf",
Greg Clayton41f92322010-06-11 03:25:34 +0000226};
227
Greg Clayton64195a22011-02-23 00:35:02 +0000228//===----------------------------------------------------------------------===//
229// Table of all ArchDefinitions
230static const ArchDefinition *g_arch_definitions[] = {
231 &g_macho_arch_def,
232 &g_elf_arch_def,
233};
Greg Clayton41f92322010-06-11 03:25:34 +0000234
Greg Clayton64195a22011-02-23 00:35:02 +0000235static const size_t k_num_arch_definitions =
236 sizeof(g_arch_definitions) / sizeof(g_arch_definitions[0]);
237
238//===----------------------------------------------------------------------===//
239// Static helper functions.
240
241
242// Get the architecture definition for a given object type.
243static const ArchDefinition *
244FindArchDefinition (ArchitectureType arch_type)
245{
246 for (unsigned int i = 0; i < k_num_arch_definitions; ++i)
247 {
248 const ArchDefinition *def = g_arch_definitions[i];
249 if (def->type == arch_type)
250 return def;
251 }
252 return NULL;
253}
254
255// Get an architecture definition by name.
256static const CoreDefinition *
257FindCoreDefinition (llvm::StringRef name)
258{
259 for (unsigned int i = 0; i < ArchSpec::kNumCores; ++i)
260 {
261 if (name.equals_lower(g_core_definitions[i].name))
262 return &g_core_definitions[i];
263 }
264 return NULL;
265}
266
267static inline const CoreDefinition *
268FindCoreDefinition (ArchSpec::Core core)
269{
270 if (core >= 0 && core < ArchSpec::kNumCores)
271 return &g_core_definitions[core];
272 return NULL;
273}
274
275// Get a definition entry by cpu type and subtype.
276static const ArchDefinitionEntry *
277FindArchDefinitionEntry (const ArchDefinition *def, uint32_t cpu, uint32_t sub)
278{
279 if (def == NULL)
280 return NULL;
281
282 const uint32_t cpu_mask = def->cpu_mask;
283 const uint32_t sub_mask = def->sub_mask;
284 const ArchDefinitionEntry *entries = def->entries;
285 for (size_t i = 0; i < def->num_entries; ++i)
286 {
287 if ((entries[i].cpu == (cpu_mask & cpu)) &&
288 (entries[i].sub == (sub_mask & sub)))
289 return &entries[i];
290 }
291 return NULL;
292}
293
294static const ArchDefinitionEntry *
295FindArchDefinitionEntry (const ArchDefinition *def, ArchSpec::Core core)
296{
297 if (def == NULL)
298 return NULL;
299
300 const ArchDefinitionEntry *entries = def->entries;
301 for (size_t i = 0; i < def->num_entries; ++i)
302 {
303 if (entries[i].core == core)
304 return &entries[i];
305 }
306 return NULL;
307}
308
309//===----------------------------------------------------------------------===//
310// Constructors and destructors.
311
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000312ArchSpec::ArchSpec() :
Greg Clayton514487e2011-02-15 21:59:32 +0000313 m_triple (),
Greg Clayton64195a22011-02-23 00:35:02 +0000314 m_core (kCore_invalid),
315 m_byte_order (eByteOrderInvalid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000316{
317}
318
Greg Claytoneb0103f2011-04-07 22:46:35 +0000319ArchSpec::ArchSpec (const char *triple_cstr, Platform *platform) :
Greg Clayton514487e2011-02-15 21:59:32 +0000320 m_triple (),
Greg Clayton64195a22011-02-23 00:35:02 +0000321 m_core (kCore_invalid),
322 m_byte_order (eByteOrderInvalid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000323{
Greg Clayton64195a22011-02-23 00:35:02 +0000324 if (triple_cstr)
Greg Claytoneb0103f2011-04-07 22:46:35 +0000325 SetTriple(triple_cstr, platform);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000326}
327
Greg Clayton70512312012-05-08 01:45:38 +0000328
329ArchSpec::ArchSpec (const char *triple_cstr) :
330 m_triple (),
331 m_core (kCore_invalid),
332 m_byte_order (eByteOrderInvalid)
333{
334 if (triple_cstr)
335 SetTriple(triple_cstr);
336}
337
Greg Clayton64195a22011-02-23 00:35:02 +0000338ArchSpec::ArchSpec(const llvm::Triple &triple) :
Greg Clayton514487e2011-02-15 21:59:32 +0000339 m_triple (),
Greg Clayton64195a22011-02-23 00:35:02 +0000340 m_core (kCore_invalid),
341 m_byte_order (eByteOrderInvalid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000342{
Greg Clayton64195a22011-02-23 00:35:02 +0000343 SetTriple(triple);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000344}
345
Greg Claytone0d378b2011-03-24 21:19:54 +0000346ArchSpec::ArchSpec (ArchitectureType arch_type, uint32_t cpu, uint32_t subtype) :
Greg Clayton64195a22011-02-23 00:35:02 +0000347 m_triple (),
348 m_core (kCore_invalid),
349 m_byte_order (eByteOrderInvalid)
350{
351 SetArchitecture (arch_type, cpu, subtype);
352}
353
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000354ArchSpec::~ArchSpec()
355{
356}
357
Greg Clayton64195a22011-02-23 00:35:02 +0000358//===----------------------------------------------------------------------===//
359// Assignment and initialization.
360
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000361const ArchSpec&
362ArchSpec::operator= (const ArchSpec& rhs)
363{
364 if (this != &rhs)
365 {
Greg Clayton514487e2011-02-15 21:59:32 +0000366 m_triple = rhs.m_triple;
Greg Clayton64195a22011-02-23 00:35:02 +0000367 m_core = rhs.m_core;
Greg Clayton514487e2011-02-15 21:59:32 +0000368 m_byte_order = rhs.m_byte_order;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000369 }
370 return *this;
371}
372
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373void
374ArchSpec::Clear()
375{
Greg Clayton514487e2011-02-15 21:59:32 +0000376 m_triple = llvm::Triple();
Greg Clayton64195a22011-02-23 00:35:02 +0000377 m_core = kCore_invalid;
378 m_byte_order = eByteOrderInvalid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379}
380
Greg Clayton64195a22011-02-23 00:35:02 +0000381//===----------------------------------------------------------------------===//
382// Predicates.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383
Greg Clayton41f92322010-06-11 03:25:34 +0000384
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000385const char *
Greg Clayton64195a22011-02-23 00:35:02 +0000386ArchSpec::GetArchitectureName () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000387{
Greg Clayton64195a22011-02-23 00:35:02 +0000388 const CoreDefinition *core_def = FindCoreDefinition (m_core);
389 if (core_def)
390 return core_def->name;
391 return "unknown";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392}
393
Greg Clayton64195a22011-02-23 00:35:02 +0000394uint32_t
395ArchSpec::GetMachOCPUType () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000396{
Greg Clayton64195a22011-02-23 00:35:02 +0000397 const CoreDefinition *core_def = FindCoreDefinition (m_core);
398 if (core_def)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000399 {
Greg Clayton64195a22011-02-23 00:35:02 +0000400 const ArchDefinitionEntry *arch_def = FindArchDefinitionEntry (&g_macho_arch_def, core_def->core);
401 if (arch_def)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000402 {
Greg Clayton64195a22011-02-23 00:35:02 +0000403 return arch_def->cpu;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000404 }
405 }
Greg Clayton64195a22011-02-23 00:35:02 +0000406 return LLDB_INVALID_CPUTYPE;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407}
408
Greg Clayton64195a22011-02-23 00:35:02 +0000409uint32_t
410ArchSpec::GetMachOCPUSubType () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411{
Greg Clayton64195a22011-02-23 00:35:02 +0000412 const CoreDefinition *core_def = FindCoreDefinition (m_core);
413 if (core_def)
414 {
415 const ArchDefinitionEntry *arch_def = FindArchDefinitionEntry (&g_macho_arch_def, core_def->core);
416 if (arch_def)
417 {
Greg Clayton1cb64962011-03-24 04:28:38 +0000418 return arch_def->sub;
Greg Clayton64195a22011-02-23 00:35:02 +0000419 }
420 }
421 return LLDB_INVALID_CPUTYPE;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000422}
423
Greg Clayton64195a22011-02-23 00:35:02 +0000424llvm::Triple::ArchType
425ArchSpec::GetMachine () const
426{
427 const CoreDefinition *core_def = FindCoreDefinition (m_core);
428 if (core_def)
429 return core_def->machine;
430
431 return llvm::Triple::UnknownArch;
432}
433
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434uint32_t
435ArchSpec::GetAddressByteSize() const
436{
Greg Clayton64195a22011-02-23 00:35:02 +0000437 const CoreDefinition *core_def = FindCoreDefinition (m_core);
438 if (core_def)
439 return core_def->addr_byte_size;
Greg Clayton41f92322010-06-11 03:25:34 +0000440 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441}
442
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000443ByteOrder
444ArchSpec::GetDefaultEndian () const
445{
Greg Clayton64195a22011-02-23 00:35:02 +0000446 const CoreDefinition *core_def = FindCoreDefinition (m_core);
447 if (core_def)
448 return core_def->default_byte_order;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000449 return eByteOrderInvalid;
450}
451
Greg Clayton64195a22011-02-23 00:35:02 +0000452lldb::ByteOrder
453ArchSpec::GetByteOrder () const
454{
455 if (m_byte_order == eByteOrderInvalid)
456 return GetDefaultEndian();
457 return m_byte_order;
458}
459
460//===----------------------------------------------------------------------===//
461// Mutators.
462
463bool
464ArchSpec::SetTriple (const llvm::Triple &triple)
465{
466 m_triple = triple;
467
468 llvm::StringRef arch_name (m_triple.getArchName());
469 const CoreDefinition *core_def = FindCoreDefinition (arch_name);
470 if (core_def)
471 {
472 m_core = core_def->core;
Greg Claytoneb0103f2011-04-07 22:46:35 +0000473 // Set the byte order to the default byte order for an architecture.
474 // This can be modified if needed for cases when cores handle both
475 // big and little endian
476 m_byte_order = core_def->default_byte_order;
Greg Clayton64195a22011-02-23 00:35:02 +0000477 }
478 else
479 {
480 Clear();
481 }
482
483
484 return IsValid();
485}
486
487bool
Greg Clayton70512312012-05-08 01:45:38 +0000488ArchSpec::SetTriple (const char *triple_cstr)
Greg Clayton64195a22011-02-23 00:35:02 +0000489{
Greg Clayton23aca092011-08-12 23:32:52 +0000490 if (triple_cstr && triple_cstr[0])
Greg Clayton64195a22011-02-23 00:35:02 +0000491 {
Greg Claytone795f1b2012-08-08 01:19:34 +0000492 if (isdigit(triple_cstr[0]))
493 {
494 // Accept "12-10" or "12.10" as cpu type/subtype
495 char *end = NULL;
Jason Molendadfa424c2012-09-18 23:27:18 +0000496 errno = 0;
Greg Claytone795f1b2012-08-08 01:19:34 +0000497 uint32_t cpu = ::strtoul (triple_cstr, &end, 0);
Jason Molendadfa424c2012-09-18 23:27:18 +0000498 if (errno == 0 && cpu != 0 && end && ((*end == '-') || (*end == '.')))
Greg Claytone795f1b2012-08-08 01:19:34 +0000499 {
Jason Molendadfa424c2012-09-18 23:27:18 +0000500 errno = 0;
Greg Claytone795f1b2012-08-08 01:19:34 +0000501 uint32_t sub = ::strtoul (end + 1, &end, 0);
Jason Molendadfa424c2012-09-18 23:27:18 +0000502 if (errno == 0 && end && ((*end == '-') || (*end == '.') || (*end == '\0')))
Greg Claytone795f1b2012-08-08 01:19:34 +0000503 {
504 if (SetArchitecture (eArchTypeMachO, cpu, sub))
505 {
506 if (*end == '-')
507 {
508 llvm::StringRef vendor_os (end + 1);
509 size_t dash_pos = vendor_os.find('-');
510 if (dash_pos != llvm::StringRef::npos)
511 {
512 llvm::StringRef vendor_str(vendor_os.substr(0, dash_pos));
513 m_triple.setVendorName(vendor_str);
514 const size_t vendor_start_pos = dash_pos+1;
515 dash_pos = vendor_os.find(vendor_start_pos, '-');
516 if (dash_pos == llvm::StringRef::npos)
517 {
518 if (vendor_start_pos < vendor_os.size())
519 m_triple.setOSName(vendor_os.substr(vendor_start_pos));
520 }
521 else
522 {
523 m_triple.setOSName(vendor_os.substr(vendor_start_pos, dash_pos - vendor_start_pos));
524 }
525 }
526 }
527 return true;
528 }
529 }
530 }
531 }
Greg Clayton64195a22011-02-23 00:35:02 +0000532 llvm::StringRef triple_stref (triple_cstr);
533 if (triple_stref.startswith (LLDB_ARCH_DEFAULT))
534 {
535 // Special case for the current host default architectures...
536 if (triple_stref.equals (LLDB_ARCH_DEFAULT_32BIT))
537 *this = Host::GetArchitecture (Host::eSystemDefaultArchitecture32);
538 else if (triple_stref.equals (LLDB_ARCH_DEFAULT_64BIT))
539 *this = Host::GetArchitecture (Host::eSystemDefaultArchitecture64);
540 else if (triple_stref.equals (LLDB_ARCH_DEFAULT))
541 *this = Host::GetArchitecture (Host::eSystemDefaultArchitecture);
542 }
543 else
544 {
545 std::string normalized_triple_sstr (llvm::Triple::normalize(triple_stref));
546 triple_stref = normalized_triple_sstr;
Greg Clayton70512312012-05-08 01:45:38 +0000547 SetTriple (llvm::Triple (triple_stref));
548 }
549 }
550 else
551 Clear();
552 return IsValid();
553}
554
555bool
556ArchSpec::SetTriple (const char *triple_cstr, Platform *platform)
557{
558 if (triple_cstr && triple_cstr[0])
559 {
560 llvm::StringRef triple_stref (triple_cstr);
561 if (triple_stref.startswith (LLDB_ARCH_DEFAULT))
562 {
563 // Special case for the current host default architectures...
564 if (triple_stref.equals (LLDB_ARCH_DEFAULT_32BIT))
565 *this = Host::GetArchitecture (Host::eSystemDefaultArchitecture32);
566 else if (triple_stref.equals (LLDB_ARCH_DEFAULT_64BIT))
567 *this = Host::GetArchitecture (Host::eSystemDefaultArchitecture64);
568 else if (triple_stref.equals (LLDB_ARCH_DEFAULT))
569 *this = Host::GetArchitecture (Host::eSystemDefaultArchitecture);
570 }
571 else
572 {
573 ArchSpec raw_arch (triple_cstr);
574
575 std::string normalized_triple_sstr (llvm::Triple::normalize(triple_stref));
576 triple_stref = normalized_triple_sstr;
Greg Claytoneb0103f2011-04-07 22:46:35 +0000577 llvm::Triple normalized_triple (triple_stref);
578
579 const bool os_specified = normalized_triple.getOSName().size() > 0;
580 const bool vendor_specified = normalized_triple.getVendorName().size() > 0;
581 const bool env_specified = normalized_triple.getEnvironmentName().size() > 0;
582
583 // If we got an arch only, then default the vendor, os, environment
584 // to match the platform if one is supplied
585 if (!(os_specified || vendor_specified || env_specified))
586 {
587 if (platform)
588 {
589 // If we were given a platform, use the platform's system
590 // architecture. If this is not available (might not be
591 // connected) use the first supported architecture.
Greg Clayton70512312012-05-08 01:45:38 +0000592 ArchSpec compatible_arch;
593 if (platform->IsCompatibleArchitecture (raw_arch, &compatible_arch))
Greg Claytoneb0103f2011-04-07 22:46:35 +0000594 {
Greg Clayton70512312012-05-08 01:45:38 +0000595 if (compatible_arch.IsValid())
596 {
597 const llvm::Triple &compatible_triple = compatible_arch.GetTriple();
598 if (!vendor_specified)
599 normalized_triple.setVendor(compatible_triple.getVendor());
600 if (!os_specified)
601 normalized_triple.setOS(compatible_triple.getOS());
602 if (!env_specified && compatible_triple.getEnvironmentName().size())
603 normalized_triple.setEnvironment(compatible_triple.getEnvironment());
604 }
Greg Claytoneb0103f2011-04-07 22:46:35 +0000605 }
Greg Clayton70512312012-05-08 01:45:38 +0000606 else
Greg Claytoneb0103f2011-04-07 22:46:35 +0000607 {
Greg Clayton70512312012-05-08 01:45:38 +0000608 *this = raw_arch;
609 return IsValid();
Greg Claytoneb0103f2011-04-07 22:46:35 +0000610 }
611 }
612 else
613 {
614 // No platform specified, fall back to the host system for
615 // the default vendor, os, and environment.
Sean Callananbfb237bc2011-11-04 22:46:46 +0000616 llvm::Triple host_triple(llvm::sys::getDefaultTargetTriple());
Greg Clayton70512312012-05-08 01:45:38 +0000617 if (!vendor_specified)
618 normalized_triple.setVendor(host_triple.getVendor());
619 if (!vendor_specified)
620 normalized_triple.setOS(host_triple.getOS());
621 if (!env_specified && host_triple.getEnvironmentName().size())
622 normalized_triple.setEnvironment(host_triple.getEnvironment());
Greg Claytoneb0103f2011-04-07 22:46:35 +0000623 }
624 }
625 SetTriple (normalized_triple);
Greg Clayton64195a22011-02-23 00:35:02 +0000626 }
627 }
628 else
629 Clear();
630 return IsValid();
631}
632
Greg Clayton64195a22011-02-23 00:35:02 +0000633bool
Greg Claytone0d378b2011-03-24 21:19:54 +0000634ArchSpec::SetArchitecture (ArchitectureType arch_type, uint32_t cpu, uint32_t sub)
Greg Clayton64195a22011-02-23 00:35:02 +0000635{
636 m_core = kCore_invalid;
637 bool update_triple = true;
638 const ArchDefinition *arch_def = FindArchDefinition(arch_type);
639 if (arch_def)
640 {
641 const ArchDefinitionEntry *arch_def_entry = FindArchDefinitionEntry (arch_def, cpu, sub);
642 if (arch_def_entry)
643 {
644 const CoreDefinition *core_def = FindCoreDefinition (arch_def_entry->core);
645 if (core_def)
646 {
647 m_core = core_def->core;
648 update_triple = false;
Greg Clayton593577a2011-09-21 03:57:31 +0000649 // Always use the architecture name because it might be more descriptive
650 // than the architecture enum ("armv7" -> llvm::Triple::arm).
651 m_triple.setArchName(llvm::StringRef(core_def->name));
Greg Clayton64195a22011-02-23 00:35:02 +0000652 if (arch_type == eArchTypeMachO)
653 {
654 m_triple.setVendor (llvm::Triple::Apple);
Greg Clayton70512312012-05-08 01:45:38 +0000655
656 switch (core_def->machine)
657 {
658 case llvm::Triple::arm:
659 case llvm::Triple::thumb:
660 m_triple.setOS (llvm::Triple::IOS);
661 break;
662
663 case llvm::Triple::x86:
664 case llvm::Triple::x86_64:
665 default:
666 m_triple.setOS (llvm::Triple::MacOSX);
667 break;
668 }
Greg Clayton64195a22011-02-23 00:35:02 +0000669 }
670 else
671 {
672 m_triple.setVendor (llvm::Triple::UnknownVendor);
673 m_triple.setOS (llvm::Triple::UnknownOS);
674 }
Greg Clayton593577a2011-09-21 03:57:31 +0000675 // Fall back onto setting the machine type if the arch by name failed...
676 if (m_triple.getArch () == llvm::Triple::UnknownArch)
677 m_triple.setArch (core_def->machine);
Greg Clayton64195a22011-02-23 00:35:02 +0000678 }
679 }
680 }
681 CoreUpdated(update_triple);
682 return IsValid();
683}
684
Greg Clayton357132e2011-03-26 19:14:58 +0000685uint32_t
686ArchSpec::GetMinimumOpcodeByteSize() const
Greg Clayton64195a22011-02-23 00:35:02 +0000687{
Greg Clayton357132e2011-03-26 19:14:58 +0000688 const CoreDefinition *core_def = FindCoreDefinition (m_core);
689 if (core_def)
690 return core_def->min_opcode_byte_size;
691 return 0;
692}
693
694uint32_t
695ArchSpec::GetMaximumOpcodeByteSize() const
696{
697 const CoreDefinition *core_def = FindCoreDefinition (m_core);
698 if (core_def)
699 return core_def->max_opcode_byte_size;
700 return 0;
Greg Clayton64195a22011-02-23 00:35:02 +0000701}
702
703//===----------------------------------------------------------------------===//
704// Helper methods.
705
706void
707ArchSpec::CoreUpdated (bool update_triple)
708{
709 const CoreDefinition *core_def = FindCoreDefinition (m_core);
710 if (core_def)
711 {
712 if (update_triple)
713 m_triple = llvm::Triple(core_def->name, "unknown", "unknown");
714 m_byte_order = core_def->default_byte_order;
715 }
716 else
717 {
718 if (update_triple)
719 m_triple = llvm::Triple();
720 m_byte_order = eByteOrderInvalid;
721 }
722}
723
724//===----------------------------------------------------------------------===//
725// Operators.
726
Greg Clayton70512312012-05-08 01:45:38 +0000727static bool
728cores_match (const ArchSpec::Core core1, const ArchSpec::Core core2, bool try_inverse)
729{
730 switch (core1)
731 {
732// case ArchSpec::eCore_arm_armv4:
733// try_inverse = false;
734// if (core2 == ArchSpec::eCore_thumb)
735// return true;
736// break;
737//
738// case ArchSpec::eCore_arm_armv4t:
739// try_inverse = false;
740// if (core2 == ArchSpec::eCore_thumbv4t)
741// return true;
742// break;
743//
744// case ArchSpec::eCore_arm_armv5:
745// try_inverse = false;
746// if (core2 == ArchSpec::eCore_thumbv5)
747// return true;
748// break;
749//
750// case ArchSpec::eCore_arm_armv5t:
751// case ArchSpec::eCore_arm_armv5e:
752// try_inverse = false;
753// if (core2 == ArchSpec::eCore_thumbv5e)
754// return true;
755// break;
756//
757// case ArchSpec::eCore_arm_armv6:
758// try_inverse = false;
759// if (core2 == ArchSpec::eCore_thumbv6)
760// return true;
761// break;
762//
763// case ArchSpec::eCore_arm_armv7:
764// try_inverse = false;
765// if (core2 == ArchSpec::eCore_thumbv7)
766// return true;
767// break;
768//
769// case ArchSpec::eCore_arm_armv7f:
770// try_inverse = false;
771// if (core2 == ArchSpec::eCore_thumbv7f)
772// return true;
773// break;
774//
775// case ArchSpec::eCore_arm_armv7k:
776// try_inverse = false;
777// if (core2 == ArchSpec::eCore_thumbv7k)
778// return true;
779// break;
780//
781// case ArchSpec::eCore_arm_armv7s:
782// try_inverse = false;
783// if (core2 == ArchSpec::eCore_thumbv7s)
784// return true;
785// break;
786//
787// case ArchSpec::eCore_thumb:
788// try_inverse = false;
789// if (core2 == ArchSpec::eCore_arm_armv4)
790// return true;
791// break;
792//
793// case ArchSpec::eCore_thumbv4t:
794// try_inverse = false;
795// if (core2 == ArchSpec::eCore_arm_armv4t)
796// return true;
797// break;
798//
799// case ArchSpec::eCore_thumbv5:
800// try_inverse = false;
801// if (core2 == ArchSpec::eCore_arm_armv5)
802// return true;
803// break;
804//
805// case ArchSpec::eCore_thumbv5e:
806// try_inverse = false;
807// if (core2 == ArchSpec::eCore_arm_armv5t || core2 == ArchSpec::eCore_arm_armv5e)
808// return true;
809// break;
810//
811// case ArchSpec::eCore_thumbv6:
812// try_inverse = false;
813// if (core2 == ArchSpec::eCore_arm_armv6)
814// return true;
815// break;
816//
817// case ArchSpec::eCore_thumbv7:
818// try_inverse = false;
819// if (core2 == ArchSpec::eCore_arm_armv7)
820// return true;
821// break;
822//
823// case ArchSpec::eCore_thumbv7f:
824// try_inverse = false;
825// if (core2 == ArchSpec::eCore_arm_armv7f)
826// return true;
827// break;
828//
829// case ArchSpec::eCore_thumbv7k:
830// try_inverse = false;
831// if (core2 == ArchSpec::eCore_arm_armv7k)
832// return true;
833// break;
834//
835// case ArchSpec::eCore_thumbv7s:
836// try_inverse = false;
837// if (core2 == ArchSpec::eCore_arm_armv7s)
838// return true;
839// break;
840
841 case ArchSpec::kCore_any:
842 return true;
843
844 case ArchSpec::kCore_arm_any:
845 if (core2 >= ArchSpec::kCore_arm_first && core2 <= ArchSpec::kCore_arm_last)
846 return true;
847 if (core2 >= ArchSpec::kCore_thumb_first && core2 <= ArchSpec::kCore_thumb_last)
848 return true;
849 if (core2 == ArchSpec::kCore_arm_any)
850 return true;
851 break;
852
853 case ArchSpec::kCore_x86_32_any:
854 if ((core2 >= ArchSpec::kCore_x86_32_first && core2 <= ArchSpec::kCore_x86_32_last) || (core2 == ArchSpec::kCore_x86_32_any))
855 return true;
856 break;
857
858 case ArchSpec::kCore_ppc_any:
859 if ((core2 >= ArchSpec::kCore_ppc_first && core2 <= ArchSpec::kCore_ppc_last) || (core2 == ArchSpec::kCore_ppc_any))
860 return true;
861 break;
862
863 case ArchSpec::kCore_ppc64_any:
864 if ((core2 >= ArchSpec::kCore_ppc64_first && core2 <= ArchSpec::kCore_ppc64_last) || (core2 == ArchSpec::kCore_ppc64_any))
865 return true;
866 break;
867
Johnny Chen1083b0d2012-08-28 22:53:40 +0000868 case ArchSpec::eCore_arm_armv7:
869 case ArchSpec::eCore_arm_armv7f:
870 case ArchSpec::eCore_arm_armv7k:
871 case ArchSpec::eCore_arm_armv7s:
872 try_inverse = false;
873 if (core2 == ArchSpec::eCore_arm_armv7)
874 return true;
875 break;
876
Greg Clayton70512312012-05-08 01:45:38 +0000877 default:
878 break;
879 }
880 if (try_inverse)
881 return cores_match (core2, core1, false);
882 return false;
883}
884
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000885bool
886lldb_private::operator== (const ArchSpec& lhs, const ArchSpec& rhs)
887{
Jim Ingham4d9695a2011-09-15 01:07:30 +0000888 if (lhs.GetByteOrder() != rhs.GetByteOrder())
889 return false;
890
Greg Clayton64195a22011-02-23 00:35:02 +0000891 const ArchSpec::Core lhs_core = lhs.GetCore ();
892 const ArchSpec::Core rhs_core = rhs.GetCore ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000893
Greg Clayton70512312012-05-08 01:45:38 +0000894 // Check if the cores match, or check a little closer watching for wildcard
895 // and equivalent cores
896 const bool core_match = (lhs_core == rhs_core) || cores_match (lhs_core, rhs_core, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000897
Greg Clayton70512312012-05-08 01:45:38 +0000898 if (core_match)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000899 {
Jim Ingham4d9695a2011-09-15 01:07:30 +0000900 const llvm::Triple &lhs_triple = lhs.GetTriple();
901 const llvm::Triple &rhs_triple = rhs.GetTriple();
Greg Clayton593577a2011-09-21 03:57:31 +0000902
903 const llvm::Triple::VendorType lhs_triple_vendor = lhs_triple.getVendor();
904 const llvm::Triple::VendorType rhs_triple_vendor = rhs_triple.getVendor();
905 if (lhs_triple_vendor != rhs_triple_vendor)
906 {
Greg Clayton70512312012-05-08 01:45:38 +0000907 const bool rhs_vendor_specified = rhs.TripleVendorWasSpecified();
908 const bool lhs_vendor_specified = lhs.TripleVendorWasSpecified();
909 // Both architectures had the vendor specified, so if they aren't
910 // equal then we return false
911 if (rhs_vendor_specified && lhs_vendor_specified)
912 return false;
913
Greg Clayton593577a2011-09-21 03:57:31 +0000914 // Only fail if both vendor types are not unknown
915 if (lhs_triple_vendor != llvm::Triple::UnknownVendor &&
916 rhs_triple_vendor != llvm::Triple::UnknownVendor)
917 return false;
918 }
919
920 const llvm::Triple::OSType lhs_triple_os = lhs_triple.getOS();
921 const llvm::Triple::OSType rhs_triple_os = rhs_triple.getOS();
922 if (lhs_triple_os != rhs_triple_os)
923 {
Greg Clayton70512312012-05-08 01:45:38 +0000924 const bool rhs_os_specified = rhs.TripleOSWasSpecified();
925 const bool lhs_os_specified = lhs.TripleOSWasSpecified();
926 // Both architectures had the OS specified, so if they aren't
927 // equal then we return false
928 if (rhs_os_specified && lhs_os_specified)
929 return false;
Greg Clayton593577a2011-09-21 03:57:31 +0000930 // Only fail if both os types are not unknown
931 if (lhs_triple_os != llvm::Triple::UnknownOS &&
932 rhs_triple_os != llvm::Triple::UnknownOS)
933 return false;
934 }
935
936 const llvm::Triple::EnvironmentType lhs_triple_env = lhs_triple.getEnvironment();
937 const llvm::Triple::EnvironmentType rhs_triple_env = rhs_triple.getEnvironment();
938
939 if (lhs_triple_env != rhs_triple_env)
940 {
941 // Only fail if both environment types are not unknown
942 if (lhs_triple_env != llvm::Triple::UnknownEnvironment &&
943 rhs_triple_env != llvm::Triple::UnknownEnvironment)
944 return false;
945 }
946 return true;
Greg Clayton64195a22011-02-23 00:35:02 +0000947 }
Greg Clayton70512312012-05-08 01:45:38 +0000948 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000949}
950
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000951bool
952lldb_private::operator!= (const ArchSpec& lhs, const ArchSpec& rhs)
953{
954 return !(lhs == rhs);
955}
956
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000957bool
958lldb_private::operator<(const ArchSpec& lhs, const ArchSpec& rhs)
959{
Greg Clayton64195a22011-02-23 00:35:02 +0000960 const ArchSpec::Core lhs_core = lhs.GetCore ();
961 const ArchSpec::Core rhs_core = rhs.GetCore ();
962 return lhs_core < rhs_core;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000963}