blob: ffe717f29c43f03d91672cbf42283353ee933809 [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"
Zachary Turner50232572015-03-18 21:31:45 +000021
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 Claytona97c4d22014-12-09 23:31:02 +000027#include "lldb/Target/Process.h"
28#include "lldb/Target/RegisterContext.h"
29#include "lldb/Target/Thread.h"
Zachary Turner50232572015-03-18 21:31:45 +000030#include "lldb/Utility/NameMatches.h"
31#include "lldb/Utility/SafeMachO.h"
Greg Claytona97c4d22014-12-09 23:31:02 +000032#include "Plugins/Process/Utility/ARMDefines.h"
33#include "Plugins/Process/Utility/InstructionUtils.h"
Greg Clayton41f92322010-06-11 03:25:34 +000034
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035using namespace lldb;
36using namespace lldb_private;
37
Greg Clayton64195a22011-02-23 00:35:02 +000038#define ARCH_SPEC_SEPARATOR_CHAR '-'
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039
Jason Molendaba813dc2012-11-04 03:20:05 +000040
41static bool cores_match (const ArchSpec::Core core1, const ArchSpec::Core core2, bool try_inverse, bool enforce_exact_match);
42
Greg Clayton64195a22011-02-23 00:35:02 +000043namespace lldb_private {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044
Greg Clayton64195a22011-02-23 00:35:02 +000045 struct CoreDefinition
46 {
47 ByteOrder default_byte_order;
48 uint32_t addr_byte_size;
Greg Clayton357132e2011-03-26 19:14:58 +000049 uint32_t min_opcode_byte_size;
50 uint32_t max_opcode_byte_size;
Greg Clayton64195a22011-02-23 00:35:02 +000051 llvm::Triple::ArchType machine;
52 ArchSpec::Core core;
Greg Clayton56b79682014-07-23 18:12:06 +000053 const char * const name;
Greg Clayton64195a22011-02-23 00:35:02 +000054 };
55
56}
57
58// This core information can be looked using the ArchSpec::Core as the index
Greg Clayton56b79682014-07-23 18:12:06 +000059static const CoreDefinition g_core_definitions[] =
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060{
Greg Clayton357132e2011-03-26 19:14:58 +000061 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_generic , "arm" },
62 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv4 , "armv4" },
63 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv4t , "armv4t" },
64 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv5 , "armv5" },
Greg Claytonb5c39fe2011-12-16 18:15:52 +000065 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv5e , "armv5e" },
Greg Clayton357132e2011-03-26 19:14:58 +000066 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv5t , "armv5t" },
67 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv6 , "armv6" },
Jason Molendaa3a04522013-09-27 23:21:54 +000068 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv6m , "armv6m" },
Greg Clayton357132e2011-03-26 19:14:58 +000069 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7 , "armv7" },
70 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7f , "armv7f" },
Greg Clayton357132e2011-03-26 19:14:58 +000071 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7s , "armv7s" },
Jason Molenda7a1559c2013-03-08 01:20:17 +000072 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7k , "armv7k" },
73 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7m , "armv7m" },
74 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_armv7em , "armv7em" },
Greg Clayton357132e2011-03-26 19:14:58 +000075 { eByteOrderLittle, 4, 2, 4, llvm::Triple::arm , ArchSpec::eCore_arm_xscale , "xscale" },
Greg Claytonb5c39fe2011-12-16 18:15:52 +000076 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumb , "thumb" },
77 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv4t , "thumbv4t" },
78 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv5 , "thumbv5" },
79 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv5e , "thumbv5e" },
80 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv6 , "thumbv6" },
Jason Molendaa3a04522013-09-27 23:21:54 +000081 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv6m , "thumbv6m" },
Greg Claytonb5c39fe2011-12-16 18:15:52 +000082 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7 , "thumbv7" },
83 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7f , "thumbv7f" },
Greg Claytonb5c39fe2011-12-16 18:15:52 +000084 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7s , "thumbv7s" },
Jason Molenda7a1559c2013-03-08 01:20:17 +000085 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7k , "thumbv7k" },
86 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7m , "thumbv7m" },
87 { eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb , ArchSpec::eCore_thumbv7em , "thumbv7em" },
Todd Fialad8eaa172014-07-23 14:37:35 +000088 { eByteOrderLittle, 8, 4, 4, llvm::Triple::aarch64, ArchSpec::eCore_arm_arm64 , "arm64" },
Todd Fiala02e71812014-08-28 14:32:43 +000089 { eByteOrderLittle, 8, 4, 4, llvm::Triple::aarch64, ArchSpec::eCore_arm_armv8 , "armv8" },
90 { eByteOrderLittle, 8, 4, 4, llvm::Triple::aarch64, ArchSpec::eCore_arm_aarch64 , "aarch64" },
Ed Masteb73f8442013-10-10 00:59:47 +000091
Mohit K. Bhakkade8659b52015-04-23 06:36:20 +000092 // mips32, mips32r2, mips32r3, mips32r5, mips32r6
Jaydeep Patil501a7812015-07-16 03:51:55 +000093 { eByteOrderBig , 4, 2, 4, llvm::Triple::mips , ArchSpec::eCore_mips32 , "mips" },
94 { eByteOrderBig , 4, 2, 4, llvm::Triple::mips , ArchSpec::eCore_mips32r2 , "mipsr2" },
95 { eByteOrderBig , 4, 2, 4, llvm::Triple::mips , ArchSpec::eCore_mips32r3 , "mipsr3" },
96 { eByteOrderBig , 4, 2, 4, llvm::Triple::mips , ArchSpec::eCore_mips32r5 , "mipsr5" },
97 { eByteOrderBig , 4, 2, 4, llvm::Triple::mips , ArchSpec::eCore_mips32r6 , "mipsr6" },
98 { eByteOrderLittle, 4, 2, 4, llvm::Triple::mipsel, ArchSpec::eCore_mips32el , "mipsel" },
99 { eByteOrderLittle, 4, 2, 4, llvm::Triple::mipsel, ArchSpec::eCore_mips32r2el , "mipsr2el" },
100 { eByteOrderLittle, 4, 2, 4, llvm::Triple::mipsel, ArchSpec::eCore_mips32r3el , "mipsr3el" },
101 { eByteOrderLittle, 4, 2, 4, llvm::Triple::mipsel, ArchSpec::eCore_mips32r5el , "mipsr5el" },
102 { eByteOrderLittle, 4, 2, 4, llvm::Triple::mipsel, ArchSpec::eCore_mips32r6el , "mipsr6el" },
Mohit K. Bhakkade8659b52015-04-23 06:36:20 +0000103
104 // mips64, mips64r2, mips64r3, mips64r5, mips64r6
Jaydeep Patil501a7812015-07-16 03:51:55 +0000105 { eByteOrderBig , 8, 2, 4, llvm::Triple::mips64 , ArchSpec::eCore_mips64 , "mips64" },
106 { eByteOrderBig , 8, 2, 4, llvm::Triple::mips64 , ArchSpec::eCore_mips64r2 , "mips64r2" },
107 { eByteOrderBig , 8, 2, 4, llvm::Triple::mips64 , ArchSpec::eCore_mips64r3 , "mips64r3" },
108 { eByteOrderBig , 8, 2, 4, llvm::Triple::mips64 , ArchSpec::eCore_mips64r5 , "mips64r5" },
109 { eByteOrderBig , 8, 2, 4, llvm::Triple::mips64 , ArchSpec::eCore_mips64r6 , "mips64r6" },
110 { eByteOrderLittle, 8, 2, 4, llvm::Triple::mips64el, ArchSpec::eCore_mips64el , "mips64el" },
111 { eByteOrderLittle, 8, 2, 4, llvm::Triple::mips64el, ArchSpec::eCore_mips64r2el , "mips64r2el" },
112 { eByteOrderLittle, 8, 2, 4, llvm::Triple::mips64el, ArchSpec::eCore_mips64r3el , "mips64r3el" },
113 { eByteOrderLittle, 8, 2, 4, llvm::Triple::mips64el, ArchSpec::eCore_mips64r5el , "mips64r5el" },
114 { eByteOrderLittle, 8, 2, 4, llvm::Triple::mips64el, ArchSpec::eCore_mips64r6el , "mips64r6el" },
Greg Clayton64195a22011-02-23 00:35:02 +0000115
Justin Hibbits6256a0e2014-10-31 02:34:28 +0000116 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_generic , "powerpc" },
Greg Clayton83b162d2013-08-12 18:34:04 +0000117 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc601 , "ppc601" },
118 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc602 , "ppc602" },
119 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc603 , "ppc603" },
120 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc603e , "ppc603e" },
121 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc603ev , "ppc603ev" },
122 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc604 , "ppc604" },
123 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc604e , "ppc604e" },
124 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc620 , "ppc620" },
125 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc750 , "ppc750" },
126 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc7400 , "ppc7400" },
127 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc7450 , "ppc7450" },
128 { eByteOrderBig , 4, 4, 4, llvm::Triple::ppc , ArchSpec::eCore_ppc_ppc970 , "ppc970" },
Greg Clayton64195a22011-02-23 00:35:02 +0000129
Justin Hibbits6256a0e2014-10-31 02:34:28 +0000130 { eByteOrderBig , 8, 4, 4, llvm::Triple::ppc64 , ArchSpec::eCore_ppc64_generic , "powerpc64" },
Greg Clayton83b162d2013-08-12 18:34:04 +0000131 { eByteOrderBig , 8, 4, 4, llvm::Triple::ppc64 , ArchSpec::eCore_ppc64_ppc970_64 , "ppc970-64" },
Greg Clayton64195a22011-02-23 00:35:02 +0000132
Greg Clayton357132e2011-03-26 19:14:58 +0000133 { eByteOrderLittle, 4, 4, 4, llvm::Triple::sparc , ArchSpec::eCore_sparc_generic , "sparc" },
134 { eByteOrderLittle, 8, 4, 4, llvm::Triple::sparcv9, ArchSpec::eCore_sparc9_generic , "sparcv9" },
Greg Clayton64195a22011-02-23 00:35:02 +0000135
Greg Claytonab65b342011-04-13 22:47:15 +0000136 { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i386 , "i386" },
137 { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i486 , "i486" },
138 { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i486sx , "i486sx" },
Virgile Bello97a70e42014-04-08 14:48:48 +0000139 { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i686 , "i686" },
Greg Clayton64195a22011-02-23 00:35:02 +0000140
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000141 { eByteOrderLittle, 8, 1, 15, llvm::Triple::x86_64 , ArchSpec::eCore_x86_64_x86_64 , "x86_64" },
Greg Claytona86dc432014-01-22 23:42:03 +0000142 { eByteOrderLittle, 8, 1, 15, llvm::Triple::x86_64 , ArchSpec::eCore_x86_64_x86_64h , "x86_64h" },
Deepak Panickal6d3df422014-02-19 11:16:46 +0000143 { eByteOrderLittle, 4, 4, 4, llvm::Triple::hexagon , ArchSpec::eCore_hexagon_generic, "hexagon" },
144 { eByteOrderLittle, 4, 4, 4, llvm::Triple::hexagon , ArchSpec::eCore_hexagon_hexagonv4, "hexagonv4" },
145 { eByteOrderLittle, 4, 4, 4, llvm::Triple::hexagon , ArchSpec::eCore_hexagon_hexagonv5, "hexagonv5" },
146
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000147 { eByteOrderLittle, 4, 4, 4 , llvm::Triple::UnknownArch , ArchSpec::eCore_uknownMach32 , "unknown-mach-32" },
Todd Fiala14bbef52014-07-01 23:33:32 +0000148 { eByteOrderLittle, 8, 4, 4 , llvm::Triple::UnknownArch , ArchSpec::eCore_uknownMach64 , "unknown-mach-64" },
149
Matthew Gardiner5f675792014-08-27 12:09:39 +0000150 { eByteOrderBig , 4, 1, 1 , llvm::Triple::kalimba , ArchSpec::eCore_kalimba3 , "kalimba3" },
151 { eByteOrderLittle, 4, 1, 1 , llvm::Triple::kalimba , ArchSpec::eCore_kalimba4 , "kalimba4" },
152 { eByteOrderLittle, 4, 1, 1 , llvm::Triple::kalimba , ArchSpec::eCore_kalimba5 , "kalimba5" }
Greg Clayton64195a22011-02-23 00:35:02 +0000153};
154
Greg Clayton56b79682014-07-23 18:12:06 +0000155// Ensure that we have an entry in the g_core_definitions for each core. If you comment out an entry above,
156// you will need to comment out the corresponding ArchSpec::Core enumeration.
Zachary Turner3b2065f2014-07-28 16:44:28 +0000157static_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 +0000158
159
Greg Clayton64195a22011-02-23 00:35:02 +0000160struct ArchDefinitionEntry
161{
162 ArchSpec::Core core;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163 uint32_t cpu;
164 uint32_t sub;
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000165 uint32_t cpu_mask;
166 uint32_t sub_mask;
Greg Clayton64195a22011-02-23 00:35:02 +0000167};
168
169struct ArchDefinition
170{
171 ArchitectureType type;
172 size_t num_entries;
173 const ArchDefinitionEntry *entries;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000174 const char *name;
175};
176
Greg Clayton41f92322010-06-11 03:25:34 +0000177
Greg Claytonc7bece562013-01-25 18:06:21 +0000178size_t
Greg Claytonab65b342011-04-13 22:47:15 +0000179ArchSpec::AutoComplete (const char *name, StringList &matches)
180{
181 uint32_t i;
182 if (name && name[0])
183 {
Greg Clayton56b79682014-07-23 18:12:06 +0000184 for (i = 0; i < llvm::array_lengthof(g_core_definitions); ++i)
Greg Claytonab65b342011-04-13 22:47:15 +0000185 {
186 if (NameMatches(g_core_definitions[i].name, eNameMatchStartsWith, name))
187 matches.AppendString (g_core_definitions[i].name);
188 }
189 }
190 else
191 {
Greg Clayton56b79682014-07-23 18:12:06 +0000192 for (i = 0; i < llvm::array_lengthof(g_core_definitions); ++i)
Greg Claytonab65b342011-04-13 22:47:15 +0000193 matches.AppendString (g_core_definitions[i].name);
194 }
195 return matches.GetSize();
196}
197
198
199
Greg Clayton64195a22011-02-23 00:35:02 +0000200#define CPU_ANY (UINT32_MAX)
201
202//===----------------------------------------------------------------------===//
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.
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000207#define SUBTYPE_MASK 0x00FFFFFFu
Greg Clayton64195a22011-02-23 00:35:02 +0000208static const ArchDefinitionEntry g_macho_arch_entries[] =
Greg Clayton41f92322010-06-11 03:25:34 +0000209{
Charles Davis510938e2013-08-27 05:04:57 +0000210 { ArchSpec::eCore_arm_generic , llvm::MachO::CPU_TYPE_ARM , CPU_ANY, UINT32_MAX , UINT32_MAX },
211 { ArchSpec::eCore_arm_generic , llvm::MachO::CPU_TYPE_ARM , 0 , UINT32_MAX , SUBTYPE_MASK },
212 { ArchSpec::eCore_arm_armv4 , llvm::MachO::CPU_TYPE_ARM , 5 , UINT32_MAX , SUBTYPE_MASK },
213 { ArchSpec::eCore_arm_armv4t , llvm::MachO::CPU_TYPE_ARM , 5 , UINT32_MAX , SUBTYPE_MASK },
214 { ArchSpec::eCore_arm_armv6 , llvm::MachO::CPU_TYPE_ARM , 6 , UINT32_MAX , SUBTYPE_MASK },
Jason Molenda64a11732013-10-08 03:01:08 +0000215 { ArchSpec::eCore_arm_armv6m , llvm::MachO::CPU_TYPE_ARM , 14 , UINT32_MAX , SUBTYPE_MASK },
Charles Davis510938e2013-08-27 05:04:57 +0000216 { ArchSpec::eCore_arm_armv5 , llvm::MachO::CPU_TYPE_ARM , 7 , UINT32_MAX , SUBTYPE_MASK },
217 { ArchSpec::eCore_arm_armv5e , llvm::MachO::CPU_TYPE_ARM , 7 , UINT32_MAX , SUBTYPE_MASK },
218 { ArchSpec::eCore_arm_armv5t , llvm::MachO::CPU_TYPE_ARM , 7 , UINT32_MAX , SUBTYPE_MASK },
219 { ArchSpec::eCore_arm_xscale , llvm::MachO::CPU_TYPE_ARM , 8 , UINT32_MAX , SUBTYPE_MASK },
220 { ArchSpec::eCore_arm_armv7 , llvm::MachO::CPU_TYPE_ARM , 9 , UINT32_MAX , SUBTYPE_MASK },
221 { ArchSpec::eCore_arm_armv7f , llvm::MachO::CPU_TYPE_ARM , 10 , UINT32_MAX , SUBTYPE_MASK },
222 { ArchSpec::eCore_arm_armv7s , llvm::MachO::CPU_TYPE_ARM , 11 , UINT32_MAX , SUBTYPE_MASK },
223 { ArchSpec::eCore_arm_armv7k , llvm::MachO::CPU_TYPE_ARM , 12 , UINT32_MAX , SUBTYPE_MASK },
224 { ArchSpec::eCore_arm_armv7m , llvm::MachO::CPU_TYPE_ARM , 15 , UINT32_MAX , SUBTYPE_MASK },
225 { ArchSpec::eCore_arm_armv7em , llvm::MachO::CPU_TYPE_ARM , 16 , UINT32_MAX , SUBTYPE_MASK },
Jason Molendaa3329782014-03-29 18:54:20 +0000226 { ArchSpec::eCore_arm_arm64 , llvm::MachO::CPU_TYPE_ARM64 , 1 , UINT32_MAX , SUBTYPE_MASK },
Jason Molenda22952582014-11-12 01:11:36 +0000227 { ArchSpec::eCore_arm_arm64 , llvm::MachO::CPU_TYPE_ARM64 , 0 , UINT32_MAX , SUBTYPE_MASK },
Jason Molendaa3329782014-03-29 18:54:20 +0000228 { ArchSpec::eCore_arm_arm64 , llvm::MachO::CPU_TYPE_ARM64 , 13 , UINT32_MAX , SUBTYPE_MASK },
Jason Molenda22952582014-11-12 01:11:36 +0000229 { ArchSpec::eCore_arm_arm64 , llvm::MachO::CPU_TYPE_ARM64 , CPU_ANY, UINT32_MAX , SUBTYPE_MASK },
Charles Davis510938e2013-08-27 05:04:57 +0000230 { ArchSpec::eCore_thumb , llvm::MachO::CPU_TYPE_ARM , 0 , UINT32_MAX , SUBTYPE_MASK },
231 { ArchSpec::eCore_thumbv4t , llvm::MachO::CPU_TYPE_ARM , 5 , UINT32_MAX , SUBTYPE_MASK },
232 { ArchSpec::eCore_thumbv5 , llvm::MachO::CPU_TYPE_ARM , 7 , UINT32_MAX , SUBTYPE_MASK },
233 { ArchSpec::eCore_thumbv5e , llvm::MachO::CPU_TYPE_ARM , 7 , UINT32_MAX , SUBTYPE_MASK },
234 { ArchSpec::eCore_thumbv6 , llvm::MachO::CPU_TYPE_ARM , 6 , UINT32_MAX , SUBTYPE_MASK },
Jason Molenda64a11732013-10-08 03:01:08 +0000235 { ArchSpec::eCore_thumbv6m , llvm::MachO::CPU_TYPE_ARM , 14 , UINT32_MAX , SUBTYPE_MASK },
Charles Davis510938e2013-08-27 05:04:57 +0000236 { ArchSpec::eCore_thumbv7 , llvm::MachO::CPU_TYPE_ARM , 9 , UINT32_MAX , SUBTYPE_MASK },
237 { ArchSpec::eCore_thumbv7f , llvm::MachO::CPU_TYPE_ARM , 10 , UINT32_MAX , SUBTYPE_MASK },
238 { ArchSpec::eCore_thumbv7s , llvm::MachO::CPU_TYPE_ARM , 11 , UINT32_MAX , SUBTYPE_MASK },
239 { ArchSpec::eCore_thumbv7k , llvm::MachO::CPU_TYPE_ARM , 12 , UINT32_MAX , SUBTYPE_MASK },
240 { ArchSpec::eCore_thumbv7m , llvm::MachO::CPU_TYPE_ARM , 15 , UINT32_MAX , SUBTYPE_MASK },
241 { ArchSpec::eCore_thumbv7em , llvm::MachO::CPU_TYPE_ARM , 16 , UINT32_MAX , SUBTYPE_MASK },
242 { ArchSpec::eCore_ppc_generic , llvm::MachO::CPU_TYPE_POWERPC , CPU_ANY, UINT32_MAX , UINT32_MAX },
243 { ArchSpec::eCore_ppc_generic , llvm::MachO::CPU_TYPE_POWERPC , 0 , UINT32_MAX , SUBTYPE_MASK },
244 { ArchSpec::eCore_ppc_ppc601 , llvm::MachO::CPU_TYPE_POWERPC , 1 , UINT32_MAX , SUBTYPE_MASK },
245 { ArchSpec::eCore_ppc_ppc602 , llvm::MachO::CPU_TYPE_POWERPC , 2 , UINT32_MAX , SUBTYPE_MASK },
246 { ArchSpec::eCore_ppc_ppc603 , llvm::MachO::CPU_TYPE_POWERPC , 3 , UINT32_MAX , SUBTYPE_MASK },
247 { ArchSpec::eCore_ppc_ppc603e , llvm::MachO::CPU_TYPE_POWERPC , 4 , UINT32_MAX , SUBTYPE_MASK },
248 { ArchSpec::eCore_ppc_ppc603ev , llvm::MachO::CPU_TYPE_POWERPC , 5 , UINT32_MAX , SUBTYPE_MASK },
249 { ArchSpec::eCore_ppc_ppc604 , llvm::MachO::CPU_TYPE_POWERPC , 6 , UINT32_MAX , SUBTYPE_MASK },
250 { ArchSpec::eCore_ppc_ppc604e , llvm::MachO::CPU_TYPE_POWERPC , 7 , UINT32_MAX , SUBTYPE_MASK },
251 { ArchSpec::eCore_ppc_ppc620 , llvm::MachO::CPU_TYPE_POWERPC , 8 , UINT32_MAX , SUBTYPE_MASK },
252 { ArchSpec::eCore_ppc_ppc750 , llvm::MachO::CPU_TYPE_POWERPC , 9 , UINT32_MAX , SUBTYPE_MASK },
253 { ArchSpec::eCore_ppc_ppc7400 , llvm::MachO::CPU_TYPE_POWERPC , 10 , UINT32_MAX , SUBTYPE_MASK },
254 { ArchSpec::eCore_ppc_ppc7450 , llvm::MachO::CPU_TYPE_POWERPC , 11 , UINT32_MAX , SUBTYPE_MASK },
255 { ArchSpec::eCore_ppc_ppc970 , llvm::MachO::CPU_TYPE_POWERPC , 100 , UINT32_MAX , SUBTYPE_MASK },
256 { ArchSpec::eCore_ppc64_generic , llvm::MachO::CPU_TYPE_POWERPC64 , 0 , UINT32_MAX , SUBTYPE_MASK },
257 { ArchSpec::eCore_ppc64_ppc970_64 , llvm::MachO::CPU_TYPE_POWERPC64 , 100 , UINT32_MAX , SUBTYPE_MASK },
258 { ArchSpec::eCore_x86_32_i386 , llvm::MachO::CPU_TYPE_I386 , 3 , UINT32_MAX , SUBTYPE_MASK },
259 { ArchSpec::eCore_x86_32_i486 , llvm::MachO::CPU_TYPE_I386 , 4 , UINT32_MAX , SUBTYPE_MASK },
260 { ArchSpec::eCore_x86_32_i486sx , llvm::MachO::CPU_TYPE_I386 , 0x84 , UINT32_MAX , SUBTYPE_MASK },
Greg Claytona86dc432014-01-22 23:42:03 +0000261 { ArchSpec::eCore_x86_32_i386 , llvm::MachO::CPU_TYPE_I386 , CPU_ANY, UINT32_MAX , UINT32_MAX },
Charles Davis510938e2013-08-27 05:04:57 +0000262 { ArchSpec::eCore_x86_64_x86_64 , llvm::MachO::CPU_TYPE_X86_64 , 3 , UINT32_MAX , SUBTYPE_MASK },
263 { ArchSpec::eCore_x86_64_x86_64 , llvm::MachO::CPU_TYPE_X86_64 , 4 , UINT32_MAX , SUBTYPE_MASK },
Greg Claytona86dc432014-01-22 23:42:03 +0000264 { ArchSpec::eCore_x86_64_x86_64h , llvm::MachO::CPU_TYPE_X86_64 , 8 , UINT32_MAX , SUBTYPE_MASK },
265 { 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 +0000266 // Catch any unknown mach architectures so we can always use the object and symbol mach-o files
Charles Davis510938e2013-08-27 05:04:57 +0000267 { ArchSpec::eCore_uknownMach32 , 0 , 0 , 0xFF000000u, 0x00000000u },
268 { ArchSpec::eCore_uknownMach64 , llvm::MachO::CPU_ARCH_ABI64 , 0 , 0xFF000000u, 0x00000000u }
Greg Clayton64195a22011-02-23 00:35:02 +0000269};
270static const ArchDefinition g_macho_arch_def = {
271 eArchTypeMachO,
Saleem Abdulrasool28606952014-06-27 05:17:41 +0000272 llvm::array_lengthof(g_macho_arch_entries),
Greg Clayton64195a22011-02-23 00:35:02 +0000273 g_macho_arch_entries,
Greg Clayton64195a22011-02-23 00:35:02 +0000274 "mach-o"
Greg Clayton41f92322010-06-11 03:25:34 +0000275};
276
Greg Clayton64195a22011-02-23 00:35:02 +0000277//===----------------------------------------------------------------------===//
278// A table that gets searched linearly for matches. This table is used to
279// convert cpu type and subtypes to architecture names, and to convert
280// architecture names to cpu types and subtypes. The ordering is important and
281// allows the precedence to be set when the table is built.
282static const ArchDefinitionEntry g_elf_arch_entries[] =
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000283{
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000284 { ArchSpec::eCore_sparc_generic , llvm::ELF::EM_SPARC , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // Sparc
285 { ArchSpec::eCore_x86_32_i386 , llvm::ELF::EM_386 , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // Intel 80386
Rafael Espindola86f422e2015-06-19 17:02:25 +0000286 { ArchSpec::eCore_x86_32_i486 , llvm::ELF::EM_IAMCU , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // Intel MCU // FIXME: is this correct?
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000287 { ArchSpec::eCore_ppc_generic , llvm::ELF::EM_PPC , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // PowerPC
288 { ArchSpec::eCore_ppc64_generic , llvm::ELF::EM_PPC64 , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // PowerPC64
289 { ArchSpec::eCore_arm_generic , llvm::ELF::EM_ARM , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // ARM
Todd Fiala02e71812014-08-28 14:32:43 +0000290 { ArchSpec::eCore_arm_aarch64 , llvm::ELF::EM_AARCH64, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // ARM64
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000291 { ArchSpec::eCore_sparc9_generic , llvm::ELF::EM_SPARCV9, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // SPARC V9
Ed Masteb73f8442013-10-10 00:59:47 +0000292 { ArchSpec::eCore_x86_64_x86_64 , llvm::ELF::EM_X86_64 , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // AMD64
Mohit K. Bhakkade8659b52015-04-23 06:36:20 +0000293 { ArchSpec::eCore_mips32 , llvm::ELF::EM_MIPS , ArchSpec::eMIPSSubType_mips32, 0xFFFFFFFFu, 0xFFFFFFFFu }, // mips32
294 { ArchSpec::eCore_mips32r2 , llvm::ELF::EM_MIPS , ArchSpec::eMIPSSubType_mips32r2, 0xFFFFFFFFu, 0xFFFFFFFFu }, // mips32r2
295 { ArchSpec::eCore_mips32r6 , llvm::ELF::EM_MIPS , ArchSpec::eMIPSSubType_mips32r6, 0xFFFFFFFFu, 0xFFFFFFFFu }, // mips32r6
296 { ArchSpec::eCore_mips32el , llvm::ELF::EM_MIPS , ArchSpec::eMIPSSubType_mips32el, 0xFFFFFFFFu, 0xFFFFFFFFu }, // mips32el
297 { ArchSpec::eCore_mips32r2el , llvm::ELF::EM_MIPS , ArchSpec::eMIPSSubType_mips32r2el, 0xFFFFFFFFu, 0xFFFFFFFFu }, // mips32r2el
298 { ArchSpec::eCore_mips32r6el , llvm::ELF::EM_MIPS , ArchSpec::eMIPSSubType_mips32r6el, 0xFFFFFFFFu, 0xFFFFFFFFu }, // mips32r6el
299 { ArchSpec::eCore_mips64 , llvm::ELF::EM_MIPS , ArchSpec::eMIPSSubType_mips64, 0xFFFFFFFFu, 0xFFFFFFFFu }, // mips64
300 { ArchSpec::eCore_mips64r2 , llvm::ELF::EM_MIPS , ArchSpec::eMIPSSubType_mips64r2, 0xFFFFFFFFu, 0xFFFFFFFFu }, // mips64r2
301 { ArchSpec::eCore_mips64r6 , llvm::ELF::EM_MIPS , ArchSpec::eMIPSSubType_mips64r6, 0xFFFFFFFFu, 0xFFFFFFFFu }, // mips64r6
302 { ArchSpec::eCore_mips64el , llvm::ELF::EM_MIPS , ArchSpec::eMIPSSubType_mips64el, 0xFFFFFFFFu, 0xFFFFFFFFu }, // mips64el
303 { ArchSpec::eCore_mips64r2el , llvm::ELF::EM_MIPS , ArchSpec::eMIPSSubType_mips64r2el, 0xFFFFFFFFu, 0xFFFFFFFFu }, // mips64r2el
304 { ArchSpec::eCore_mips64r6el , llvm::ELF::EM_MIPS , ArchSpec::eMIPSSubType_mips64r6el, 0xFFFFFFFFu, 0xFFFFFFFFu }, // mips64r6el
Todd Fiala14bbef52014-07-01 23:33:32 +0000305 { ArchSpec::eCore_hexagon_generic , llvm::ELF::EM_HEXAGON, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // HEXAGON
Matthew Gardinerf03e6d842014-09-29 08:02:24 +0000306 { ArchSpec::eCore_kalimba3 , llvm::ELF::EM_CSR_KALIMBA, llvm::Triple::KalimbaSubArch_v3, 0xFFFFFFFFu, 0xFFFFFFFFu }, // KALIMBA
307 { ArchSpec::eCore_kalimba4 , llvm::ELF::EM_CSR_KALIMBA, llvm::Triple::KalimbaSubArch_v4, 0xFFFFFFFFu, 0xFFFFFFFFu }, // KALIMBA
308 { ArchSpec::eCore_kalimba5 , llvm::ELF::EM_CSR_KALIMBA, llvm::Triple::KalimbaSubArch_v5, 0xFFFFFFFFu, 0xFFFFFFFFu } // KALIMBA
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000309};
310
Greg Clayton64195a22011-02-23 00:35:02 +0000311static const ArchDefinition g_elf_arch_def = {
312 eArchTypeELF,
Saleem Abdulrasool28606952014-06-27 05:17:41 +0000313 llvm::array_lengthof(g_elf_arch_entries),
Greg Clayton64195a22011-02-23 00:35:02 +0000314 g_elf_arch_entries,
Greg Clayton64195a22011-02-23 00:35:02 +0000315 "elf",
Greg Clayton41f92322010-06-11 03:25:34 +0000316};
317
Charles Davis237ad972013-08-27 05:04:33 +0000318static const ArchDefinitionEntry g_coff_arch_entries[] =
319{
Zachary Turnerad587ae42014-07-28 16:44:49 +0000320 { 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 +0000321 { ArchSpec::eCore_ppc_generic , llvm::COFF::IMAGE_FILE_MACHINE_POWERPC , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // PowerPC
322 { ArchSpec::eCore_ppc_generic , llvm::COFF::IMAGE_FILE_MACHINE_POWERPCFP, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // PowerPC (with FPU)
323 { ArchSpec::eCore_arm_generic , llvm::COFF::IMAGE_FILE_MACHINE_ARM , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // ARM
Saleem Abdulrasool1108cb32014-03-11 03:09:08 +0000324 { ArchSpec::eCore_arm_armv7 , llvm::COFF::IMAGE_FILE_MACHINE_ARMNT , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // ARMv7
Charles Davis237ad972013-08-27 05:04:33 +0000325 { ArchSpec::eCore_thumb , llvm::COFF::IMAGE_FILE_MACHINE_THUMB , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // ARMv7
326 { ArchSpec::eCore_x86_64_x86_64, llvm::COFF::IMAGE_FILE_MACHINE_AMD64 , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu } // AMD64
327};
328
329static const ArchDefinition g_coff_arch_def = {
330 eArchTypeCOFF,
Saleem Abdulrasool28606952014-06-27 05:17:41 +0000331 llvm::array_lengthof(g_coff_arch_entries),
Charles Davis237ad972013-08-27 05:04:33 +0000332 g_coff_arch_entries,
333 "pe-coff",
334};
335
Greg Clayton64195a22011-02-23 00:35:02 +0000336//===----------------------------------------------------------------------===//
337// Table of all ArchDefinitions
338static const ArchDefinition *g_arch_definitions[] = {
339 &g_macho_arch_def,
Charles Davis237ad972013-08-27 05:04:33 +0000340 &g_elf_arch_def,
341 &g_coff_arch_def
Greg Clayton64195a22011-02-23 00:35:02 +0000342};
Greg Clayton41f92322010-06-11 03:25:34 +0000343
Saleem Abdulrasool28606952014-06-27 05:17:41 +0000344static const size_t k_num_arch_definitions = llvm::array_lengthof(g_arch_definitions);
Greg Clayton64195a22011-02-23 00:35:02 +0000345
346//===----------------------------------------------------------------------===//
347// Static helper functions.
348
349
350// Get the architecture definition for a given object type.
351static const ArchDefinition *
352FindArchDefinition (ArchitectureType arch_type)
353{
354 for (unsigned int i = 0; i < k_num_arch_definitions; ++i)
355 {
356 const ArchDefinition *def = g_arch_definitions[i];
357 if (def->type == arch_type)
358 return def;
359 }
360 return NULL;
361}
362
363// Get an architecture definition by name.
364static const CoreDefinition *
365FindCoreDefinition (llvm::StringRef name)
366{
Greg Clayton56b79682014-07-23 18:12:06 +0000367 for (unsigned int i = 0; i < llvm::array_lengthof(g_core_definitions); ++i)
Greg Clayton64195a22011-02-23 00:35:02 +0000368 {
369 if (name.equals_lower(g_core_definitions[i].name))
370 return &g_core_definitions[i];
371 }
372 return NULL;
373}
374
375static inline const CoreDefinition *
376FindCoreDefinition (ArchSpec::Core core)
377{
Greg Clayton56b79682014-07-23 18:12:06 +0000378 if (core >= 0 && core < llvm::array_lengthof(g_core_definitions))
Greg Clayton64195a22011-02-23 00:35:02 +0000379 return &g_core_definitions[core];
380 return NULL;
381}
382
383// Get a definition entry by cpu type and subtype.
384static const ArchDefinitionEntry *
385FindArchDefinitionEntry (const ArchDefinition *def, uint32_t cpu, uint32_t sub)
386{
387 if (def == NULL)
388 return NULL;
389
Greg Clayton64195a22011-02-23 00:35:02 +0000390 const ArchDefinitionEntry *entries = def->entries;
391 for (size_t i = 0; i < def->num_entries; ++i)
392 {
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000393 if (entries[i].cpu == (cpu & entries[i].cpu_mask))
394 if (entries[i].sub == (sub & entries[i].sub_mask))
395 return &entries[i];
Greg Clayton64195a22011-02-23 00:35:02 +0000396 }
397 return NULL;
398}
399
400static const ArchDefinitionEntry *
401FindArchDefinitionEntry (const ArchDefinition *def, ArchSpec::Core core)
402{
403 if (def == NULL)
404 return NULL;
405
406 const ArchDefinitionEntry *entries = def->entries;
407 for (size_t i = 0; i < def->num_entries; ++i)
408 {
409 if (entries[i].core == core)
410 return &entries[i];
411 }
412 return NULL;
413}
414
415//===----------------------------------------------------------------------===//
416// Constructors and destructors.
417
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000418ArchSpec::ArchSpec() :
Greg Clayton514487e2011-02-15 21:59:32 +0000419 m_triple (),
Greg Clayton64195a22011-02-23 00:35:02 +0000420 m_core (kCore_invalid),
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000421 m_byte_order (eByteOrderInvalid),
Pavel Labath07695bd2015-07-16 13:11:34 +0000422 m_flags (0),
423 m_distribution_id ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424{
425}
426
Greg Claytoneb0103f2011-04-07 22:46:35 +0000427ArchSpec::ArchSpec (const char *triple_cstr, Platform *platform) :
Greg Clayton514487e2011-02-15 21:59:32 +0000428 m_triple (),
Greg Clayton64195a22011-02-23 00:35:02 +0000429 m_core (kCore_invalid),
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000430 m_byte_order (eByteOrderInvalid),
Pavel Labath07695bd2015-07-16 13:11:34 +0000431 m_flags (0),
432 m_distribution_id ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000433{
Greg Clayton64195a22011-02-23 00:35:02 +0000434 if (triple_cstr)
Greg Claytoneb0103f2011-04-07 22:46:35 +0000435 SetTriple(triple_cstr, platform);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000436}
437
Greg Clayton70512312012-05-08 01:45:38 +0000438
439ArchSpec::ArchSpec (const char *triple_cstr) :
440 m_triple (),
441 m_core (kCore_invalid),
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000442 m_byte_order (eByteOrderInvalid),
Pavel Labath07695bd2015-07-16 13:11:34 +0000443 m_flags (0),
444 m_distribution_id ()
Greg Clayton70512312012-05-08 01:45:38 +0000445{
446 if (triple_cstr)
447 SetTriple(triple_cstr);
448}
449
Greg Clayton64195a22011-02-23 00:35:02 +0000450ArchSpec::ArchSpec(const llvm::Triple &triple) :
Greg Clayton514487e2011-02-15 21:59:32 +0000451 m_triple (),
Greg Clayton64195a22011-02-23 00:35:02 +0000452 m_core (kCore_invalid),
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000453 m_byte_order (eByteOrderInvalid),
Pavel Labath07695bd2015-07-16 13:11:34 +0000454 m_flags (0),
455 m_distribution_id ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000456{
Greg Clayton64195a22011-02-23 00:35:02 +0000457 SetTriple(triple);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000458}
459
Greg Claytone0d378b2011-03-24 21:19:54 +0000460ArchSpec::ArchSpec (ArchitectureType arch_type, uint32_t cpu, uint32_t subtype) :
Greg Clayton64195a22011-02-23 00:35:02 +0000461 m_triple (),
462 m_core (kCore_invalid),
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000463 m_byte_order (eByteOrderInvalid),
Pavel Labath07695bd2015-07-16 13:11:34 +0000464 m_flags (0),
465 m_distribution_id ()
Greg Clayton64195a22011-02-23 00:35:02 +0000466{
467 SetArchitecture (arch_type, cpu, subtype);
468}
469
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470ArchSpec::~ArchSpec()
471{
472}
473
Greg Clayton64195a22011-02-23 00:35:02 +0000474//===----------------------------------------------------------------------===//
475// Assignment and initialization.
476
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477const ArchSpec&
478ArchSpec::operator= (const ArchSpec& rhs)
479{
480 if (this != &rhs)
481 {
Greg Clayton514487e2011-02-15 21:59:32 +0000482 m_triple = rhs.m_triple;
Greg Clayton64195a22011-02-23 00:35:02 +0000483 m_core = rhs.m_core;
Greg Clayton514487e2011-02-15 21:59:32 +0000484 m_byte_order = rhs.m_byte_order;
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000485 m_distribution_id = rhs.m_distribution_id;
Jaydeep Patil501a7812015-07-16 03:51:55 +0000486 m_flags = rhs.m_flags;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487 }
488 return *this;
489}
490
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000491void
492ArchSpec::Clear()
493{
Greg Clayton514487e2011-02-15 21:59:32 +0000494 m_triple = llvm::Triple();
Greg Clayton64195a22011-02-23 00:35:02 +0000495 m_core = kCore_invalid;
496 m_byte_order = eByteOrderInvalid;
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000497 m_distribution_id.Clear ();
Jaydeep Patil501a7812015-07-16 03:51:55 +0000498 m_flags = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000499}
500
Greg Clayton64195a22011-02-23 00:35:02 +0000501//===----------------------------------------------------------------------===//
502// Predicates.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000503
Greg Clayton41f92322010-06-11 03:25:34 +0000504
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505const char *
Greg Clayton64195a22011-02-23 00:35:02 +0000506ArchSpec::GetArchitectureName () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000507{
Greg Clayton64195a22011-02-23 00:35:02 +0000508 const CoreDefinition *core_def = FindCoreDefinition (m_core);
509 if (core_def)
510 return core_def->name;
511 return "unknown";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000512}
513
Greg Clayton64195a22011-02-23 00:35:02 +0000514uint32_t
515ArchSpec::GetMachOCPUType () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000516{
Greg Clayton64195a22011-02-23 00:35:02 +0000517 const CoreDefinition *core_def = FindCoreDefinition (m_core);
518 if (core_def)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519 {
Greg Clayton64195a22011-02-23 00:35:02 +0000520 const ArchDefinitionEntry *arch_def = FindArchDefinitionEntry (&g_macho_arch_def, core_def->core);
521 if (arch_def)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000522 {
Greg Clayton64195a22011-02-23 00:35:02 +0000523 return arch_def->cpu;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000524 }
525 }
Greg Clayton64195a22011-02-23 00:35:02 +0000526 return LLDB_INVALID_CPUTYPE;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000527}
528
Greg Clayton64195a22011-02-23 00:35:02 +0000529uint32_t
530ArchSpec::GetMachOCPUSubType () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531{
Greg Clayton64195a22011-02-23 00:35:02 +0000532 const CoreDefinition *core_def = FindCoreDefinition (m_core);
533 if (core_def)
534 {
535 const ArchDefinitionEntry *arch_def = FindArchDefinitionEntry (&g_macho_arch_def, core_def->core);
536 if (arch_def)
537 {
Greg Clayton1cb64962011-03-24 04:28:38 +0000538 return arch_def->sub;
Greg Clayton64195a22011-02-23 00:35:02 +0000539 }
540 }
541 return LLDB_INVALID_CPUTYPE;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542}
543
Matthew Gardinere77b2942014-09-01 09:06:03 +0000544uint32_t
545ArchSpec::GetDataByteSize () const
546{
547 switch (m_core)
548 {
549 case eCore_kalimba3:
Matthew Gardinerf03e6d842014-09-29 08:02:24 +0000550 return 4;
Matthew Gardinere77b2942014-09-01 09:06:03 +0000551 case eCore_kalimba4:
552 return 1;
553 case eCore_kalimba5:
Matthew Gardinerf03e6d842014-09-29 08:02:24 +0000554 return 4;
Matthew Gardinere77b2942014-09-01 09:06:03 +0000555 default:
556 return 1;
557 }
558 return 1;
559}
560
561uint32_t
562ArchSpec::GetCodeByteSize () const
563{
564 switch (m_core)
565 {
566 case eCore_kalimba3:
567 return 4;
568 case eCore_kalimba4:
569 return 1;
570 case eCore_kalimba5:
571 return 1;
572 default:
573 return 1;
574 }
575 return 1;
576}
577
Greg Clayton64195a22011-02-23 00:35:02 +0000578llvm::Triple::ArchType
579ArchSpec::GetMachine () const
580{
581 const CoreDefinition *core_def = FindCoreDefinition (m_core);
582 if (core_def)
583 return core_def->machine;
584
585 return llvm::Triple::UnknownArch;
586}
587
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000588const ConstString&
589ArchSpec::GetDistributionId () const
590{
591 return m_distribution_id;
592}
593
594void
595ArchSpec::SetDistributionId (const char* distribution_id)
596{
597 m_distribution_id.SetCString (distribution_id);
598}
599
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000600uint32_t
601ArchSpec::GetAddressByteSize() const
602{
Greg Clayton64195a22011-02-23 00:35:02 +0000603 const CoreDefinition *core_def = FindCoreDefinition (m_core);
604 if (core_def)
Mohit K. Bhakkad9514a382015-09-09 10:32:20 +0000605 {
606 if (core_def->machine == llvm::Triple::mips64 || core_def->machine == llvm::Triple::mips64el)
607 {
608 // For N32/O32 applications Address size is 4 bytes.
609 if (m_flags & (eMIPSABI_N32 | eMIPSABI_O32))
610 return 4;
611 }
612 return core_def->addr_byte_size;
613 }
Greg Clayton41f92322010-06-11 03:25:34 +0000614 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000615}
616
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000617ByteOrder
618ArchSpec::GetDefaultEndian () const
619{
Greg Clayton64195a22011-02-23 00:35:02 +0000620 const CoreDefinition *core_def = FindCoreDefinition (m_core);
621 if (core_def)
622 return core_def->default_byte_order;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000623 return eByteOrderInvalid;
624}
625
Tamas Berghammerdccbfaf2015-03-31 10:21:50 +0000626bool
627ArchSpec::CharIsSignedByDefault () const
628{
629 switch (m_triple.getArch()) {
630 default:
631 return true;
632
633 case llvm::Triple::aarch64:
634 case llvm::Triple::aarch64_be:
635 case llvm::Triple::arm:
636 case llvm::Triple::armeb:
637 case llvm::Triple::thumb:
638 case llvm::Triple::thumbeb:
639 return m_triple.isOSDarwin() || m_triple.isOSWindows();
640
641 case llvm::Triple::ppc:
642 case llvm::Triple::ppc64:
643 return m_triple.isOSDarwin();
644
645 case llvm::Triple::ppc64le:
646 case llvm::Triple::systemz:
647 case llvm::Triple::xcore:
648 return false;
649 }
650}
651
Greg Clayton64195a22011-02-23 00:35:02 +0000652lldb::ByteOrder
653ArchSpec::GetByteOrder () const
654{
655 if (m_byte_order == eByteOrderInvalid)
656 return GetDefaultEndian();
657 return m_byte_order;
658}
659
660//===----------------------------------------------------------------------===//
661// Mutators.
662
663bool
664ArchSpec::SetTriple (const llvm::Triple &triple)
665{
666 m_triple = triple;
667
668 llvm::StringRef arch_name (m_triple.getArchName());
669 const CoreDefinition *core_def = FindCoreDefinition (arch_name);
670 if (core_def)
671 {
672 m_core = core_def->core;
Greg Claytoneb0103f2011-04-07 22:46:35 +0000673 // Set the byte order to the default byte order for an architecture.
674 // This can be modified if needed for cases when cores handle both
675 // big and little endian
676 m_byte_order = core_def->default_byte_order;
Greg Clayton64195a22011-02-23 00:35:02 +0000677 }
678 else
679 {
680 Clear();
681 }
682
683
684 return IsValid();
685}
686
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000687static bool
688ParseMachCPUDashSubtypeTriple (const char *triple_cstr, ArchSpec &arch)
689{
690 // Accept "12-10" or "12.10" as cpu type/subtype
691 if (isdigit(triple_cstr[0]))
692 {
693 char *end = NULL;
694 errno = 0;
Greg Claytonc7bece562013-01-25 18:06:21 +0000695 uint32_t cpu = (uint32_t)::strtoul (triple_cstr, &end, 0);
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000696 if (errno == 0 && cpu != 0 && end && ((*end == '-') || (*end == '.')))
697 {
698 errno = 0;
Greg Claytonc7bece562013-01-25 18:06:21 +0000699 uint32_t sub = (uint32_t)::strtoul (end + 1, &end, 0);
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000700 if (errno == 0 && end && ((*end == '-') || (*end == '.') || (*end == '\0')))
701 {
702 if (arch.SetArchitecture (eArchTypeMachO, cpu, sub))
703 {
704 if (*end == '-')
705 {
706 llvm::StringRef vendor_os (end + 1);
707 size_t dash_pos = vendor_os.find('-');
708 if (dash_pos != llvm::StringRef::npos)
709 {
710 llvm::StringRef vendor_str(vendor_os.substr(0, dash_pos));
711 arch.GetTriple().setVendorName(vendor_str);
712 const size_t vendor_start_pos = dash_pos+1;
Greg Claytonc7bece562013-01-25 18:06:21 +0000713 dash_pos = vendor_os.find('-', vendor_start_pos);
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000714 if (dash_pos == llvm::StringRef::npos)
715 {
716 if (vendor_start_pos < vendor_os.size())
717 arch.GetTriple().setOSName(vendor_os.substr(vendor_start_pos));
718 }
719 else
720 {
721 arch.GetTriple().setOSName(vendor_os.substr(vendor_start_pos, dash_pos - vendor_start_pos));
722 }
723 }
724 }
725 return true;
726 }
727 }
728 }
729 }
730 return false;
731}
Greg Clayton64195a22011-02-23 00:35:02 +0000732bool
Greg Clayton70512312012-05-08 01:45:38 +0000733ArchSpec::SetTriple (const char *triple_cstr)
Greg Clayton64195a22011-02-23 00:35:02 +0000734{
Greg Clayton23aca092011-08-12 23:32:52 +0000735 if (triple_cstr && triple_cstr[0])
Greg Clayton64195a22011-02-23 00:35:02 +0000736 {
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000737 if (ParseMachCPUDashSubtypeTriple (triple_cstr, *this))
738 return true;
739
Greg Clayton64195a22011-02-23 00:35:02 +0000740 llvm::StringRef triple_stref (triple_cstr);
741 if (triple_stref.startswith (LLDB_ARCH_DEFAULT))
742 {
743 // Special case for the current host default architectures...
744 if (triple_stref.equals (LLDB_ARCH_DEFAULT_32BIT))
Zachary Turner13b18262014-08-20 16:42:51 +0000745 *this = HostInfo::GetArchitecture(HostInfo::eArchKind32);
Greg Clayton64195a22011-02-23 00:35:02 +0000746 else if (triple_stref.equals (LLDB_ARCH_DEFAULT_64BIT))
Zachary Turner13b18262014-08-20 16:42:51 +0000747 *this = HostInfo::GetArchitecture(HostInfo::eArchKind64);
Greg Clayton64195a22011-02-23 00:35:02 +0000748 else if (triple_stref.equals (LLDB_ARCH_DEFAULT))
Zachary Turner13b18262014-08-20 16:42:51 +0000749 *this = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
Greg Clayton64195a22011-02-23 00:35:02 +0000750 }
751 else
752 {
753 std::string normalized_triple_sstr (llvm::Triple::normalize(triple_stref));
754 triple_stref = normalized_triple_sstr;
Greg Clayton70512312012-05-08 01:45:38 +0000755 SetTriple (llvm::Triple (triple_stref));
756 }
757 }
758 else
759 Clear();
760 return IsValid();
761}
762
763bool
764ArchSpec::SetTriple (const char *triple_cstr, Platform *platform)
765{
766 if (triple_cstr && triple_cstr[0])
767 {
Greg Clayton9e6cffc2012-09-19 22:25:17 +0000768 if (ParseMachCPUDashSubtypeTriple (triple_cstr, *this))
769 return true;
770
Greg Clayton70512312012-05-08 01:45:38 +0000771 llvm::StringRef triple_stref (triple_cstr);
772 if (triple_stref.startswith (LLDB_ARCH_DEFAULT))
773 {
774 // Special case for the current host default architectures...
775 if (triple_stref.equals (LLDB_ARCH_DEFAULT_32BIT))
Zachary Turner13b18262014-08-20 16:42:51 +0000776 *this = HostInfo::GetArchitecture(HostInfo::eArchKind32);
Greg Clayton70512312012-05-08 01:45:38 +0000777 else if (triple_stref.equals (LLDB_ARCH_DEFAULT_64BIT))
Zachary Turner13b18262014-08-20 16:42:51 +0000778 *this = HostInfo::GetArchitecture(HostInfo::eArchKind64);
Greg Clayton70512312012-05-08 01:45:38 +0000779 else if (triple_stref.equals (LLDB_ARCH_DEFAULT))
Zachary Turner13b18262014-08-20 16:42:51 +0000780 *this = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
Greg Clayton70512312012-05-08 01:45:38 +0000781 }
782 else
783 {
784 ArchSpec raw_arch (triple_cstr);
785
786 std::string normalized_triple_sstr (llvm::Triple::normalize(triple_stref));
787 triple_stref = normalized_triple_sstr;
Greg Claytoneb0103f2011-04-07 22:46:35 +0000788 llvm::Triple normalized_triple (triple_stref);
789
790 const bool os_specified = normalized_triple.getOSName().size() > 0;
791 const bool vendor_specified = normalized_triple.getVendorName().size() > 0;
792 const bool env_specified = normalized_triple.getEnvironmentName().size() > 0;
793
794 // If we got an arch only, then default the vendor, os, environment
795 // to match the platform if one is supplied
796 if (!(os_specified || vendor_specified || env_specified))
797 {
798 if (platform)
799 {
800 // If we were given a platform, use the platform's system
801 // architecture. If this is not available (might not be
802 // connected) use the first supported architecture.
Greg Clayton70512312012-05-08 01:45:38 +0000803 ArchSpec compatible_arch;
Greg Clayton1e0c8842013-01-11 20:49:54 +0000804 if (platform->IsCompatibleArchitecture (raw_arch, false, &compatible_arch))
Greg Claytoneb0103f2011-04-07 22:46:35 +0000805 {
Greg Clayton70512312012-05-08 01:45:38 +0000806 if (compatible_arch.IsValid())
807 {
808 const llvm::Triple &compatible_triple = compatible_arch.GetTriple();
809 if (!vendor_specified)
810 normalized_triple.setVendor(compatible_triple.getVendor());
811 if (!os_specified)
812 normalized_triple.setOS(compatible_triple.getOS());
813 if (!env_specified && compatible_triple.getEnvironmentName().size())
814 normalized_triple.setEnvironment(compatible_triple.getEnvironment());
815 }
Greg Claytoneb0103f2011-04-07 22:46:35 +0000816 }
Greg Clayton70512312012-05-08 01:45:38 +0000817 else
Greg Claytoneb0103f2011-04-07 22:46:35 +0000818 {
Greg Clayton70512312012-05-08 01:45:38 +0000819 *this = raw_arch;
820 return IsValid();
Greg Claytoneb0103f2011-04-07 22:46:35 +0000821 }
822 }
823 else
824 {
825 // No platform specified, fall back to the host system for
826 // the default vendor, os, and environment.
Sean Callananbfb237bc2011-11-04 22:46:46 +0000827 llvm::Triple host_triple(llvm::sys::getDefaultTargetTriple());
Greg Clayton70512312012-05-08 01:45:38 +0000828 if (!vendor_specified)
829 normalized_triple.setVendor(host_triple.getVendor());
830 if (!vendor_specified)
831 normalized_triple.setOS(host_triple.getOS());
832 if (!env_specified && host_triple.getEnvironmentName().size())
833 normalized_triple.setEnvironment(host_triple.getEnvironment());
Greg Claytoneb0103f2011-04-07 22:46:35 +0000834 }
835 }
836 SetTriple (normalized_triple);
Greg Clayton64195a22011-02-23 00:35:02 +0000837 }
838 }
839 else
840 Clear();
841 return IsValid();
842}
843
Zachary Turner5e6f4522015-01-22 18:59:05 +0000844void
845ArchSpec::MergeFrom(const ArchSpec &other)
846{
Todd Fiala7df337f2015-10-13 23:41:19 +0000847 if (TripleVendorIsUnspecifiedUnknown() && !other.TripleVendorIsUnspecifiedUnknown())
Zachary Turner5e6f4522015-01-22 18:59:05 +0000848 GetTriple().setVendor(other.GetTriple().getVendor());
Todd Fiala7df337f2015-10-13 23:41:19 +0000849 if (TripleOSIsUnspecifiedUnknown() && !other.TripleOSIsUnspecifiedUnknown())
Zachary Turner5e6f4522015-01-22 18:59:05 +0000850 GetTriple().setOS(other.GetTriple().getOS());
851 if (GetTriple().getArch() == llvm::Triple::UnknownArch)
852 GetTriple().setArch(other.GetTriple().getArch());
Jason Molenda03fe45e2015-11-06 01:43:36 +0000853 if (GetTriple().getEnvironment() == llvm::Triple::UnknownEnvironment && !TripleVendorWasSpecified())
854 {
855 if (other.TripleVendorWasSpecified())
856 GetTriple().setEnvironment(other.GetTriple().getEnvironment());
857 }
Zachary Turner5e6f4522015-01-22 18:59:05 +0000858}
859
Greg Clayton64195a22011-02-23 00:35:02 +0000860bool
Ed Mastef6a13122015-06-05 13:03:08 +0000861ArchSpec::SetArchitecture (ArchitectureType arch_type, uint32_t cpu, uint32_t sub, uint32_t os)
Greg Clayton64195a22011-02-23 00:35:02 +0000862{
863 m_core = kCore_invalid;
864 bool update_triple = true;
865 const ArchDefinition *arch_def = FindArchDefinition(arch_type);
866 if (arch_def)
867 {
868 const ArchDefinitionEntry *arch_def_entry = FindArchDefinitionEntry (arch_def, cpu, sub);
869 if (arch_def_entry)
870 {
871 const CoreDefinition *core_def = FindCoreDefinition (arch_def_entry->core);
872 if (core_def)
873 {
874 m_core = core_def->core;
875 update_triple = false;
Greg Clayton593577a2011-09-21 03:57:31 +0000876 // Always use the architecture name because it might be more descriptive
877 // than the architecture enum ("armv7" -> llvm::Triple::arm).
878 m_triple.setArchName(llvm::StringRef(core_def->name));
Greg Clayton64195a22011-02-23 00:35:02 +0000879 if (arch_type == eArchTypeMachO)
880 {
881 m_triple.setVendor (llvm::Triple::Apple);
Greg Claytona3a6c122014-07-29 18:04:57 +0000882
Jason Molenda03fe45e2015-11-06 01:43:36 +0000883 // Don't set the OS. It could be simulator, macosx, ios, watchos, tvos. We could
884 // get close with the cpu type - but we can't get it right all of the time. Better
885 // to leave this unset so other sections of code will set it when they have more
886 // information.
887 // NB: don't call m_triple.setOS (llvm::Triple::UnknownOS). That sets the OSName to
888 // "unknown" and the ArchSpec::TripleVendorWasSpecified() method says that any
889 // OSName setting means it was specified.
Greg Clayton64195a22011-02-23 00:35:02 +0000890 }
Ed Mastef6a13122015-06-05 13:03:08 +0000891 else if (arch_type == eArchTypeELF)
892 {
Ed Mastef6a13122015-06-05 13:03:08 +0000893 switch (os)
894 {
Tamas Berghammered1fa202015-07-07 09:11:59 +0000895 case llvm::ELF::ELFOSABI_AIX: m_triple.setOS (llvm::Triple::OSType::AIX); break;
896 case llvm::ELF::ELFOSABI_FREEBSD: m_triple.setOS (llvm::Triple::OSType::FreeBSD); break;
897 case llvm::ELF::ELFOSABI_GNU: m_triple.setOS (llvm::Triple::OSType::Linux); break;
898 case llvm::ELF::ELFOSABI_NETBSD: m_triple.setOS (llvm::Triple::OSType::NetBSD); break;
899 case llvm::ELF::ELFOSABI_OPENBSD: m_triple.setOS (llvm::Triple::OSType::OpenBSD); break;
900 case llvm::ELF::ELFOSABI_SOLARIS: m_triple.setOS (llvm::Triple::OSType::Solaris); break;
Ed Mastef6a13122015-06-05 13:03:08 +0000901 }
Ed Mastef6a13122015-06-05 13:03:08 +0000902 }
Jason Molenda03fe45e2015-11-06 01:43:36 +0000903 else
904 {
905 m_triple.setVendor (llvm::Triple::UnknownVendor);
906 m_triple.setOS (llvm::Triple::UnknownOS);
907 }
Greg Clayton593577a2011-09-21 03:57:31 +0000908 // Fall back onto setting the machine type if the arch by name failed...
909 if (m_triple.getArch () == llvm::Triple::UnknownArch)
910 m_triple.setArch (core_def->machine);
Greg Clayton64195a22011-02-23 00:35:02 +0000911 }
912 }
913 }
914 CoreUpdated(update_triple);
915 return IsValid();
916}
917
Greg Clayton357132e2011-03-26 19:14:58 +0000918uint32_t
919ArchSpec::GetMinimumOpcodeByteSize() const
Greg Clayton64195a22011-02-23 00:35:02 +0000920{
Greg Clayton357132e2011-03-26 19:14:58 +0000921 const CoreDefinition *core_def = FindCoreDefinition (m_core);
922 if (core_def)
923 return core_def->min_opcode_byte_size;
924 return 0;
925}
926
927uint32_t
928ArchSpec::GetMaximumOpcodeByteSize() const
929{
930 const CoreDefinition *core_def = FindCoreDefinition (m_core);
931 if (core_def)
932 return core_def->max_opcode_byte_size;
933 return 0;
Greg Clayton64195a22011-02-23 00:35:02 +0000934}
935
Jason Molendaba813dc2012-11-04 03:20:05 +0000936bool
937ArchSpec::IsExactMatch (const ArchSpec& rhs) const
938{
Sean Callananbf4b7be2012-12-13 22:07:14 +0000939 return IsEqualTo (rhs, true);
Jason Molendaba813dc2012-11-04 03:20:05 +0000940}
941
942bool
943ArchSpec::IsCompatibleMatch (const ArchSpec& rhs) const
944{
Sean Callananbf4b7be2012-12-13 22:07:14 +0000945 return IsEqualTo (rhs, false);
Jason Molendaba813dc2012-11-04 03:20:05 +0000946}
947
948bool
Sean Callananbf4b7be2012-12-13 22:07:14 +0000949ArchSpec::IsEqualTo (const ArchSpec& rhs, bool exact_match) const
Jason Molendaba813dc2012-11-04 03:20:05 +0000950{
Todd Fialaa9ddb0e2014-01-18 03:02:39 +0000951 // explicitly ignoring m_distribution_id in this method.
952
Jason Molendaba813dc2012-11-04 03:20:05 +0000953 if (GetByteOrder() != rhs.GetByteOrder())
954 return false;
955
956 const ArchSpec::Core lhs_core = GetCore ();
957 const ArchSpec::Core rhs_core = rhs.GetCore ();
958
959 const bool core_match = cores_match (lhs_core, rhs_core, true, exact_match);
960
961 if (core_match)
962 {
963 const llvm::Triple &lhs_triple = GetTriple();
964 const llvm::Triple &rhs_triple = rhs.GetTriple();
965
966 const llvm::Triple::VendorType lhs_triple_vendor = lhs_triple.getVendor();
967 const llvm::Triple::VendorType rhs_triple_vendor = rhs_triple.getVendor();
968 if (lhs_triple_vendor != rhs_triple_vendor)
969 {
Jason Molenda03fe45e2015-11-06 01:43:36 +0000970 const bool rhs_vendor_specified = rhs.TripleVendorWasSpecified();
971 const bool lhs_vendor_specified = TripleVendorWasSpecified();
972 // Both architectures had the vendor specified, so if they aren't
973 // equal then we return false
974 if (rhs_vendor_specified && lhs_vendor_specified)
975 return false;
Jason Molendaba813dc2012-11-04 03:20:05 +0000976
977 // Only fail if both vendor types are not unknown
978 if (lhs_triple_vendor != llvm::Triple::UnknownVendor &&
979 rhs_triple_vendor != llvm::Triple::UnknownVendor)
980 return false;
981 }
982
983 const llvm::Triple::OSType lhs_triple_os = lhs_triple.getOS();
984 const llvm::Triple::OSType rhs_triple_os = rhs_triple.getOS();
985 if (lhs_triple_os != rhs_triple_os)
986 {
Jason Molenda03fe45e2015-11-06 01:43:36 +0000987 const bool rhs_os_specified = rhs.TripleOSWasSpecified();
988 const bool lhs_os_specified = TripleOSWasSpecified();
989 // Both architectures had the OS specified, so if they aren't
990 // equal then we return false
991 if (rhs_os_specified && lhs_os_specified)
992 return false;
Greg Clayton7ab7f892014-05-29 21:33:45 +0000993
Greg Clayton3f19ada2014-07-10 23:33:37 +0000994 // Only fail if both os types are not unknown
995 if (lhs_triple_os != llvm::Triple::UnknownOS &&
996 rhs_triple_os != llvm::Triple::UnknownOS)
997 return false;
Jason Molendaba813dc2012-11-04 03:20:05 +0000998 }
999
1000 const llvm::Triple::EnvironmentType lhs_triple_env = lhs_triple.getEnvironment();
1001 const llvm::Triple::EnvironmentType rhs_triple_env = rhs_triple.getEnvironment();
1002
1003 if (lhs_triple_env != rhs_triple_env)
1004 {
1005 // Only fail if both environment types are not unknown
1006 if (lhs_triple_env != llvm::Triple::UnknownEnvironment &&
1007 rhs_triple_env != llvm::Triple::UnknownEnvironment)
1008 return false;
1009 }
1010 return true;
1011 }
1012 return false;
1013}
1014
Greg Clayton64195a22011-02-23 00:35:02 +00001015//===----------------------------------------------------------------------===//
1016// Helper methods.
1017
1018void
1019ArchSpec::CoreUpdated (bool update_triple)
1020{
1021 const CoreDefinition *core_def = FindCoreDefinition (m_core);
1022 if (core_def)
1023 {
1024 if (update_triple)
1025 m_triple = llvm::Triple(core_def->name, "unknown", "unknown");
1026 m_byte_order = core_def->default_byte_order;
1027 }
1028 else
1029 {
1030 if (update_triple)
1031 m_triple = llvm::Triple();
1032 m_byte_order = eByteOrderInvalid;
1033 }
1034}
1035
1036//===----------------------------------------------------------------------===//
1037// Operators.
1038
Greg Clayton70512312012-05-08 01:45:38 +00001039static bool
Jason Molendaba813dc2012-11-04 03:20:05 +00001040cores_match (const ArchSpec::Core core1, const ArchSpec::Core core2, bool try_inverse, bool enforce_exact_match)
Greg Clayton70512312012-05-08 01:45:38 +00001041{
Jason Molendaba813dc2012-11-04 03:20:05 +00001042 if (core1 == core2)
1043 return true;
1044
Greg Clayton70512312012-05-08 01:45:38 +00001045 switch (core1)
1046 {
Greg Clayton70512312012-05-08 01:45:38 +00001047 case ArchSpec::kCore_any:
1048 return true;
1049
Greg Clayton44362e02014-07-12 00:11:34 +00001050 case ArchSpec::eCore_arm_generic:
1051 if (enforce_exact_match)
1052 break;
1053 // Fall through to case below
Greg Clayton70512312012-05-08 01:45:38 +00001054 case ArchSpec::kCore_arm_any:
1055 if (core2 >= ArchSpec::kCore_arm_first && core2 <= ArchSpec::kCore_arm_last)
1056 return true;
1057 if (core2 >= ArchSpec::kCore_thumb_first && core2 <= ArchSpec::kCore_thumb_last)
1058 return true;
1059 if (core2 == ArchSpec::kCore_arm_any)
1060 return true;
1061 break;
Sylvestre Ledru1c9e0642014-08-18 14:53:42 +00001062
Greg Clayton70512312012-05-08 01:45:38 +00001063 case ArchSpec::kCore_x86_32_any:
1064 if ((core2 >= ArchSpec::kCore_x86_32_first && core2 <= ArchSpec::kCore_x86_32_last) || (core2 == ArchSpec::kCore_x86_32_any))
1065 return true;
1066 break;
Zachary Turnerad587ae42014-07-28 16:44:49 +00001067
1068 case ArchSpec::kCore_x86_64_any:
1069 if ((core2 >= ArchSpec::kCore_x86_64_first && core2 <= ArchSpec::kCore_x86_64_last) || (core2 == ArchSpec::kCore_x86_64_any))
1070 return true;
Sylvestre Ledru1c9e0642014-08-18 14:53:42 +00001071 break;
Zachary Turnerad587ae42014-07-28 16:44:49 +00001072
Greg Clayton70512312012-05-08 01:45:38 +00001073 case ArchSpec::kCore_ppc_any:
1074 if ((core2 >= ArchSpec::kCore_ppc_first && core2 <= ArchSpec::kCore_ppc_last) || (core2 == ArchSpec::kCore_ppc_any))
1075 return true;
1076 break;
Sylvestre Ledru1c9e0642014-08-18 14:53:42 +00001077
Greg Clayton70512312012-05-08 01:45:38 +00001078 case ArchSpec::kCore_ppc64_any:
1079 if ((core2 >= ArchSpec::kCore_ppc64_first && core2 <= ArchSpec::kCore_ppc64_last) || (core2 == ArchSpec::kCore_ppc64_any))
1080 return true;
1081 break;
1082
Jason Molendaa3a04522013-09-27 23:21:54 +00001083 case ArchSpec::eCore_arm_armv6m:
1084 if (!enforce_exact_match)
1085 {
Greg Clayton44362e02014-07-12 00:11:34 +00001086 if (core2 == ArchSpec::eCore_arm_generic)
1087 return true;
Jason Molendaa3a04522013-09-27 23:21:54 +00001088 try_inverse = false;
Jason Molendac7cda272013-09-27 23:29:10 +00001089 if (core2 == ArchSpec::eCore_arm_armv7)
Jason Molendaa3a04522013-09-27 23:21:54 +00001090 return true;
Jason Molendad607afd2015-06-25 22:37:57 +00001091 if (core2 == ArchSpec::eCore_arm_armv6m)
1092 return true;
Jason Molendaa3a04522013-09-27 23:21:54 +00001093 }
Sylvestre Ledru1c9e0642014-08-18 14:53:42 +00001094 break;
Deepak Panickal6d3df422014-02-19 11:16:46 +00001095
1096 case ArchSpec::kCore_hexagon_any:
1097 if ((core2 >= ArchSpec::kCore_hexagon_first && core2 <= ArchSpec::kCore_hexagon_last) || (core2 == ArchSpec::kCore_hexagon_any))
1098 return true;
Jason Molendaa3a04522013-09-27 23:21:54 +00001099 break;
1100
Jason Molenda8825c5c2015-10-08 21:48:35 +00001101 // v. https://en.wikipedia.org/wiki/ARM_Cortex-M#Silicon_customization
1102 // Cortex-M0 - ARMv6-M - armv6m
1103 // Cortex-M3 - ARMv7-M - armv7m
1104 // Cortex-M4 - ARMv7E-M - armv7em
Jason Molenda7a1559c2013-03-08 01:20:17 +00001105 case ArchSpec::eCore_arm_armv7em:
Jason Molendad607afd2015-06-25 22:37:57 +00001106 if (!enforce_exact_match)
1107 {
1108 if (core2 == ArchSpec::eCore_arm_generic)
1109 return true;
1110 if (core2 == ArchSpec::eCore_arm_armv7m)
1111 return true;
1112 if (core2 == ArchSpec::eCore_arm_armv6m)
1113 return true;
1114 if (core2 == ArchSpec::eCore_arm_armv7)
1115 return true;
1116 try_inverse = true;
1117 }
1118 break;
1119
Jason Molenda8825c5c2015-10-08 21:48:35 +00001120 // v. https://en.wikipedia.org/wiki/ARM_Cortex-M#Silicon_customization
1121 // Cortex-M0 - ARMv6-M - armv6m
1122 // Cortex-M3 - ARMv7-M - armv7m
1123 // Cortex-M4 - ARMv7E-M - armv7em
Jason Molendad607afd2015-06-25 22:37:57 +00001124 case ArchSpec::eCore_arm_armv7m:
1125 if (!enforce_exact_match)
1126 {
1127 if (core2 == ArchSpec::eCore_arm_generic)
1128 return true;
1129 if (core2 == ArchSpec::eCore_arm_armv6m)
1130 return true;
1131 if (core2 == ArchSpec::eCore_arm_armv7)
1132 return true;
1133 if (core2 == ArchSpec::eCore_arm_armv7em)
1134 return true;
1135 try_inverse = true;
1136 }
1137 break;
1138
Johnny Chen1083b0d2012-08-28 22:53:40 +00001139 case ArchSpec::eCore_arm_armv7f:
1140 case ArchSpec::eCore_arm_armv7k:
1141 case ArchSpec::eCore_arm_armv7s:
Jason Molendaba813dc2012-11-04 03:20:05 +00001142 if (!enforce_exact_match)
1143 {
Greg Clayton44362e02014-07-12 00:11:34 +00001144 if (core2 == ArchSpec::eCore_arm_generic)
1145 return true;
Jason Molendaba813dc2012-11-04 03:20:05 +00001146 if (core2 == ArchSpec::eCore_arm_armv7)
1147 return true;
Greg Clayton44362e02014-07-12 00:11:34 +00001148 try_inverse = false;
Jason Molendaba813dc2012-11-04 03:20:05 +00001149 }
Johnny Chen1083b0d2012-08-28 22:53:40 +00001150 break;
Sylvestre Ledru1c9e0642014-08-18 14:53:42 +00001151
Greg Clayton52edb362014-07-14 22:53:02 +00001152 case ArchSpec::eCore_x86_64_x86_64h:
1153 if (!enforce_exact_match)
1154 {
1155 try_inverse = false;
1156 if (core2 == ArchSpec::eCore_x86_64_x86_64)
1157 return true;
1158 }
1159 break;
Johnny Chen1083b0d2012-08-28 22:53:40 +00001160
Todd Fiala02e71812014-08-28 14:32:43 +00001161 case ArchSpec::eCore_arm_armv8:
1162 if (!enforce_exact_match)
1163 {
1164 if (core2 == ArchSpec::eCore_arm_arm64)
1165 return true;
1166 if (core2 == ArchSpec::eCore_arm_aarch64)
1167 return true;
1168 try_inverse = false;
1169 }
1170 break;
1171
1172 case ArchSpec::eCore_arm_aarch64:
1173 if (!enforce_exact_match)
1174 {
1175 if (core2 == ArchSpec::eCore_arm_arm64)
1176 return true;
1177 if (core2 == ArchSpec::eCore_arm_armv8)
1178 return true;
1179 try_inverse = false;
1180 }
1181 break;
1182
1183 case ArchSpec::eCore_arm_arm64:
1184 if (!enforce_exact_match)
1185 {
1186 if (core2 == ArchSpec::eCore_arm_aarch64)
1187 return true;
1188 if (core2 == ArchSpec::eCore_arm_armv8)
1189 return true;
1190 try_inverse = false;
1191 }
1192 break;
1193
Sagar Thakur6bee9612015-07-13 09:52:06 +00001194 case ArchSpec::eCore_mips32:
1195 if (!enforce_exact_match)
1196 {
1197 if (core2 >= ArchSpec::kCore_mips32_first && core2 <= ArchSpec::kCore_mips32_last)
1198 return true;
1199 try_inverse = false;
1200 }
1201 break;
1202
1203 case ArchSpec::eCore_mips32el:
1204 if (!enforce_exact_match)
1205 {
1206 if (core2 >= ArchSpec::kCore_mips32el_first && core2 <= ArchSpec::kCore_mips32el_last)
1207 return true;
1208 try_inverse = false;
1209 }
1210
Sagar Thakurce815e42015-06-03 10:14:24 +00001211 case ArchSpec::eCore_mips64:
Sagar Thakur6bee9612015-07-13 09:52:06 +00001212 if (!enforce_exact_match)
1213 {
1214 if (core2 >= ArchSpec::kCore_mips32_first && core2 <= ArchSpec::kCore_mips32_last)
1215 return true;
1216 if (core2 >= ArchSpec::kCore_mips64_first && core2 <= ArchSpec::kCore_mips64_last)
1217 return true;
1218 try_inverse = false;
1219 }
1220
1221 case ArchSpec::eCore_mips64el:
1222 if (!enforce_exact_match)
1223 {
1224 if (core2 >= ArchSpec::kCore_mips32el_first && core2 <= ArchSpec::kCore_mips32el_last)
1225 return true;
1226 if (core2 >= ArchSpec::kCore_mips64el_first && core2 <= ArchSpec::kCore_mips64el_last)
1227 return true;
1228 try_inverse = false;
1229 }
1230
Sagar Thakurce815e42015-06-03 10:14:24 +00001231 case ArchSpec::eCore_mips64r2:
1232 case ArchSpec::eCore_mips64r3:
1233 case ArchSpec::eCore_mips64r5:
Sagar Thakurce815e42015-06-03 10:14:24 +00001234 if (!enforce_exact_match)
1235 {
1236 if (core2 >= ArchSpec::kCore_mips32_first && core2 <= (core1 - 10))
1237 return true;
1238 if (core2 >= ArchSpec::kCore_mips64_first && core2 <= (core1 - 1))
1239 return true;
1240 try_inverse = false;
1241 }
1242 break;
1243
Sagar Thakurce815e42015-06-03 10:14:24 +00001244 case ArchSpec::eCore_mips64r2el:
1245 case ArchSpec::eCore_mips64r3el:
1246 case ArchSpec::eCore_mips64r5el:
Sagar Thakurce815e42015-06-03 10:14:24 +00001247 if (!enforce_exact_match)
1248 {
1249 if (core2 >= ArchSpec::kCore_mips32el_first && core2 <= (core1 - 10))
1250 return true;
1251 if (core2 >= ArchSpec::kCore_mips64el_first && core2 <= (core1 - 1))
1252 return true;
1253 try_inverse = false;
1254 }
1255 break;
1256
Sagar Thakur6bee9612015-07-13 09:52:06 +00001257 case ArchSpec::eCore_mips32r2:
1258 case ArchSpec::eCore_mips32r3:
1259 case ArchSpec::eCore_mips32r5:
1260 if (!enforce_exact_match)
1261 {
1262 if (core2 >= ArchSpec::kCore_mips32_first && core2 <= core1)
1263 return true;
1264 }
1265 break;
1266
1267 case ArchSpec::eCore_mips32r2el:
1268 case ArchSpec::eCore_mips32r3el:
1269 case ArchSpec::eCore_mips32r5el:
1270 if (!enforce_exact_match)
1271 {
1272 if (core2 >= ArchSpec::kCore_mips32el_first && core2 <= core1)
1273 return true;
1274 }
1275 break;
1276
1277 case ArchSpec::eCore_mips32r6:
1278 if (!enforce_exact_match)
1279 {
1280 if (core2 == ArchSpec::eCore_mips32 || core2 == ArchSpec::eCore_mips32r6)
1281 return true;
1282 }
1283 break;
1284
1285 case ArchSpec::eCore_mips32r6el:
1286 if (!enforce_exact_match)
1287 {
1288 if (core2 == ArchSpec::eCore_mips32el || core2 == ArchSpec::eCore_mips32r6el)
1289 return true;
1290 return true;
1291 }
1292 break;
1293
1294 case ArchSpec::eCore_mips64r6:
1295 if (!enforce_exact_match)
1296 {
1297 if (core2 == ArchSpec::eCore_mips32 || core2 == ArchSpec::eCore_mips32r6)
1298 return true;
1299 if (core2 == ArchSpec::eCore_mips64 || core2 == ArchSpec::eCore_mips64r6)
1300 return true;
1301 }
1302 break;
1303
1304 case ArchSpec::eCore_mips64r6el:
1305 if (!enforce_exact_match)
1306 {
1307 if (core2 == ArchSpec::eCore_mips32el || core2 == ArchSpec::eCore_mips32r6el)
1308 return true;
1309 if (core2 == ArchSpec::eCore_mips64el || core2 == ArchSpec::eCore_mips64r6el)
1310 return true;
1311 }
1312 break;
1313
Greg Clayton70512312012-05-08 01:45:38 +00001314 default:
1315 break;
1316 }
1317 if (try_inverse)
Jason Molendaba813dc2012-11-04 03:20:05 +00001318 return cores_match (core2, core1, false, enforce_exact_match);
Greg Clayton70512312012-05-08 01:45:38 +00001319 return false;
1320}
1321
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001322bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001323lldb_private::operator<(const ArchSpec& lhs, const ArchSpec& rhs)
1324{
Greg Clayton64195a22011-02-23 00:35:02 +00001325 const ArchSpec::Core lhs_core = lhs.GetCore ();
1326 const ArchSpec::Core rhs_core = rhs.GetCore ();
1327 return lhs_core < rhs_core;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001328}
Greg Claytona97c4d22014-12-09 23:31:02 +00001329
1330static void
1331StopInfoOverrideCallbackTypeARM(lldb_private::Thread &thread)
1332{
1333 // We need to check if we are stopped in Thumb mode in a IT instruction
1334 // and detect if the condition doesn't pass. If this is the case it means
1335 // we won't actually execute this instruction. If this happens we need to
1336 // clear the stop reason to no thread plans think we are stopped for a
1337 // reason and the plans should keep going.
1338 //
1339 // We do this because when single stepping many ARM processes, debuggers
1340 // often use the BVR/BCR registers that says "stop when the PC is not
1341 // equal to its current value". This method of stepping means we can end
1342 // up stopping on instructions inside an if/then block that wouldn't get
1343 // executed. By fixing this we can stop the debugger from seeming like
1344 // you stepped through both the "if" _and_ the "else" clause when source
1345 // level stepping because the debugger stops regardless due to the BVR/BCR
1346 // triggering a stop.
1347 //
1348 // It also means we can set breakpoints on instructions inside an an
1349 // if/then block and correctly skip them if we use the BKPT instruction.
1350 // The ARM and Thumb BKPT instructions are unconditional even when executed
1351 // in a Thumb IT block.
1352 //
1353 // If your debugger inserts software traps in ARM/Thumb code, it will
1354 // need to use 16 and 32 bit instruction for 16 and 32 bit thumb
1355 // instructions respectively. If your debugger inserts a 16 bit thumb
1356 // trap on top of a 32 bit thumb instruction for an opcode that is inside
1357 // an if/then, it will change the it/then to conditionally execute your
1358 // 16 bit trap and then cause your program to crash if it executes the
1359 // trailing 16 bits (the second half of the 32 bit thumb instruction you
1360 // partially overwrote).
1361
1362 RegisterContextSP reg_ctx_sp (thread.GetRegisterContext());
1363 if (reg_ctx_sp)
1364 {
1365 const uint32_t cpsr = reg_ctx_sp->GetFlags(0);
1366 if (cpsr != 0)
1367 {
1368 // Read the J and T bits to get the ISETSTATE
1369 const uint32_t J = Bit32(cpsr, 24);
1370 const uint32_t T = Bit32(cpsr, 5);
1371 const uint32_t ISETSTATE = J << 1 | T;
1372 if (ISETSTATE == 0)
1373 {
1374 // NOTE: I am pretty sure we want to enable the code below
1375 // that detects when we stop on an instruction in ARM mode
1376 // that is conditional and the condition doesn't pass. This
1377 // can happen if you set a breakpoint on an instruction that
1378 // is conditional. We currently will _always_ stop on the
1379 // instruction which is bad. You can also run into this while
1380 // single stepping and you could appear to run code in the "if"
1381 // and in the "else" clause because it would stop at all of the
1382 // conditional instructions in both.
1383 // In such cases, we really don't want to stop at this location.
1384 // I will check with the lldb-dev list first before I enable this.
1385#if 0
1386 // ARM mode: check for condition on intsruction
1387 const addr_t pc = reg_ctx_sp->GetPC();
1388 Error error;
1389 // If we fail to read the opcode we will get UINT64_MAX as the
1390 // result in "opcode" which we can use to detect if we read a
1391 // valid opcode.
1392 const uint64_t opcode = thread.GetProcess()->ReadUnsignedIntegerFromMemory(pc, 4, UINT64_MAX, error);
1393 if (opcode <= UINT32_MAX)
1394 {
1395 const uint32_t condition = Bits32((uint32_t)opcode, 31, 28);
1396 if (ARMConditionPassed(condition, cpsr) == false)
1397 {
1398 // We ARE stopped on an ARM instruction whose condition doesn't
1399 // pass so this instruction won't get executed.
1400 // Regardless of why it stopped, we need to clear the stop info
1401 thread.SetStopInfo (StopInfoSP());
1402 }
1403 }
1404#endif
1405 }
1406 else if (ISETSTATE == 1)
1407 {
1408 // Thumb mode
1409 const uint32_t ITSTATE = Bits32 (cpsr, 15, 10) << 2 | Bits32 (cpsr, 26, 25);
1410 if (ITSTATE != 0)
1411 {
1412 const uint32_t condition = Bits32(ITSTATE, 7, 4);
1413 if (ARMConditionPassed(condition, cpsr) == false)
1414 {
1415 // We ARE stopped in a Thumb IT instruction on an instruction whose
1416 // condition doesn't pass so this instruction won't get executed.
1417 // Regardless of why it stopped, we need to clear the stop info
1418 thread.SetStopInfo (StopInfoSP());
1419 }
1420 }
1421 }
1422 }
1423 }
1424}
1425
1426ArchSpec::StopInfoOverrideCallbackType
1427ArchSpec::GetStopInfoOverrideCallback () const
1428{
1429 const llvm::Triple::ArchType machine = GetMachine();
1430 if (machine == llvm::Triple::arm)
1431 return StopInfoOverrideCallbackTypeARM;
1432 return NULL;
1433}
Todd Fiala7df337f2015-10-13 23:41:19 +00001434
Jason Molenda03fe45e2015-11-06 01:43:36 +00001435bool
1436ArchSpec::IsFullySpecifiedTriple () const
1437{
1438 const auto& user_specified_triple = GetTriple();
1439
1440 bool user_triple_fully_specified = false;
1441
1442 if ((user_specified_triple.getOS() != llvm::Triple::UnknownOS) || TripleOSWasSpecified())
1443 {
1444 if ((user_specified_triple.getVendor() != llvm::Triple::UnknownVendor) || TripleVendorWasSpecified())
1445 {
1446 const unsigned unspecified = 0;
1447 if (user_specified_triple.getOSMajorVersion() != unspecified)
1448 {
1449 user_triple_fully_specified = true;
1450 }
1451 }
1452 }
1453
1454 return user_triple_fully_specified;
1455}
1456
1457void
1458ArchSpec::PiecewiseTripleCompare (const ArchSpec &other,
1459 bool &arch_different,
1460 bool &vendor_different,
1461 bool &os_different,
1462 bool &os_version_different,
1463 bool &env_different)
1464{
1465 const llvm::Triple &me(GetTriple());
1466 const llvm::Triple &them(other.GetTriple());
1467
1468 arch_different = (me.getArch() != them.getArch());
1469
1470 vendor_different = (me.getVendor() != them.getVendor());
1471
1472 os_different = (me.getOS() != them.getOS());
1473
1474 os_version_different = (me.getOSMajorVersion() != them.getOSMajorVersion());
1475
1476 env_different = (me.getEnvironment() != them.getEnvironment());
1477}
1478
Todd Fiala7df337f2015-10-13 23:41:19 +00001479void
1480ArchSpec::DumpTriple(Stream &s) const
1481{
1482 const llvm::Triple &triple = GetTriple();
1483 llvm::StringRef arch_str = triple.getArchName();
1484 llvm::StringRef vendor_str = triple.getVendorName();
1485 llvm::StringRef os_str = triple.getOSName();
1486
1487 s.Printf("%s-%s-%s",
1488 arch_str.empty() ? "*" : arch_str.str().c_str(),
1489 vendor_str.empty() ? "*" : vendor_str.str().c_str(),
1490 os_str.empty() ? "*" : os_str.str().c_str()
1491 );
1492}