blob: a4eafb4d227d64f64ac8fb0a10436fcc3a966bc0 [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>
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013
14#include <string>
15
Greg Clayton41f92322010-06-11 03:25:34 +000016#include "llvm/Support/ELF.h"
Stephen Wilsonfacebfc2011-02-24 19:13:58 +000017#include "llvm/Support/Host.h"
Greg Clayton41f92322010-06-11 03:25:34 +000018#include "llvm/Support/MachO.h"
Greg Claytone795f1b2012-08-08 01:19:34 +000019#include "lldb/Core/RegularExpression.h"
Greg Clayton514487e2011-02-15 21:59:32 +000020#include "lldb/Host/Endian.h"
21#include "lldb/Host/Host.h"
Greg Claytoneb0103f2011-04-07 22:46:35 +000022#include "lldb/Target/Platform.h"
Greg Clayton41f92322010-06-11 03:25:34 +000023
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024using namespace lldb;
25using namespace lldb_private;
26
Greg Clayton64195a22011-02-23 00:35:02 +000027#define ARCH_SPEC_SEPARATOR_CHAR '-'
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028
Greg Clayton64195a22011-02-23 00:35:02 +000029namespace lldb_private {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030
Greg Clayton64195a22011-02-23 00:35:02 +000031 struct CoreDefinition
32 {
33 ByteOrder default_byte_order;
34 uint32_t addr_byte_size;
Greg Clayton357132e2011-03-26 19:14:58 +000035 uint32_t min_opcode_byte_size;
36 uint32_t max_opcode_byte_size;
Greg Clayton64195a22011-02-23 00:35:02 +000037 llvm::Triple::ArchType machine;
38 ArchSpec::Core core;
39 const char *name;
40 };
41
42}
43
44// This core information can be looked using the ArchSpec::Core as the index
45static const CoreDefinition g_core_definitions[ArchSpec::kNumCores] =
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046{
Greg Clayton357132e2011-03-26 19:14:58 +000047 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_generic , "arm" },
48 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv4 , "armv4" },
49 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv4t , "armv4t" },
50 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv5 , "armv5" },
Greg Claytonb5c39fe2011-12-16 18:15:52 +000051 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv5e , "armv5e" },
Greg Clayton357132e2011-03-26 19:14:58 +000052 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv5t , "armv5t" },
53 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv6 , "armv6" },
54 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7 , "armv7" },
55 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7f , "armv7f" },
56 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7k , "armv7k" },
57 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7s , "armv7s" },
58 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_xscale , "xscale" },
Greg Claytonb5c39fe2011-12-16 18:15:52 +000059 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumb , "thumb" },
60 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv4t , "thumbv4t" },
61 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv5 , "thumbv5" },
62 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv5e , "thumbv5e" },
63 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv6 , "thumbv6" },
64 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7 , "thumbv7" },
65 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7f , "thumbv7f" },
66 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7k , "thumbv7k" },
67 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7s , "thumbv7s" },
68
Greg Clayton64195a22011-02-23 00:35:02 +000069
Greg Clayton357132e2011-03-26 19:14:58 +000070 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_generic , "ppc" },
71 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc601 , "ppc601" },
72 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc602 , "ppc602" },
73 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc603 , "ppc603" },
74 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc603e , "ppc603e" },
75 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc603ev , "ppc603ev" },
76 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc604 , "ppc604" },
77 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc604e , "ppc604e" },
78 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc620 , "ppc620" },
79 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc750 , "ppc750" },
80 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc7400 , "ppc7400" },
81 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc7450 , "ppc7450" },
82 { eByteOrderLittle, 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc970 , "ppc970" },
Greg Clayton64195a22011-02-23 00:35:02 +000083
Greg Clayton357132e2011-03-26 19:14:58 +000084 { eByteOrderLittle, 8, 4, 4, llvm::Triple::ppc64 , ArchSpec::eCore_ppc64_generic , "ppc64" },
85 { eByteOrderLittle, 8, 4, 4, llvm::Triple::ppc64 , ArchSpec::eCore_ppc64_ppc970_64 , "ppc970-64" },
Greg Clayton64195a22011-02-23 00:35:02 +000086
Greg Clayton357132e2011-03-26 19:14:58 +000087 { eByteOrderLittle, 4, 4, 4, llvm::Triple::sparc , ArchSpec::eCore_sparc_generic , "sparc" },
88 { eByteOrderLittle, 8, 4, 4, llvm::Triple::sparcv9, ArchSpec::eCore_sparc9_generic , "sparcv9" },
Greg Clayton64195a22011-02-23 00:35:02 +000089
Greg Claytonab65b342011-04-13 22:47:15 +000090 { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i386 , "i386" },
91 { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i486 , "i486" },
92 { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i486sx , "i486sx" },
Greg Clayton64195a22011-02-23 00:35:02 +000093
Greg Claytonab65b342011-04-13 22:47:15 +000094 { eByteOrderLittle, 8, 1, 15, llvm::Triple::x86_64 , ArchSpec::eCore_x86_64_x86_64 , "x86_64" }
Greg Clayton64195a22011-02-23 00:35:02 +000095};
96
97struct ArchDefinitionEntry
98{
99 ArchSpec::Core core;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000100 uint32_t cpu;
101 uint32_t sub;
Greg Clayton64195a22011-02-23 00:35:02 +0000102};
103
104struct ArchDefinition
105{
106 ArchitectureType type;
107 size_t num_entries;
108 const ArchDefinitionEntry *entries;
109 uint32_t cpu_mask;
110 uint32_t sub_mask;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111 const char *name;
112};
113
Greg Clayton41f92322010-06-11 03:25:34 +0000114
Greg Claytonab65b342011-04-13 22:47:15 +0000115uint32_t
116ArchSpec::AutoComplete (const char *name, StringList &matches)
117{
118 uint32_t i;
119 if (name && name[0])
120 {
121 for (i = 0; i < ArchSpec::kNumCores; ++i)
122 {
123 if (NameMatches(g_core_definitions[i].name, eNameMatchStartsWith, name))
124 matches.AppendString (g_core_definitions[i].name);
125 }
126 }
127 else
128 {
129 for (i = 0; i < ArchSpec::kNumCores; ++i)
130 matches.AppendString (g_core_definitions[i].name);
131 }
132 return matches.GetSize();
133}
134
135
136
Greg Clayton64195a22011-02-23 00:35:02 +0000137#define CPU_ANY (UINT32_MAX)
138
139//===----------------------------------------------------------------------===//
140// A table that gets searched linearly for matches. This table is used to
141// convert cpu type and subtypes to architecture names, and to convert
142// architecture names to cpu types and subtypes. The ordering is important and
143// allows the precedence to be set when the table is built.
144static const ArchDefinitionEntry g_macho_arch_entries[] =
Greg Clayton41f92322010-06-11 03:25:34 +0000145{
Greg Clayton64195a22011-02-23 00:35:02 +0000146 { ArchSpec::eCore_arm_generic , llvm::MachO::CPUTypeARM , CPU_ANY },
147 { ArchSpec::eCore_arm_generic , llvm::MachO::CPUTypeARM , 0 },
148 { ArchSpec::eCore_arm_armv4 , llvm::MachO::CPUTypeARM , 5 },
Greg Claytonb5c39fe2011-12-16 18:15:52 +0000149 { ArchSpec::eCore_arm_armv4t , llvm::MachO::CPUTypeARM , 5 },
Greg Clayton64195a22011-02-23 00:35:02 +0000150 { ArchSpec::eCore_arm_armv6 , llvm::MachO::CPUTypeARM , 6 },
151 { ArchSpec::eCore_arm_armv5 , llvm::MachO::CPUTypeARM , 7 },
Greg Claytonb5c39fe2011-12-16 18:15:52 +0000152 { ArchSpec::eCore_arm_armv5e , llvm::MachO::CPUTypeARM , 7 },
153 { ArchSpec::eCore_arm_armv5t , llvm::MachO::CPUTypeARM , 7 },
Greg Clayton64195a22011-02-23 00:35:02 +0000154 { ArchSpec::eCore_arm_xscale , llvm::MachO::CPUTypeARM , 8 },
155 { ArchSpec::eCore_arm_armv7 , llvm::MachO::CPUTypeARM , 9 },
Greg Claytonded470d2011-03-19 01:12:21 +0000156 { ArchSpec::eCore_arm_armv7f , llvm::MachO::CPUTypeARM , 10 },
157 { ArchSpec::eCore_arm_armv7k , llvm::MachO::CPUTypeARM , 12 },
158 { ArchSpec::eCore_arm_armv7s , llvm::MachO::CPUTypeARM , 11 },
Greg Claytonb5c39fe2011-12-16 18:15:52 +0000159 { ArchSpec::eCore_thumb , llvm::MachO::CPUTypeARM , 0 },
160 { ArchSpec::eCore_thumbv4t , llvm::MachO::CPUTypeARM , 5 },
161 { ArchSpec::eCore_thumbv5 , llvm::MachO::CPUTypeARM , 7 },
162 { ArchSpec::eCore_thumbv5e , llvm::MachO::CPUTypeARM , 7 },
163 { ArchSpec::eCore_thumbv6 , llvm::MachO::CPUTypeARM , 6 },
164 { ArchSpec::eCore_thumbv7 , llvm::MachO::CPUTypeARM , 9 },
165 { ArchSpec::eCore_thumbv7f , llvm::MachO::CPUTypeARM , 10 },
166 { ArchSpec::eCore_thumbv7k , llvm::MachO::CPUTypeARM , 12 },
167 { ArchSpec::eCore_thumbv7s , llvm::MachO::CPUTypeARM , 11 },
Greg Clayton64195a22011-02-23 00:35:02 +0000168 { ArchSpec::eCore_ppc_generic , llvm::MachO::CPUTypePowerPC , CPU_ANY },
169 { ArchSpec::eCore_ppc_generic , llvm::MachO::CPUTypePowerPC , 0 },
170 { ArchSpec::eCore_ppc_ppc601 , llvm::MachO::CPUTypePowerPC , 1 },
171 { ArchSpec::eCore_ppc_ppc602 , llvm::MachO::CPUTypePowerPC , 2 },
172 { ArchSpec::eCore_ppc_ppc603 , llvm::MachO::CPUTypePowerPC , 3 },
173 { ArchSpec::eCore_ppc_ppc603e , llvm::MachO::CPUTypePowerPC , 4 },
174 { ArchSpec::eCore_ppc_ppc603ev , llvm::MachO::CPUTypePowerPC , 5 },
175 { ArchSpec::eCore_ppc_ppc604 , llvm::MachO::CPUTypePowerPC , 6 },
176 { ArchSpec::eCore_ppc_ppc604e , llvm::MachO::CPUTypePowerPC , 7 },
177 { ArchSpec::eCore_ppc_ppc620 , llvm::MachO::CPUTypePowerPC , 8 },
178 { ArchSpec::eCore_ppc_ppc750 , llvm::MachO::CPUTypePowerPC , 9 },
179 { ArchSpec::eCore_ppc_ppc7400 , llvm::MachO::CPUTypePowerPC , 10 },
180 { ArchSpec::eCore_ppc_ppc7450 , llvm::MachO::CPUTypePowerPC , 11 },
181 { ArchSpec::eCore_ppc_ppc970 , llvm::MachO::CPUTypePowerPC , 100 },
182 { ArchSpec::eCore_ppc64_generic , llvm::MachO::CPUTypePowerPC64 , 0 },
183 { ArchSpec::eCore_ppc64_ppc970_64 , llvm::MachO::CPUTypePowerPC64 , 100 },
184 { ArchSpec::eCore_x86_32_i386 , llvm::MachO::CPUTypeI386 , 3 },
185 { ArchSpec::eCore_x86_32_i486 , llvm::MachO::CPUTypeI386 , 4 },
186 { ArchSpec::eCore_x86_32_i486sx , llvm::MachO::CPUTypeI386 , 0x84 },
187 { ArchSpec::eCore_x86_32_i386 , llvm::MachO::CPUTypeI386 , CPU_ANY },
188 { ArchSpec::eCore_x86_64_x86_64 , llvm::MachO::CPUTypeX86_64 , 3 },
Jason Molenda311186a2011-08-16 01:23:22 +0000189 { ArchSpec::eCore_x86_64_x86_64 , llvm::MachO::CPUTypeX86_64 , 4 },
Greg Clayton64195a22011-02-23 00:35:02 +0000190 { ArchSpec::eCore_x86_64_x86_64 , llvm::MachO::CPUTypeX86_64 , CPU_ANY }
191};
192static const ArchDefinition g_macho_arch_def = {
193 eArchTypeMachO,
194 sizeof(g_macho_arch_entries)/sizeof(g_macho_arch_entries[0]),
195 g_macho_arch_entries,
196 UINT32_MAX, // CPU type mask
197 0x00FFFFFFu, // CPU subtype mask
198 "mach-o"
Greg Clayton41f92322010-06-11 03:25:34 +0000199};
200
Greg Clayton64195a22011-02-23 00:35:02 +0000201//===----------------------------------------------------------------------===//
202// A table that gets searched linearly for matches. This table is used to
203// convert cpu type and subtypes to architecture names, and to convert
204// architecture names to cpu types and subtypes. The ordering is important and
205// allows the precedence to be set when the table is built.
206static const ArchDefinitionEntry g_elf_arch_entries[] =
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000207{
Greg Clayton64195a22011-02-23 00:35:02 +0000208 { ArchSpec::eCore_sparc_generic , llvm::ELF::EM_SPARC , LLDB_INVALID_CPUTYPE }, // Sparc
209 { ArchSpec::eCore_x86_32_i386 , llvm::ELF::EM_386 , LLDB_INVALID_CPUTYPE }, // Intel 80386
210 { ArchSpec::eCore_x86_32_i486 , llvm::ELF::EM_486 , LLDB_INVALID_CPUTYPE }, // Intel 486 (deprecated)
211 { ArchSpec::eCore_ppc_generic , llvm::ELF::EM_PPC , LLDB_INVALID_CPUTYPE }, // PowerPC
212 { ArchSpec::eCore_ppc64_generic , llvm::ELF::EM_PPC64 , LLDB_INVALID_CPUTYPE }, // PowerPC64
213 { ArchSpec::eCore_arm_generic , llvm::ELF::EM_ARM , LLDB_INVALID_CPUTYPE }, // ARM
Greg Clayton64195a22011-02-23 00:35:02 +0000214 { ArchSpec::eCore_sparc9_generic , llvm::ELF::EM_SPARCV9, LLDB_INVALID_CPUTYPE }, // SPARC V9
215 { ArchSpec::eCore_x86_64_x86_64 , llvm::ELF::EM_X86_64 , LLDB_INVALID_CPUTYPE }, // AMD64
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000216};
217
Greg Clayton64195a22011-02-23 00:35:02 +0000218static const ArchDefinition g_elf_arch_def = {
219 eArchTypeELF,
220 sizeof(g_elf_arch_entries)/sizeof(g_elf_arch_entries[0]),
221 g_elf_arch_entries,
222 UINT32_MAX, // CPU type mask
223 UINT32_MAX, // CPU subtype mask
224 "elf",
Greg Clayton41f92322010-06-11 03:25:34 +0000225};
226
Greg Clayton64195a22011-02-23 00:35:02 +0000227//===----------------------------------------------------------------------===//
228// Table of all ArchDefinitions
229static const ArchDefinition *g_arch_definitions[] = {
230 &g_macho_arch_def,
231 &g_elf_arch_def,
232};
Greg Clayton41f92322010-06-11 03:25:34 +0000233
Greg Clayton64195a22011-02-23 00:35:02 +0000234static const size_t k_num_arch_definitions =
235 sizeof(g_arch_definitions) / sizeof(g_arch_definitions[0]);
236
237//===----------------------------------------------------------------------===//
238// Static helper functions.
239
240
241// Get the architecture definition for a given object type.
242static const ArchDefinition *
243FindArchDefinition (ArchitectureType arch_type)
244{
245 for (unsigned int i = 0; i < k_num_arch_definitions; ++i)
246 {
247 const ArchDefinition *def = g_arch_definitions[i];
248 if (def->type == arch_type)
249 return def;
250 }
251 return NULL;
252}
253
254// Get an architecture definition by name.
255static const CoreDefinition *
256FindCoreDefinition (llvm::StringRef name)
257{
258 for (unsigned int i = 0; i < ArchSpec::kNumCores; ++i)
259 {
260 if (name.equals_lower(g_core_definitions[i].name))
261 return &g_core_definitions[i];
262 }
263 return NULL;
264}
265
266static inline const CoreDefinition *
267FindCoreDefinition (ArchSpec::Core core)
268{
269 if (core >= 0 && core < ArchSpec::kNumCores)
270 return &g_core_definitions[core];
271 return NULL;
272}
273
274// Get a definition entry by cpu type and subtype.
275static const ArchDefinitionEntry *
276FindArchDefinitionEntry (const ArchDefinition *def, uint32_t cpu, uint32_t sub)
277{
278 if (def == NULL)
279 return NULL;
280
281 const uint32_t cpu_mask = def->cpu_mask;
282 const uint32_t sub_mask = def->sub_mask;
283 const ArchDefinitionEntry *entries = def->entries;
284 for (size_t i = 0; i < def->num_entries; ++i)
285 {
286 if ((entries[i].cpu == (cpu_mask & cpu)) &&
287 (entries[i].sub == (sub_mask & sub)))
288 return &entries[i];
289 }
290 return NULL;
291}
292
293static const ArchDefinitionEntry *
294FindArchDefinitionEntry (const ArchDefinition *def, ArchSpec::Core core)
295{
296 if (def == NULL)
297 return NULL;
298
299 const ArchDefinitionEntry *entries = def->entries;
300 for (size_t i = 0; i < def->num_entries; ++i)
301 {
302 if (entries[i].core == core)
303 return &entries[i];
304 }
305 return NULL;
306}
307
308//===----------------------------------------------------------------------===//
309// Constructors and destructors.
310
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000311ArchSpec::ArchSpec() :
Greg Clayton514487e2011-02-15 21:59:32 +0000312 m_triple (),
Greg Clayton64195a22011-02-23 00:35:02 +0000313 m_core (kCore_invalid),
314 m_byte_order (eByteOrderInvalid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000315{
316}
317
Greg Claytoneb0103f2011-04-07 22:46:35 +0000318ArchSpec::ArchSpec (const char *triple_cstr, Platform *platform) :
Greg Clayton514487e2011-02-15 21:59:32 +0000319 m_triple (),
Greg Clayton64195a22011-02-23 00:35:02 +0000320 m_core (kCore_invalid),
321 m_byte_order (eByteOrderInvalid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000322{
Greg Clayton64195a22011-02-23 00:35:02 +0000323 if (triple_cstr)
Greg Claytoneb0103f2011-04-07 22:46:35 +0000324 SetTriple(triple_cstr, platform);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000325}
326
Greg Clayton70512312012-05-08 01:45:38 +0000327
328ArchSpec::ArchSpec (const char *triple_cstr) :
329 m_triple (),
330 m_core (kCore_invalid),
331 m_byte_order (eByteOrderInvalid)
332{
333 if (triple_cstr)
334 SetTriple(triple_cstr);
335}
336
Greg Clayton64195a22011-02-23 00:35:02 +0000337ArchSpec::ArchSpec(const llvm::Triple &triple) :
Greg Clayton514487e2011-02-15 21:59:32 +0000338 m_triple (),
Greg Clayton64195a22011-02-23 00:35:02 +0000339 m_core (kCore_invalid),
340 m_byte_order (eByteOrderInvalid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000341{
Greg Clayton64195a22011-02-23 00:35:02 +0000342 SetTriple(triple);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000343}
344
Greg Claytone0d378b2011-03-24 21:19:54 +0000345ArchSpec::ArchSpec (ArchitectureType arch_type, uint32_t cpu, uint32_t subtype) :
Greg Clayton64195a22011-02-23 00:35:02 +0000346 m_triple (),
347 m_core (kCore_invalid),
348 m_byte_order (eByteOrderInvalid)
349{
350 SetArchitecture (arch_type, cpu, subtype);
351}
352
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000353ArchSpec::~ArchSpec()
354{
355}
356
Greg Clayton64195a22011-02-23 00:35:02 +0000357//===----------------------------------------------------------------------===//
358// Assignment and initialization.
359
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000360const ArchSpec&
361ArchSpec::operator= (const ArchSpec& rhs)
362{
363 if (this != &rhs)
364 {
Greg Clayton514487e2011-02-15 21:59:32 +0000365 m_triple = rhs.m_triple;
Greg Clayton64195a22011-02-23 00:35:02 +0000366 m_core = rhs.m_core;
Greg Clayton514487e2011-02-15 21:59:32 +0000367 m_byte_order = rhs.m_byte_order;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368 }
369 return *this;
370}
371
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000372void
373ArchSpec::Clear()
374{
Greg Clayton514487e2011-02-15 21:59:32 +0000375 m_triple = llvm::Triple();
Greg Clayton64195a22011-02-23 00:35:02 +0000376 m_core = kCore_invalid;
377 m_byte_order = eByteOrderInvalid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000378}
379
Greg Clayton64195a22011-02-23 00:35:02 +0000380//===----------------------------------------------------------------------===//
381// Predicates.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000382
Greg Clayton41f92322010-06-11 03:25:34 +0000383
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384const char *
Greg Clayton64195a22011-02-23 00:35:02 +0000385ArchSpec::GetArchitectureName () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000386{
Greg Clayton64195a22011-02-23 00:35:02 +0000387 const CoreDefinition *core_def = FindCoreDefinition (m_core);
388 if (core_def)
389 return core_def->name;
390 return "unknown";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000391}
392
Greg Clayton64195a22011-02-23 00:35:02 +0000393uint32_t
394ArchSpec::GetMachOCPUType () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000395{
Greg Clayton64195a22011-02-23 00:35:02 +0000396 const CoreDefinition *core_def = FindCoreDefinition (m_core);
397 if (core_def)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000398 {
Greg Clayton64195a22011-02-23 00:35:02 +0000399 const ArchDefinitionEntry *arch_def = FindArchDefinitionEntry (&g_macho_arch_def, core_def->core);
400 if (arch_def)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000401 {
Greg Clayton64195a22011-02-23 00:35:02 +0000402 return arch_def->cpu;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403 }
404 }
Greg Clayton64195a22011-02-23 00:35:02 +0000405 return LLDB_INVALID_CPUTYPE;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000406}
407
Greg Clayton64195a22011-02-23 00:35:02 +0000408uint32_t
409ArchSpec::GetMachOCPUSubType () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410{
Greg Clayton64195a22011-02-23 00:35:02 +0000411 const CoreDefinition *core_def = FindCoreDefinition (m_core);
412 if (core_def)
413 {
414 const ArchDefinitionEntry *arch_def = FindArchDefinitionEntry (&g_macho_arch_def, core_def->core);
415 if (arch_def)
416 {
Greg Clayton1cb64962011-03-24 04:28:38 +0000417 return arch_def->sub;
Greg Clayton64195a22011-02-23 00:35:02 +0000418 }
419 }
420 return LLDB_INVALID_CPUTYPE;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000421}
422
Greg Clayton64195a22011-02-23 00:35:02 +0000423llvm::Triple::ArchType
424ArchSpec::GetMachine () const
425{
426 const CoreDefinition *core_def = FindCoreDefinition (m_core);
427 if (core_def)
428 return core_def->machine;
429
430 return llvm::Triple::UnknownArch;
431}
432
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000433uint32_t
434ArchSpec::GetAddressByteSize() const
435{
Greg Clayton64195a22011-02-23 00:35:02 +0000436 const CoreDefinition *core_def = FindCoreDefinition (m_core);
437 if (core_def)
438 return core_def->addr_byte_size;
Greg Clayton41f92322010-06-11 03:25:34 +0000439 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000440}
441
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000442ByteOrder
443ArchSpec::GetDefaultEndian () const
444{
Greg Clayton64195a22011-02-23 00:35:02 +0000445 const CoreDefinition *core_def = FindCoreDefinition (m_core);
446 if (core_def)
447 return core_def->default_byte_order;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000448 return eByteOrderInvalid;
449}
450
Greg Clayton64195a22011-02-23 00:35:02 +0000451lldb::ByteOrder
452ArchSpec::GetByteOrder () const
453{
454 if (m_byte_order == eByteOrderInvalid)
455 return GetDefaultEndian();
456 return m_byte_order;
457}
458
459//===----------------------------------------------------------------------===//
460// Mutators.
461
462bool
463ArchSpec::SetTriple (const llvm::Triple &triple)
464{
465 m_triple = triple;
466
467 llvm::StringRef arch_name (m_triple.getArchName());
468 const CoreDefinition *core_def = FindCoreDefinition (arch_name);
469 if (core_def)
470 {
471 m_core = core_def->core;
Greg Claytoneb0103f2011-04-07 22:46:35 +0000472 // Set the byte order to the default byte order for an architecture.
473 // This can be modified if needed for cases when cores handle both
474 // big and little endian
475 m_byte_order = core_def->default_byte_order;
Greg Clayton64195a22011-02-23 00:35:02 +0000476 }
477 else
478 {
479 Clear();
480 }
481
482
483 return IsValid();
484}
485
486bool
Greg Clayton70512312012-05-08 01:45:38 +0000487ArchSpec::SetTriple (const char *triple_cstr)
Greg Clayton64195a22011-02-23 00:35:02 +0000488{
Greg Clayton23aca092011-08-12 23:32:52 +0000489 if (triple_cstr && triple_cstr[0])
Greg Clayton64195a22011-02-23 00:35:02 +0000490 {
Greg Claytone795f1b2012-08-08 01:19:34 +0000491 if (isdigit(triple_cstr[0]))
492 {
493 // Accept "12-10" or "12.10" as cpu type/subtype
494 char *end = NULL;
495 uint32_t cpu = ::strtoul (triple_cstr, &end, 0);
496 if (cpu != 0 && end && ((*end == '-') || (*end == '.')))
497 {
498 uint32_t sub = ::strtoul (end + 1, &end, 0);
499 if (sub != 0 && end && ((*end == '-') || (*end == '.') || (*end == '\0')))
500 {
501 if (SetArchitecture (eArchTypeMachO, cpu, sub))
502 {
503 if (*end == '-')
504 {
505 llvm::StringRef vendor_os (end + 1);
506 size_t dash_pos = vendor_os.find('-');
507 if (dash_pos != llvm::StringRef::npos)
508 {
509 llvm::StringRef vendor_str(vendor_os.substr(0, dash_pos));
510 m_triple.setVendorName(vendor_str);
511 const size_t vendor_start_pos = dash_pos+1;
512 dash_pos = vendor_os.find(vendor_start_pos, '-');
513 if (dash_pos == llvm::StringRef::npos)
514 {
515 if (vendor_start_pos < vendor_os.size())
516 m_triple.setOSName(vendor_os.substr(vendor_start_pos));
517 }
518 else
519 {
520 m_triple.setOSName(vendor_os.substr(vendor_start_pos, dash_pos - vendor_start_pos));
521 }
522 }
523 }
524 return true;
525 }
526 }
527 }
528 }
Greg Clayton64195a22011-02-23 00:35:02 +0000529 llvm::StringRef triple_stref (triple_cstr);
530 if (triple_stref.startswith (LLDB_ARCH_DEFAULT))
531 {
532 // Special case for the current host default architectures...
533 if (triple_stref.equals (LLDB_ARCH_DEFAULT_32BIT))
534 *this = Host::GetArchitecture (Host::eSystemDefaultArchitecture32);
535 else if (triple_stref.equals (LLDB_ARCH_DEFAULT_64BIT))
536 *this = Host::GetArchitecture (Host::eSystemDefaultArchitecture64);
537 else if (triple_stref.equals (LLDB_ARCH_DEFAULT))
538 *this = Host::GetArchitecture (Host::eSystemDefaultArchitecture);
539 }
540 else
541 {
542 std::string normalized_triple_sstr (llvm::Triple::normalize(triple_stref));
543 triple_stref = normalized_triple_sstr;
Greg Clayton70512312012-05-08 01:45:38 +0000544 SetTriple (llvm::Triple (triple_stref));
545 }
546 }
547 else
548 Clear();
549 return IsValid();
550}
551
552bool
553ArchSpec::SetTriple (const char *triple_cstr, Platform *platform)
554{
555 if (triple_cstr && triple_cstr[0])
556 {
557 llvm::StringRef triple_stref (triple_cstr);
558 if (triple_stref.startswith (LLDB_ARCH_DEFAULT))
559 {
560 // Special case for the current host default architectures...
561 if (triple_stref.equals (LLDB_ARCH_DEFAULT_32BIT))
562 *this = Host::GetArchitecture (Host::eSystemDefaultArchitecture32);
563 else if (triple_stref.equals (LLDB_ARCH_DEFAULT_64BIT))
564 *this = Host::GetArchitecture (Host::eSystemDefaultArchitecture64);
565 else if (triple_stref.equals (LLDB_ARCH_DEFAULT))
566 *this = Host::GetArchitecture (Host::eSystemDefaultArchitecture);
567 }
568 else
569 {
570 ArchSpec raw_arch (triple_cstr);
571
572 std::string normalized_triple_sstr (llvm::Triple::normalize(triple_stref));
573 triple_stref = normalized_triple_sstr;
Greg Claytoneb0103f2011-04-07 22:46:35 +0000574 llvm::Triple normalized_triple (triple_stref);
575
576 const bool os_specified = normalized_triple.getOSName().size() > 0;
577 const bool vendor_specified = normalized_triple.getVendorName().size() > 0;
578 const bool env_specified = normalized_triple.getEnvironmentName().size() > 0;
579
580 // If we got an arch only, then default the vendor, os, environment
581 // to match the platform if one is supplied
582 if (!(os_specified || vendor_specified || env_specified))
583 {
584 if (platform)
585 {
586 // If we were given a platform, use the platform's system
587 // architecture. If this is not available (might not be
588 // connected) use the first supported architecture.
Greg Clayton70512312012-05-08 01:45:38 +0000589 ArchSpec compatible_arch;
590 if (platform->IsCompatibleArchitecture (raw_arch, &compatible_arch))
Greg Claytoneb0103f2011-04-07 22:46:35 +0000591 {
Greg Clayton70512312012-05-08 01:45:38 +0000592 if (compatible_arch.IsValid())
593 {
594 const llvm::Triple &compatible_triple = compatible_arch.GetTriple();
595 if (!vendor_specified)
596 normalized_triple.setVendor(compatible_triple.getVendor());
597 if (!os_specified)
598 normalized_triple.setOS(compatible_triple.getOS());
599 if (!env_specified && compatible_triple.getEnvironmentName().size())
600 normalized_triple.setEnvironment(compatible_triple.getEnvironment());
601 }
Greg Claytoneb0103f2011-04-07 22:46:35 +0000602 }
Greg Clayton70512312012-05-08 01:45:38 +0000603 else
Greg Claytoneb0103f2011-04-07 22:46:35 +0000604 {
Greg Clayton70512312012-05-08 01:45:38 +0000605 *this = raw_arch;
606 return IsValid();
Greg Claytoneb0103f2011-04-07 22:46:35 +0000607 }
608 }
609 else
610 {
611 // No platform specified, fall back to the host system for
612 // the default vendor, os, and environment.
Sean Callananbfb237bc2011-11-04 22:46:46 +0000613 llvm::Triple host_triple(llvm::sys::getDefaultTargetTriple());
Greg Clayton70512312012-05-08 01:45:38 +0000614 if (!vendor_specified)
615 normalized_triple.setVendor(host_triple.getVendor());
616 if (!vendor_specified)
617 normalized_triple.setOS(host_triple.getOS());
618 if (!env_specified && host_triple.getEnvironmentName().size())
619 normalized_triple.setEnvironment(host_triple.getEnvironment());
Greg Claytoneb0103f2011-04-07 22:46:35 +0000620 }
621 }
622 SetTriple (normalized_triple);
Greg Clayton64195a22011-02-23 00:35:02 +0000623 }
624 }
625 else
626 Clear();
627 return IsValid();
628}
629
Greg Clayton64195a22011-02-23 00:35:02 +0000630bool
Greg Claytone0d378b2011-03-24 21:19:54 +0000631ArchSpec::SetArchitecture (ArchitectureType arch_type, uint32_t cpu, uint32_t sub)
Greg Clayton64195a22011-02-23 00:35:02 +0000632{
633 m_core = kCore_invalid;
634 bool update_triple = true;
635 const ArchDefinition *arch_def = FindArchDefinition(arch_type);
636 if (arch_def)
637 {
638 const ArchDefinitionEntry *arch_def_entry = FindArchDefinitionEntry (arch_def, cpu, sub);
639 if (arch_def_entry)
640 {
641 const CoreDefinition *core_def = FindCoreDefinition (arch_def_entry->core);
642 if (core_def)
643 {
644 m_core = core_def->core;
645 update_triple = false;
Greg Clayton593577a2011-09-21 03:57:31 +0000646 // Always use the architecture name because it might be more descriptive
647 // than the architecture enum ("armv7" -> llvm::Triple::arm).
648 m_triple.setArchName(llvm::StringRef(core_def->name));
Greg Clayton64195a22011-02-23 00:35:02 +0000649 if (arch_type == eArchTypeMachO)
650 {
651 m_triple.setVendor (llvm::Triple::Apple);
Greg Clayton70512312012-05-08 01:45:38 +0000652
653 switch (core_def->machine)
654 {
655 case llvm::Triple::arm:
656 case llvm::Triple::thumb:
657 m_triple.setOS (llvm::Triple::IOS);
658 break;
659
660 case llvm::Triple::x86:
661 case llvm::Triple::x86_64:
662 default:
663 m_triple.setOS (llvm::Triple::MacOSX);
664 break;
665 }
Greg Clayton64195a22011-02-23 00:35:02 +0000666 }
667 else
668 {
669 m_triple.setVendor (llvm::Triple::UnknownVendor);
670 m_triple.setOS (llvm::Triple::UnknownOS);
671 }
Greg Clayton593577a2011-09-21 03:57:31 +0000672 // Fall back onto setting the machine type if the arch by name failed...
673 if (m_triple.getArch () == llvm::Triple::UnknownArch)
674 m_triple.setArch (core_def->machine);
Greg Clayton64195a22011-02-23 00:35:02 +0000675 }
676 }
677 }
678 CoreUpdated(update_triple);
679 return IsValid();
680}
681
Greg Clayton357132e2011-03-26 19:14:58 +0000682uint32_t
683ArchSpec::GetMinimumOpcodeByteSize() const
Greg Clayton64195a22011-02-23 00:35:02 +0000684{
Greg Clayton357132e2011-03-26 19:14:58 +0000685 const CoreDefinition *core_def = FindCoreDefinition (m_core);
686 if (core_def)
687 return core_def->min_opcode_byte_size;
688 return 0;
689}
690
691uint32_t
692ArchSpec::GetMaximumOpcodeByteSize() const
693{
694 const CoreDefinition *core_def = FindCoreDefinition (m_core);
695 if (core_def)
696 return core_def->max_opcode_byte_size;
697 return 0;
Greg Clayton64195a22011-02-23 00:35:02 +0000698}
699
700//===----------------------------------------------------------------------===//
701// Helper methods.
702
703void
704ArchSpec::CoreUpdated (bool update_triple)
705{
706 const CoreDefinition *core_def = FindCoreDefinition (m_core);
707 if (core_def)
708 {
709 if (update_triple)
710 m_triple = llvm::Triple(core_def->name, "unknown", "unknown");
711 m_byte_order = core_def->default_byte_order;
712 }
713 else
714 {
715 if (update_triple)
716 m_triple = llvm::Triple();
717 m_byte_order = eByteOrderInvalid;
718 }
719}
720
721//===----------------------------------------------------------------------===//
722// Operators.
723
Greg Clayton70512312012-05-08 01:45:38 +0000724static bool
725cores_match (const ArchSpec::Core core1, const ArchSpec::Core core2, bool try_inverse)
726{
727 switch (core1)
728 {
729// case ArchSpec::eCore_arm_armv4:
730// try_inverse = false;
731// if (core2 == ArchSpec::eCore_thumb)
732// return true;
733// break;
734//
735// case ArchSpec::eCore_arm_armv4t:
736// try_inverse = false;
737// if (core2 == ArchSpec::eCore_thumbv4t)
738// return true;
739// break;
740//
741// case ArchSpec::eCore_arm_armv5:
742// try_inverse = false;
743// if (core2 == ArchSpec::eCore_thumbv5)
744// return true;
745// break;
746//
747// case ArchSpec::eCore_arm_armv5t:
748// case ArchSpec::eCore_arm_armv5e:
749// try_inverse = false;
750// if (core2 == ArchSpec::eCore_thumbv5e)
751// return true;
752// break;
753//
754// case ArchSpec::eCore_arm_armv6:
755// try_inverse = false;
756// if (core2 == ArchSpec::eCore_thumbv6)
757// return true;
758// break;
759//
760// case ArchSpec::eCore_arm_armv7:
761// try_inverse = false;
762// if (core2 == ArchSpec::eCore_thumbv7)
763// return true;
764// break;
765//
766// case ArchSpec::eCore_arm_armv7f:
767// try_inverse = false;
768// if (core2 == ArchSpec::eCore_thumbv7f)
769// return true;
770// break;
771//
772// case ArchSpec::eCore_arm_armv7k:
773// try_inverse = false;
774// if (core2 == ArchSpec::eCore_thumbv7k)
775// return true;
776// break;
777//
778// case ArchSpec::eCore_arm_armv7s:
779// try_inverse = false;
780// if (core2 == ArchSpec::eCore_thumbv7s)
781// return true;
782// break;
783//
784// case ArchSpec::eCore_thumb:
785// try_inverse = false;
786// if (core2 == ArchSpec::eCore_arm_armv4)
787// return true;
788// break;
789//
790// case ArchSpec::eCore_thumbv4t:
791// try_inverse = false;
792// if (core2 == ArchSpec::eCore_arm_armv4t)
793// return true;
794// break;
795//
796// case ArchSpec::eCore_thumbv5:
797// try_inverse = false;
798// if (core2 == ArchSpec::eCore_arm_armv5)
799// return true;
800// break;
801//
802// case ArchSpec::eCore_thumbv5e:
803// try_inverse = false;
804// if (core2 == ArchSpec::eCore_arm_armv5t || core2 == ArchSpec::eCore_arm_armv5e)
805// return true;
806// break;
807//
808// case ArchSpec::eCore_thumbv6:
809// try_inverse = false;
810// if (core2 == ArchSpec::eCore_arm_armv6)
811// return true;
812// break;
813//
814// case ArchSpec::eCore_thumbv7:
815// try_inverse = false;
816// if (core2 == ArchSpec::eCore_arm_armv7)
817// return true;
818// break;
819//
820// case ArchSpec::eCore_thumbv7f:
821// try_inverse = false;
822// if (core2 == ArchSpec::eCore_arm_armv7f)
823// return true;
824// break;
825//
826// case ArchSpec::eCore_thumbv7k:
827// try_inverse = false;
828// if (core2 == ArchSpec::eCore_arm_armv7k)
829// return true;
830// break;
831//
832// case ArchSpec::eCore_thumbv7s:
833// try_inverse = false;
834// if (core2 == ArchSpec::eCore_arm_armv7s)
835// return true;
836// break;
837
838 case ArchSpec::kCore_any:
839 return true;
840
841 case ArchSpec::kCore_arm_any:
842 if (core2 >= ArchSpec::kCore_arm_first && core2 <= ArchSpec::kCore_arm_last)
843 return true;
844 if (core2 >= ArchSpec::kCore_thumb_first && core2 <= ArchSpec::kCore_thumb_last)
845 return true;
846 if (core2 == ArchSpec::kCore_arm_any)
847 return true;
848 break;
849
850 case ArchSpec::kCore_x86_32_any:
851 if ((core2 >= ArchSpec::kCore_x86_32_first && core2 <= ArchSpec::kCore_x86_32_last) || (core2 == ArchSpec::kCore_x86_32_any))
852 return true;
853 break;
854
855 case ArchSpec::kCore_ppc_any:
856 if ((core2 >= ArchSpec::kCore_ppc_first && core2 <= ArchSpec::kCore_ppc_last) || (core2 == ArchSpec::kCore_ppc_any))
857 return true;
858 break;
859
860 case ArchSpec::kCore_ppc64_any:
861 if ((core2 >= ArchSpec::kCore_ppc64_first && core2 <= ArchSpec::kCore_ppc64_last) || (core2 == ArchSpec::kCore_ppc64_any))
862 return true;
863 break;
864
Johnny Chen1083b0d2012-08-28 22:53:40 +0000865 case ArchSpec::eCore_arm_armv7:
866 case ArchSpec::eCore_arm_armv7f:
867 case ArchSpec::eCore_arm_armv7k:
868 case ArchSpec::eCore_arm_armv7s:
869 try_inverse = false;
870 if (core2 == ArchSpec::eCore_arm_armv7)
871 return true;
872 break;
873
Greg Clayton70512312012-05-08 01:45:38 +0000874 default:
875 break;
876 }
877 if (try_inverse)
878 return cores_match (core2, core1, false);
879 return false;
880}
881
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000882bool
883lldb_private::operator== (const ArchSpec& lhs, const ArchSpec& rhs)
884{
Jim Ingham4d9695a2011-09-15 01:07:30 +0000885 if (lhs.GetByteOrder() != rhs.GetByteOrder())
886 return false;
887
Greg Clayton64195a22011-02-23 00:35:02 +0000888 const ArchSpec::Core lhs_core = lhs.GetCore ();
889 const ArchSpec::Core rhs_core = rhs.GetCore ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000890
Greg Clayton70512312012-05-08 01:45:38 +0000891 // Check if the cores match, or check a little closer watching for wildcard
892 // and equivalent cores
893 const bool core_match = (lhs_core == rhs_core) || cores_match (lhs_core, rhs_core, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000894
Greg Clayton70512312012-05-08 01:45:38 +0000895 if (core_match)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000896 {
Jim Ingham4d9695a2011-09-15 01:07:30 +0000897 const llvm::Triple &lhs_triple = lhs.GetTriple();
898 const llvm::Triple &rhs_triple = rhs.GetTriple();
Greg Clayton593577a2011-09-21 03:57:31 +0000899
900 const llvm::Triple::VendorType lhs_triple_vendor = lhs_triple.getVendor();
901 const llvm::Triple::VendorType rhs_triple_vendor = rhs_triple.getVendor();
902 if (lhs_triple_vendor != rhs_triple_vendor)
903 {
Greg Clayton70512312012-05-08 01:45:38 +0000904 const bool rhs_vendor_specified = rhs.TripleVendorWasSpecified();
905 const bool lhs_vendor_specified = lhs.TripleVendorWasSpecified();
906 // Both architectures had the vendor specified, so if they aren't
907 // equal then we return false
908 if (rhs_vendor_specified && lhs_vendor_specified)
909 return false;
910
Greg Clayton593577a2011-09-21 03:57:31 +0000911 // Only fail if both vendor types are not unknown
912 if (lhs_triple_vendor != llvm::Triple::UnknownVendor &&
913 rhs_triple_vendor != llvm::Triple::UnknownVendor)
914 return false;
915 }
916
917 const llvm::Triple::OSType lhs_triple_os = lhs_triple.getOS();
918 const llvm::Triple::OSType rhs_triple_os = rhs_triple.getOS();
919 if (lhs_triple_os != rhs_triple_os)
920 {
Greg Clayton70512312012-05-08 01:45:38 +0000921 const bool rhs_os_specified = rhs.TripleOSWasSpecified();
922 const bool lhs_os_specified = lhs.TripleOSWasSpecified();
923 // Both architectures had the OS specified, so if they aren't
924 // equal then we return false
925 if (rhs_os_specified && lhs_os_specified)
926 return false;
Greg Clayton593577a2011-09-21 03:57:31 +0000927 // Only fail if both os types are not unknown
928 if (lhs_triple_os != llvm::Triple::UnknownOS &&
929 rhs_triple_os != llvm::Triple::UnknownOS)
930 return false;
931 }
932
933 const llvm::Triple::EnvironmentType lhs_triple_env = lhs_triple.getEnvironment();
934 const llvm::Triple::EnvironmentType rhs_triple_env = rhs_triple.getEnvironment();
935
936 if (lhs_triple_env != rhs_triple_env)
937 {
938 // Only fail if both environment types are not unknown
939 if (lhs_triple_env != llvm::Triple::UnknownEnvironment &&
940 rhs_triple_env != llvm::Triple::UnknownEnvironment)
941 return false;
942 }
943 return true;
Greg Clayton64195a22011-02-23 00:35:02 +0000944 }
Greg Clayton70512312012-05-08 01:45:38 +0000945 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000946}
947
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000948bool
949lldb_private::operator!= (const ArchSpec& lhs, const ArchSpec& rhs)
950{
951 return !(lhs == rhs);
952}
953
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000954bool
955lldb_private::operator<(const ArchSpec& lhs, const ArchSpec& rhs)
956{
Greg Clayton64195a22011-02-23 00:35:02 +0000957 const ArchSpec::Core lhs_core = lhs.GetCore ();
958 const ArchSpec::Core rhs_core = rhs.GetCore ();
959 return lhs_core < rhs_core;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000960}