1 //===-- ArchSpec.cpp ------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Utility/ArchSpec.h"
10 #include "lldb/Utility/LLDBLog.h"
12 #include "lldb/Utility/Log.h"
13 #include "lldb/Utility/StringList.h"
14 #include "lldb/lldb-defines.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/BinaryFormat/COFF.h"
17 #include "llvm/BinaryFormat/ELF.h"
18 #include "llvm/BinaryFormat/MachO.h"
19 #include "llvm/Support/Compiler.h"
20 #include "llvm/TargetParser/ARMTargetParser.h"
23 using namespace lldb_private
;
25 static bool cores_match(const ArchSpec::Core core1
, const ArchSpec::Core core2
,
26 bool try_inverse
, bool enforce_exact_match
);
28 namespace lldb_private
{
30 struct CoreDefinition
{
31 ByteOrder default_byte_order
;
32 uint32_t addr_byte_size
;
33 uint32_t min_opcode_byte_size
;
34 uint32_t max_opcode_byte_size
;
35 llvm::Triple::ArchType machine
;
37 const char *const name
;
40 } // namespace lldb_private
42 // This core information can be looked using the ArchSpec::Core as the index
43 static const CoreDefinition g_core_definitions
[] = {
44 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_generic
,
46 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_armv4
,
48 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_armv4t
,
50 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_armv5
,
52 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_armv5e
,
54 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_armv5t
,
56 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_armv6
,
58 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_armv6m
,
60 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_armv7
,
62 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_armv7l
,
64 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_armv7f
,
66 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_armv7s
,
68 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_armv7k
,
70 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_armv7m
,
72 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_armv7em
,
74 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_xscale
,
76 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::thumb
, ArchSpec::eCore_thumb
,
78 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::thumb
, ArchSpec::eCore_thumbv4t
,
80 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::thumb
, ArchSpec::eCore_thumbv5
,
82 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::thumb
, ArchSpec::eCore_thumbv5e
,
84 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::thumb
, ArchSpec::eCore_thumbv6
,
86 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::thumb
, ArchSpec::eCore_thumbv6m
,
88 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::thumb
, ArchSpec::eCore_thumbv7
,
90 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::thumb
, ArchSpec::eCore_thumbv7f
,
92 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::thumb
, ArchSpec::eCore_thumbv7s
,
94 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::thumb
, ArchSpec::eCore_thumbv7k
,
96 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::thumb
, ArchSpec::eCore_thumbv7m
,
98 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::thumb
, ArchSpec::eCore_thumbv7em
,
100 {eByteOrderLittle
, 8, 4, 4, llvm::Triple::aarch64
,
101 ArchSpec::eCore_arm_arm64
, "arm64"},
102 {eByteOrderLittle
, 8, 4, 4, llvm::Triple::aarch64
,
103 ArchSpec::eCore_arm_armv8
, "armv8"},
104 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arm
, ArchSpec::eCore_arm_armv8l
,
106 {eByteOrderLittle
, 8, 4, 4, llvm::Triple::aarch64
,
107 ArchSpec::eCore_arm_arm64e
, "arm64e"},
108 {eByteOrderLittle
, 4, 4, 4, llvm::Triple::aarch64_32
,
109 ArchSpec::eCore_arm_arm64_32
, "arm64_32"},
110 {eByteOrderLittle
, 8, 4, 4, llvm::Triple::aarch64
,
111 ArchSpec::eCore_arm_aarch64
, "aarch64"},
113 // mips32, mips32r2, mips32r3, mips32r5, mips32r6
114 {eByteOrderBig
, 4, 2, 4, llvm::Triple::mips
, ArchSpec::eCore_mips32
,
116 {eByteOrderBig
, 4, 2, 4, llvm::Triple::mips
, ArchSpec::eCore_mips32r2
,
118 {eByteOrderBig
, 4, 2, 4, llvm::Triple::mips
, ArchSpec::eCore_mips32r3
,
120 {eByteOrderBig
, 4, 2, 4, llvm::Triple::mips
, ArchSpec::eCore_mips32r5
,
122 {eByteOrderBig
, 4, 2, 4, llvm::Triple::mips
, ArchSpec::eCore_mips32r6
,
124 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::mipsel
, ArchSpec::eCore_mips32el
,
126 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::mipsel
,
127 ArchSpec::eCore_mips32r2el
, "mipsr2el"},
128 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::mipsel
,
129 ArchSpec::eCore_mips32r3el
, "mipsr3el"},
130 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::mipsel
,
131 ArchSpec::eCore_mips32r5el
, "mipsr5el"},
132 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::mipsel
,
133 ArchSpec::eCore_mips32r6el
, "mipsr6el"},
135 // mips64, mips64r2, mips64r3, mips64r5, mips64r6
136 {eByteOrderBig
, 8, 2, 4, llvm::Triple::mips64
, ArchSpec::eCore_mips64
,
138 {eByteOrderBig
, 8, 2, 4, llvm::Triple::mips64
, ArchSpec::eCore_mips64r2
,
140 {eByteOrderBig
, 8, 2, 4, llvm::Triple::mips64
, ArchSpec::eCore_mips64r3
,
142 {eByteOrderBig
, 8, 2, 4, llvm::Triple::mips64
, ArchSpec::eCore_mips64r5
,
144 {eByteOrderBig
, 8, 2, 4, llvm::Triple::mips64
, ArchSpec::eCore_mips64r6
,
146 {eByteOrderLittle
, 8, 2, 4, llvm::Triple::mips64el
,
147 ArchSpec::eCore_mips64el
, "mips64el"},
148 {eByteOrderLittle
, 8, 2, 4, llvm::Triple::mips64el
,
149 ArchSpec::eCore_mips64r2el
, "mips64r2el"},
150 {eByteOrderLittle
, 8, 2, 4, llvm::Triple::mips64el
,
151 ArchSpec::eCore_mips64r3el
, "mips64r3el"},
152 {eByteOrderLittle
, 8, 2, 4, llvm::Triple::mips64el
,
153 ArchSpec::eCore_mips64r5el
, "mips64r5el"},
154 {eByteOrderLittle
, 8, 2, 4, llvm::Triple::mips64el
,
155 ArchSpec::eCore_mips64r6el
, "mips64r6el"},
158 {eByteOrderLittle
, 2, 2, 4, llvm::Triple::msp430
, ArchSpec::eCore_msp430
,
161 {eByteOrderBig
, 4, 4, 4, llvm::Triple::ppc
, ArchSpec::eCore_ppc_generic
,
163 {eByteOrderBig
, 4, 4, 4, llvm::Triple::ppc
, ArchSpec::eCore_ppc_ppc601
,
165 {eByteOrderBig
, 4, 4, 4, llvm::Triple::ppc
, ArchSpec::eCore_ppc_ppc602
,
167 {eByteOrderBig
, 4, 4, 4, llvm::Triple::ppc
, ArchSpec::eCore_ppc_ppc603
,
169 {eByteOrderBig
, 4, 4, 4, llvm::Triple::ppc
, ArchSpec::eCore_ppc_ppc603e
,
171 {eByteOrderBig
, 4, 4, 4, llvm::Triple::ppc
, ArchSpec::eCore_ppc_ppc603ev
,
173 {eByteOrderBig
, 4, 4, 4, llvm::Triple::ppc
, ArchSpec::eCore_ppc_ppc604
,
175 {eByteOrderBig
, 4, 4, 4, llvm::Triple::ppc
, ArchSpec::eCore_ppc_ppc604e
,
177 {eByteOrderBig
, 4, 4, 4, llvm::Triple::ppc
, ArchSpec::eCore_ppc_ppc620
,
179 {eByteOrderBig
, 4, 4, 4, llvm::Triple::ppc
, ArchSpec::eCore_ppc_ppc750
,
181 {eByteOrderBig
, 4, 4, 4, llvm::Triple::ppc
, ArchSpec::eCore_ppc_ppc7400
,
183 {eByteOrderBig
, 4, 4, 4, llvm::Triple::ppc
, ArchSpec::eCore_ppc_ppc7450
,
185 {eByteOrderBig
, 4, 4, 4, llvm::Triple::ppc
, ArchSpec::eCore_ppc_ppc970
,
188 {eByteOrderLittle
, 8, 4, 4, llvm::Triple::ppc64le
,
189 ArchSpec::eCore_ppc64le_generic
, "powerpc64le"},
190 {eByteOrderBig
, 8, 4, 4, llvm::Triple::ppc64
, ArchSpec::eCore_ppc64_generic
,
192 {eByteOrderBig
, 8, 4, 4, llvm::Triple::ppc64
,
193 ArchSpec::eCore_ppc64_ppc970_64
, "ppc970-64"},
195 {eByteOrderBig
, 8, 2, 6, llvm::Triple::systemz
,
196 ArchSpec::eCore_s390x_generic
, "s390x"},
198 {eByteOrderLittle
, 4, 4, 4, llvm::Triple::sparc
,
199 ArchSpec::eCore_sparc_generic
, "sparc"},
200 {eByteOrderLittle
, 8, 4, 4, llvm::Triple::sparcv9
,
201 ArchSpec::eCore_sparc9_generic
, "sparcv9"},
203 {eByteOrderLittle
, 4, 1, 15, llvm::Triple::x86
, ArchSpec::eCore_x86_32_i386
,
205 {eByteOrderLittle
, 4, 1, 15, llvm::Triple::x86
, ArchSpec::eCore_x86_32_i486
,
207 {eByteOrderLittle
, 4, 1, 15, llvm::Triple::x86
,
208 ArchSpec::eCore_x86_32_i486sx
, "i486sx"},
209 {eByteOrderLittle
, 4, 1, 15, llvm::Triple::x86
, ArchSpec::eCore_x86_32_i686
,
212 {eByteOrderLittle
, 8, 1, 15, llvm::Triple::x86_64
,
213 ArchSpec::eCore_x86_64_x86_64
, "x86_64"},
214 {eByteOrderLittle
, 8, 1, 15, llvm::Triple::x86_64
,
215 ArchSpec::eCore_x86_64_x86_64h
, "x86_64h"},
216 {eByteOrderLittle
, 4, 4, 4, llvm::Triple::hexagon
,
217 ArchSpec::eCore_hexagon_generic
, "hexagon"},
218 {eByteOrderLittle
, 4, 4, 4, llvm::Triple::hexagon
,
219 ArchSpec::eCore_hexagon_hexagonv4
, "hexagonv4"},
220 {eByteOrderLittle
, 4, 4, 4, llvm::Triple::hexagon
,
221 ArchSpec::eCore_hexagon_hexagonv5
, "hexagonv5"},
223 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::riscv32
, ArchSpec::eCore_riscv32
,
225 {eByteOrderLittle
, 8, 2, 4, llvm::Triple::riscv64
, ArchSpec::eCore_riscv64
,
228 {eByteOrderLittle
, 4, 4, 4, llvm::Triple::loongarch32
,
229 ArchSpec::eCore_loongarch32
, "loongarch32"},
230 {eByteOrderLittle
, 8, 4, 4, llvm::Triple::loongarch64
,
231 ArchSpec::eCore_loongarch64
, "loongarch64"},
233 {eByteOrderLittle
, 4, 4, 4, llvm::Triple::UnknownArch
,
234 ArchSpec::eCore_uknownMach32
, "unknown-mach-32"},
235 {eByteOrderLittle
, 8, 4, 4, llvm::Triple::UnknownArch
,
236 ArchSpec::eCore_uknownMach64
, "unknown-mach-64"},
237 {eByteOrderLittle
, 4, 2, 4, llvm::Triple::arc
, ArchSpec::eCore_arc
, "arc"},
239 {eByteOrderLittle
, 2, 2, 4, llvm::Triple::avr
, ArchSpec::eCore_avr
, "avr"},
241 {eByteOrderLittle
, 4, 1, 4, llvm::Triple::wasm32
, ArchSpec::eCore_wasm32
,
245 // Ensure that we have an entry in the g_core_definitions for each core. If you
246 // comment out an entry above, you will need to comment out the corresponding
247 // ArchSpec::Core enumeration.
248 static_assert(sizeof(g_core_definitions
) / sizeof(CoreDefinition
) ==
250 "make sure we have one core definition for each core");
252 struct ArchDefinitionEntry
{
260 struct ArchDefinition
{
261 ArchitectureType type
;
263 const ArchDefinitionEntry
*entries
;
267 void ArchSpec::ListSupportedArchNames(StringList
&list
) {
268 for (const auto &def
: g_core_definitions
)
269 list
.AppendString(def
.name
);
272 void ArchSpec::AutoComplete(CompletionRequest
&request
) {
273 for (const auto &def
: g_core_definitions
)
274 request
.TryCompleteCurrentArg(def
.name
);
277 #define CPU_ANY (UINT32_MAX)
279 //===----------------------------------------------------------------------===//
280 // A table that gets searched linearly for matches. This table is used to
281 // convert cpu type and subtypes to architecture names, and to convert
282 // architecture names to cpu types and subtypes. The ordering is important and
283 // allows the precedence to be set when the table is built.
284 #define SUBTYPE_MASK 0x00FFFFFFu
287 static const ArchDefinitionEntry g_macho_arch_entries
[] = {
288 {ArchSpec::eCore_arm_generic
, llvm::MachO::CPU_TYPE_ARM
, CPU_ANY
, UINT32_MAX
, UINT32_MAX
},
289 {ArchSpec::eCore_arm_generic
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_ALL
, UINT32_MAX
, SUBTYPE_MASK
},
290 {ArchSpec::eCore_arm_armv4
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V4T
, UINT32_MAX
, SUBTYPE_MASK
},
291 {ArchSpec::eCore_arm_armv4t
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V4T
, UINT32_MAX
, SUBTYPE_MASK
},
292 {ArchSpec::eCore_arm_armv6
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V6
, UINT32_MAX
, SUBTYPE_MASK
},
293 {ArchSpec::eCore_arm_armv6m
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V6M
, UINT32_MAX
, SUBTYPE_MASK
},
294 {ArchSpec::eCore_arm_armv5
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V5TEJ
, UINT32_MAX
, SUBTYPE_MASK
},
295 {ArchSpec::eCore_arm_armv5e
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V5TEJ
, UINT32_MAX
, SUBTYPE_MASK
},
296 {ArchSpec::eCore_arm_armv5t
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V5TEJ
, UINT32_MAX
, SUBTYPE_MASK
},
297 {ArchSpec::eCore_arm_xscale
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_XSCALE
, UINT32_MAX
, SUBTYPE_MASK
},
298 {ArchSpec::eCore_arm_armv7
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V7
, UINT32_MAX
, SUBTYPE_MASK
},
299 {ArchSpec::eCore_arm_armv7f
, llvm::MachO::CPU_TYPE_ARM
, 10, UINT32_MAX
, SUBTYPE_MASK
},
300 {ArchSpec::eCore_arm_armv7s
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V7S
, UINT32_MAX
, SUBTYPE_MASK
},
301 {ArchSpec::eCore_arm_armv7k
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V7K
, UINT32_MAX
, SUBTYPE_MASK
},
302 {ArchSpec::eCore_arm_armv7m
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V7M
, UINT32_MAX
, SUBTYPE_MASK
},
303 {ArchSpec::eCore_arm_armv7em
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V7EM
, UINT32_MAX
, SUBTYPE_MASK
},
304 {ArchSpec::eCore_arm_arm64e
, llvm::MachO::CPU_TYPE_ARM64
, llvm::MachO::CPU_SUBTYPE_ARM64E
, UINT32_MAX
, SUBTYPE_MASK
},
305 {ArchSpec::eCore_arm_arm64
, llvm::MachO::CPU_TYPE_ARM64
, llvm::MachO::CPU_SUBTYPE_ARM64_ALL
, UINT32_MAX
, SUBTYPE_MASK
},
306 {ArchSpec::eCore_arm_arm64
, llvm::MachO::CPU_TYPE_ARM64
, llvm::MachO::CPU_SUBTYPE_ARM64_V8
, UINT32_MAX
, SUBTYPE_MASK
},
307 {ArchSpec::eCore_arm_arm64
, llvm::MachO::CPU_TYPE_ARM64
, 13, UINT32_MAX
, SUBTYPE_MASK
},
308 {ArchSpec::eCore_arm_arm64_32
, llvm::MachO::CPU_TYPE_ARM64_32
, 0, UINT32_MAX
, SUBTYPE_MASK
},
309 {ArchSpec::eCore_arm_arm64_32
, llvm::MachO::CPU_TYPE_ARM64_32
, 1, UINT32_MAX
, SUBTYPE_MASK
},
310 {ArchSpec::eCore_arm_arm64
, llvm::MachO::CPU_TYPE_ARM64
, CPU_ANY
, UINT32_MAX
, SUBTYPE_MASK
},
311 {ArchSpec::eCore_thumb
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_ALL
, UINT32_MAX
, SUBTYPE_MASK
},
312 {ArchSpec::eCore_thumbv4t
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V4T
, UINT32_MAX
, SUBTYPE_MASK
},
313 {ArchSpec::eCore_thumbv5
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V5
, UINT32_MAX
, SUBTYPE_MASK
},
314 {ArchSpec::eCore_thumbv5e
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V5
, UINT32_MAX
, SUBTYPE_MASK
},
315 {ArchSpec::eCore_thumbv6
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V6
, UINT32_MAX
, SUBTYPE_MASK
},
316 {ArchSpec::eCore_thumbv6m
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V6M
, UINT32_MAX
, SUBTYPE_MASK
},
317 {ArchSpec::eCore_thumbv7
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V7
, UINT32_MAX
, SUBTYPE_MASK
},
318 {ArchSpec::eCore_thumbv7f
, llvm::MachO::CPU_TYPE_ARM
, 10, UINT32_MAX
, SUBTYPE_MASK
},
319 {ArchSpec::eCore_thumbv7s
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V7S
, UINT32_MAX
, SUBTYPE_MASK
},
320 {ArchSpec::eCore_thumbv7k
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V7K
, UINT32_MAX
, SUBTYPE_MASK
},
321 {ArchSpec::eCore_thumbv7m
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V7M
, UINT32_MAX
, SUBTYPE_MASK
},
322 {ArchSpec::eCore_thumbv7em
, llvm::MachO::CPU_TYPE_ARM
, llvm::MachO::CPU_SUBTYPE_ARM_V7EM
, UINT32_MAX
, SUBTYPE_MASK
},
323 {ArchSpec::eCore_ppc_generic
, llvm::MachO::CPU_TYPE_POWERPC
, CPU_ANY
, UINT32_MAX
, UINT32_MAX
},
324 {ArchSpec::eCore_ppc_generic
, llvm::MachO::CPU_TYPE_POWERPC
, llvm::MachO::CPU_SUBTYPE_POWERPC_ALL
, UINT32_MAX
, SUBTYPE_MASK
},
325 {ArchSpec::eCore_ppc_ppc601
, llvm::MachO::CPU_TYPE_POWERPC
, llvm::MachO::CPU_SUBTYPE_POWERPC_601
, UINT32_MAX
, SUBTYPE_MASK
},
326 {ArchSpec::eCore_ppc_ppc602
, llvm::MachO::CPU_TYPE_POWERPC
, llvm::MachO::CPU_SUBTYPE_POWERPC_602
, UINT32_MAX
, SUBTYPE_MASK
},
327 {ArchSpec::eCore_ppc_ppc603
, llvm::MachO::CPU_TYPE_POWERPC
, llvm::MachO::CPU_SUBTYPE_POWERPC_603
, UINT32_MAX
, SUBTYPE_MASK
},
328 {ArchSpec::eCore_ppc_ppc603e
, llvm::MachO::CPU_TYPE_POWERPC
, llvm::MachO::CPU_SUBTYPE_POWERPC_603e
, UINT32_MAX
, SUBTYPE_MASK
},
329 {ArchSpec::eCore_ppc_ppc603ev
, llvm::MachO::CPU_TYPE_POWERPC
, llvm::MachO::CPU_SUBTYPE_POWERPC_603ev
, UINT32_MAX
, SUBTYPE_MASK
},
330 {ArchSpec::eCore_ppc_ppc604
, llvm::MachO::CPU_TYPE_POWERPC
, llvm::MachO::CPU_SUBTYPE_POWERPC_604
, UINT32_MAX
, SUBTYPE_MASK
},
331 {ArchSpec::eCore_ppc_ppc604e
, llvm::MachO::CPU_TYPE_POWERPC
, llvm::MachO::CPU_SUBTYPE_POWERPC_604e
, UINT32_MAX
, SUBTYPE_MASK
},
332 {ArchSpec::eCore_ppc_ppc620
, llvm::MachO::CPU_TYPE_POWERPC
, llvm::MachO::CPU_SUBTYPE_POWERPC_620
, UINT32_MAX
, SUBTYPE_MASK
},
333 {ArchSpec::eCore_ppc_ppc750
, llvm::MachO::CPU_TYPE_POWERPC
, llvm::MachO::CPU_SUBTYPE_POWERPC_750
, UINT32_MAX
, SUBTYPE_MASK
},
334 {ArchSpec::eCore_ppc_ppc7400
, llvm::MachO::CPU_TYPE_POWERPC
, llvm::MachO::CPU_SUBTYPE_POWERPC_7400
, UINT32_MAX
, SUBTYPE_MASK
},
335 {ArchSpec::eCore_ppc_ppc7450
, llvm::MachO::CPU_TYPE_POWERPC
, llvm::MachO::CPU_SUBTYPE_POWERPC_7450
, UINT32_MAX
, SUBTYPE_MASK
},
336 {ArchSpec::eCore_ppc_ppc970
, llvm::MachO::CPU_TYPE_POWERPC
, llvm::MachO::CPU_SUBTYPE_POWERPC_970
, UINT32_MAX
, SUBTYPE_MASK
},
337 {ArchSpec::eCore_ppc64_generic
, llvm::MachO::CPU_TYPE_POWERPC64
, llvm::MachO::CPU_SUBTYPE_POWERPC_ALL
, UINT32_MAX
, SUBTYPE_MASK
},
338 {ArchSpec::eCore_ppc64le_generic
, llvm::MachO::CPU_TYPE_POWERPC64
, CPU_ANY
, UINT32_MAX
, SUBTYPE_MASK
},
339 {ArchSpec::eCore_ppc64_ppc970_64
, llvm::MachO::CPU_TYPE_POWERPC64
, 100, UINT32_MAX
, SUBTYPE_MASK
},
340 {ArchSpec::eCore_x86_32_i386
, llvm::MachO::CPU_TYPE_I386
, llvm::MachO::CPU_SUBTYPE_I386_ALL
, UINT32_MAX
, SUBTYPE_MASK
},
341 {ArchSpec::eCore_x86_32_i486
, llvm::MachO::CPU_TYPE_I386
, llvm::MachO::CPU_SUBTYPE_486
, UINT32_MAX
, SUBTYPE_MASK
},
342 {ArchSpec::eCore_x86_32_i486sx
, llvm::MachO::CPU_TYPE_I386
, llvm::MachO::CPU_SUBTYPE_486SX
, UINT32_MAX
, SUBTYPE_MASK
},
343 {ArchSpec::eCore_x86_32_i386
, llvm::MachO::CPU_TYPE_I386
, CPU_ANY
, UINT32_MAX
, UINT32_MAX
},
344 {ArchSpec::eCore_x86_64_x86_64
, llvm::MachO::CPU_TYPE_X86_64
, llvm::MachO::CPU_SUBTYPE_X86_64_ALL
, UINT32_MAX
, SUBTYPE_MASK
},
345 {ArchSpec::eCore_x86_64_x86_64
, llvm::MachO::CPU_TYPE_X86_64
, llvm::MachO::CPU_SUBTYPE_X86_ARCH1
, UINT32_MAX
, SUBTYPE_MASK
},
346 {ArchSpec::eCore_x86_64_x86_64h
, llvm::MachO::CPU_TYPE_X86_64
, llvm::MachO::CPU_SUBTYPE_X86_64_H
, UINT32_MAX
, SUBTYPE_MASK
},
347 {ArchSpec::eCore_x86_64_x86_64
, llvm::MachO::CPU_TYPE_X86_64
, CPU_ANY
, UINT32_MAX
, UINT32_MAX
},
348 // Catch any unknown mach architectures so we can always use the object and symbol mach-o files
349 {ArchSpec::eCore_uknownMach32
, 0, 0, 0xFF000000u
, 0x00000000u
},
350 {ArchSpec::eCore_uknownMach64
, llvm::MachO::CPU_ARCH_ABI64
, 0, 0xFF000000u
, 0x00000000u
}};
353 static const ArchDefinition g_macho_arch_def
= {eArchTypeMachO
,
354 std::size(g_macho_arch_entries
),
355 g_macho_arch_entries
, "mach-o"};
357 //===----------------------------------------------------------------------===//
358 // A table that gets searched linearly for matches. This table is used to
359 // convert cpu type and subtypes to architecture names, and to convert
360 // architecture names to cpu types and subtypes. The ordering is important and
361 // allows the precedence to be set when the table is built.
362 static const ArchDefinitionEntry g_elf_arch_entries
[] = {
363 {ArchSpec::eCore_sparc_generic
, llvm::ELF::EM_SPARC
, LLDB_INVALID_CPUTYPE
,
364 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // Sparc
365 {ArchSpec::eCore_x86_32_i386
, llvm::ELF::EM_386
, LLDB_INVALID_CPUTYPE
,
366 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // Intel 80386
367 {ArchSpec::eCore_x86_32_i486
, llvm::ELF::EM_IAMCU
, LLDB_INVALID_CPUTYPE
,
368 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // Intel MCU // FIXME: is this correct?
369 {ArchSpec::eCore_ppc_generic
, llvm::ELF::EM_PPC
, LLDB_INVALID_CPUTYPE
,
370 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // PowerPC
371 {ArchSpec::eCore_ppc64le_generic
, llvm::ELF::EM_PPC64
,
372 ArchSpec::eCore_ppc64le_generic
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // PowerPC64le
373 {ArchSpec::eCore_ppc64_generic
, llvm::ELF::EM_PPC64
,
374 ArchSpec::eCore_ppc64_generic
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // PowerPC64
375 {ArchSpec::eCore_arm_generic
, llvm::ELF::EM_ARM
, LLDB_INVALID_CPUTYPE
,
376 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // ARM
377 {ArchSpec::eCore_arm_aarch64
, llvm::ELF::EM_AARCH64
, LLDB_INVALID_CPUTYPE
,
378 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // ARM64
379 {ArchSpec::eCore_s390x_generic
, llvm::ELF::EM_S390
, LLDB_INVALID_CPUTYPE
,
380 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // SystemZ
381 {ArchSpec::eCore_sparc9_generic
, llvm::ELF::EM_SPARCV9
,
382 LLDB_INVALID_CPUTYPE
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // SPARC V9
383 {ArchSpec::eCore_x86_64_x86_64
, llvm::ELF::EM_X86_64
, LLDB_INVALID_CPUTYPE
,
384 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // AMD64
385 {ArchSpec::eCore_mips32
, llvm::ELF::EM_MIPS
, ArchSpec::eMIPSSubType_mips32
,
386 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // mips32
387 {ArchSpec::eCore_mips32r2
, llvm::ELF::EM_MIPS
,
388 ArchSpec::eMIPSSubType_mips32r2
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // mips32r2
389 {ArchSpec::eCore_mips32r6
, llvm::ELF::EM_MIPS
,
390 ArchSpec::eMIPSSubType_mips32r6
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // mips32r6
391 {ArchSpec::eCore_mips32el
, llvm::ELF::EM_MIPS
,
392 ArchSpec::eMIPSSubType_mips32el
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // mips32el
393 {ArchSpec::eCore_mips32r2el
, llvm::ELF::EM_MIPS
,
394 ArchSpec::eMIPSSubType_mips32r2el
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // mips32r2el
395 {ArchSpec::eCore_mips32r6el
, llvm::ELF::EM_MIPS
,
396 ArchSpec::eMIPSSubType_mips32r6el
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // mips32r6el
397 {ArchSpec::eCore_mips64
, llvm::ELF::EM_MIPS
, ArchSpec::eMIPSSubType_mips64
,
398 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // mips64
399 {ArchSpec::eCore_mips64r2
, llvm::ELF::EM_MIPS
,
400 ArchSpec::eMIPSSubType_mips64r2
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // mips64r2
401 {ArchSpec::eCore_mips64r6
, llvm::ELF::EM_MIPS
,
402 ArchSpec::eMIPSSubType_mips64r6
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // mips64r6
403 {ArchSpec::eCore_mips64el
, llvm::ELF::EM_MIPS
,
404 ArchSpec::eMIPSSubType_mips64el
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // mips64el
405 {ArchSpec::eCore_mips64r2el
, llvm::ELF::EM_MIPS
,
406 ArchSpec::eMIPSSubType_mips64r2el
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // mips64r2el
407 {ArchSpec::eCore_mips64r6el
, llvm::ELF::EM_MIPS
,
408 ArchSpec::eMIPSSubType_mips64r6el
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // mips64r6el
409 {ArchSpec::eCore_msp430
, llvm::ELF::EM_MSP430
, LLDB_INVALID_CPUTYPE
,
410 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // MSP430
411 {ArchSpec::eCore_hexagon_generic
, llvm::ELF::EM_HEXAGON
,
412 LLDB_INVALID_CPUTYPE
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // HEXAGON
413 {ArchSpec::eCore_arc
, llvm::ELF::EM_ARC_COMPACT2
, LLDB_INVALID_CPUTYPE
,
414 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // ARC
415 {ArchSpec::eCore_avr
, llvm::ELF::EM_AVR
, LLDB_INVALID_CPUTYPE
, 0xFFFFFFFFu
,
417 {ArchSpec::eCore_riscv32
, llvm::ELF::EM_RISCV
,
418 ArchSpec::eRISCVSubType_riscv32
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // riscv32
419 {ArchSpec::eCore_riscv64
, llvm::ELF::EM_RISCV
,
420 ArchSpec::eRISCVSubType_riscv64
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // riscv64
421 {ArchSpec::eCore_loongarch32
, llvm::ELF::EM_LOONGARCH
,
422 ArchSpec::eLoongArchSubType_loongarch32
, 0xFFFFFFFFu
,
423 0xFFFFFFFFu
}, // loongarch32
424 {ArchSpec::eCore_loongarch64
, llvm::ELF::EM_LOONGARCH
,
425 ArchSpec::eLoongArchSubType_loongarch64
, 0xFFFFFFFFu
,
426 0xFFFFFFFFu
}, // loongarch64
429 static const ArchDefinition g_elf_arch_def
= {
431 std::size(g_elf_arch_entries
),
436 static const ArchDefinitionEntry g_coff_arch_entries
[] = {
437 {ArchSpec::eCore_x86_32_i386
, llvm::COFF::IMAGE_FILE_MACHINE_I386
,
438 LLDB_INVALID_CPUTYPE
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // Intel 80x86
439 {ArchSpec::eCore_ppc_generic
, llvm::COFF::IMAGE_FILE_MACHINE_POWERPC
,
440 LLDB_INVALID_CPUTYPE
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // PowerPC
441 {ArchSpec::eCore_ppc_generic
, llvm::COFF::IMAGE_FILE_MACHINE_POWERPCFP
,
442 LLDB_INVALID_CPUTYPE
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // PowerPC (with FPU)
443 {ArchSpec::eCore_arm_generic
, llvm::COFF::IMAGE_FILE_MACHINE_ARM
,
444 LLDB_INVALID_CPUTYPE
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // ARM
445 {ArchSpec::eCore_arm_armv7
, llvm::COFF::IMAGE_FILE_MACHINE_ARMNT
,
446 LLDB_INVALID_CPUTYPE
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // ARMv7
447 {ArchSpec::eCore_thumb
, llvm::COFF::IMAGE_FILE_MACHINE_THUMB
,
448 LLDB_INVALID_CPUTYPE
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // ARMv7
449 {ArchSpec::eCore_x86_64_x86_64
, llvm::COFF::IMAGE_FILE_MACHINE_AMD64
,
450 LLDB_INVALID_CPUTYPE
, 0xFFFFFFFFu
, 0xFFFFFFFFu
}, // AMD64
451 {ArchSpec::eCore_arm_arm64
, llvm::COFF::IMAGE_FILE_MACHINE_ARM64
,
452 LLDB_INVALID_CPUTYPE
, 0xFFFFFFFFu
, 0xFFFFFFFFu
} // ARM64
455 static const ArchDefinition g_coff_arch_def
= {
457 std::size(g_coff_arch_entries
),
462 //===----------------------------------------------------------------------===//
463 // Table of all ArchDefinitions
464 static const ArchDefinition
*g_arch_definitions
[] = {
465 &g_macho_arch_def
, &g_elf_arch_def
, &g_coff_arch_def
};
467 //===----------------------------------------------------------------------===//
468 // Static helper functions.
470 // Get the architecture definition for a given object type.
471 static const ArchDefinition
*FindArchDefinition(ArchitectureType arch_type
) {
472 for (const ArchDefinition
*def
: g_arch_definitions
) {
473 if (def
->type
== arch_type
)
479 // Get an architecture definition by name.
480 static const CoreDefinition
*FindCoreDefinition(llvm::StringRef name
) {
481 for (const auto &def
: g_core_definitions
) {
482 if (name
.equals_insensitive(def
.name
))
488 static inline const CoreDefinition
*FindCoreDefinition(ArchSpec::Core core
) {
489 if (core
< std::size(g_core_definitions
))
490 return &g_core_definitions
[core
];
494 // Get a definition entry by cpu type and subtype.
495 static const ArchDefinitionEntry
*
496 FindArchDefinitionEntry(const ArchDefinition
*def
, uint32_t cpu
, uint32_t sub
) {
500 const ArchDefinitionEntry
*entries
= def
->entries
;
501 for (size_t i
= 0; i
< def
->num_entries
; ++i
) {
502 if (entries
[i
].cpu
== (cpu
& entries
[i
].cpu_mask
))
503 if (entries
[i
].sub
== (sub
& entries
[i
].sub_mask
))
509 static const ArchDefinitionEntry
*
510 FindArchDefinitionEntry(const ArchDefinition
*def
, ArchSpec::Core core
) {
514 const ArchDefinitionEntry
*entries
= def
->entries
;
515 for (size_t i
= 0; i
< def
->num_entries
; ++i
) {
516 if (entries
[i
].core
== core
)
522 //===----------------------------------------------------------------------===//
523 // Constructors and destructors.
525 ArchSpec::ArchSpec() = default;
527 ArchSpec::ArchSpec(const char *triple_cstr
) {
529 SetTriple(triple_cstr
);
532 ArchSpec::ArchSpec(llvm::StringRef triple_str
) { SetTriple(triple_str
); }
534 ArchSpec::ArchSpec(const llvm::Triple
&triple
) { SetTriple(triple
); }
536 ArchSpec::ArchSpec(ArchitectureType arch_type
, uint32_t cpu
, uint32_t subtype
) {
537 SetArchitecture(arch_type
, cpu
, subtype
);
540 ArchSpec::~ArchSpec() = default;
542 void ArchSpec::Clear() {
543 m_triple
= llvm::Triple();
544 m_core
= kCore_invalid
;
545 m_byte_order
= eByteOrderInvalid
;
549 //===----------------------------------------------------------------------===//
552 const char *ArchSpec::GetArchitectureName() const {
553 const CoreDefinition
*core_def
= FindCoreDefinition(m_core
);
555 return core_def
->name
;
559 bool ArchSpec::IsMIPS() const { return GetTriple().isMIPS(); }
561 std::string
ArchSpec::GetTargetABI() const {
566 switch (GetFlags() & ArchSpec::eMIPSABI_mask
) {
567 case ArchSpec::eMIPSABI_N64
:
570 case ArchSpec::eMIPSABI_N32
:
573 case ArchSpec::eMIPSABI_O32
:
583 void ArchSpec::SetFlags(const std::string
&elf_abi
) {
585 uint32_t flag
= GetFlags();
587 if (elf_abi
== "n64")
588 flag
|= ArchSpec::eMIPSABI_N64
;
589 else if (elf_abi
== "n32")
590 flag
|= ArchSpec::eMIPSABI_N32
;
591 else if (elf_abi
== "o32")
592 flag
|= ArchSpec::eMIPSABI_O32
;
597 std::string
ArchSpec::GetClangTargetCPU() const {
601 case ArchSpec::eCore_mips32
:
602 case ArchSpec::eCore_mips32el
:
605 case ArchSpec::eCore_mips32r2
:
606 case ArchSpec::eCore_mips32r2el
:
609 case ArchSpec::eCore_mips32r3
:
610 case ArchSpec::eCore_mips32r3el
:
613 case ArchSpec::eCore_mips32r5
:
614 case ArchSpec::eCore_mips32r5el
:
617 case ArchSpec::eCore_mips32r6
:
618 case ArchSpec::eCore_mips32r6el
:
621 case ArchSpec::eCore_mips64
:
622 case ArchSpec::eCore_mips64el
:
625 case ArchSpec::eCore_mips64r2
:
626 case ArchSpec::eCore_mips64r2el
:
629 case ArchSpec::eCore_mips64r3
:
630 case ArchSpec::eCore_mips64r3el
:
633 case ArchSpec::eCore_mips64r5
:
634 case ArchSpec::eCore_mips64r5el
:
637 case ArchSpec::eCore_mips64r6
:
638 case ArchSpec::eCore_mips64r6el
:
646 if (GetTriple().isARM())
647 cpu
= llvm::ARM::getARMCPUForArch(GetTriple(), "").str();
651 uint32_t ArchSpec::GetMachOCPUType() const {
652 const CoreDefinition
*core_def
= FindCoreDefinition(m_core
);
654 const ArchDefinitionEntry
*arch_def
=
655 FindArchDefinitionEntry(&g_macho_arch_def
, core_def
->core
);
657 return arch_def
->cpu
;
660 return LLDB_INVALID_CPUTYPE
;
663 uint32_t ArchSpec::GetMachOCPUSubType() const {
664 const CoreDefinition
*core_def
= FindCoreDefinition(m_core
);
666 const ArchDefinitionEntry
*arch_def
=
667 FindArchDefinitionEntry(&g_macho_arch_def
, core_def
->core
);
669 return arch_def
->sub
;
672 return LLDB_INVALID_CPUTYPE
;
675 uint32_t ArchSpec::GetDataByteSize() const {
679 uint32_t ArchSpec::GetCodeByteSize() const {
683 llvm::Triple::ArchType
ArchSpec::GetMachine() const {
684 const CoreDefinition
*core_def
= FindCoreDefinition(m_core
);
686 return core_def
->machine
;
688 return llvm::Triple::UnknownArch
;
691 uint32_t ArchSpec::GetAddressByteSize() const {
692 const CoreDefinition
*core_def
= FindCoreDefinition(m_core
);
694 if (core_def
->machine
== llvm::Triple::mips64
||
695 core_def
->machine
== llvm::Triple::mips64el
) {
696 // For N32/O32 applications Address size is 4 bytes.
697 if (m_flags
& (eMIPSABI_N32
| eMIPSABI_O32
))
700 return core_def
->addr_byte_size
;
705 ByteOrder
ArchSpec::GetDefaultEndian() const {
706 const CoreDefinition
*core_def
= FindCoreDefinition(m_core
);
708 return core_def
->default_byte_order
;
709 return eByteOrderInvalid
;
712 bool ArchSpec::CharIsSignedByDefault() const {
713 switch (m_triple
.getArch()) {
717 case llvm::Triple::aarch64
:
718 case llvm::Triple::aarch64_32
:
719 case llvm::Triple::aarch64_be
:
720 case llvm::Triple::arm
:
721 case llvm::Triple::armeb
:
722 case llvm::Triple::thumb
:
723 case llvm::Triple::thumbeb
:
724 return m_triple
.isOSDarwin() || m_triple
.isOSWindows();
726 case llvm::Triple::ppc
:
727 case llvm::Triple::ppc64
:
728 return m_triple
.isOSDarwin();
730 case llvm::Triple::ppc64le
:
731 case llvm::Triple::systemz
:
732 case llvm::Triple::xcore
:
733 case llvm::Triple::arc
:
738 lldb::ByteOrder
ArchSpec::GetByteOrder() const {
739 if (m_byte_order
== eByteOrderInvalid
)
740 return GetDefaultEndian();
744 //===----------------------------------------------------------------------===//
747 bool ArchSpec::SetTriple(const llvm::Triple
&triple
) {
753 bool lldb_private::ParseMachCPUDashSubtypeTriple(llvm::StringRef triple_str
,
755 // Accept "12-10" or "12.10" as cpu type/subtype
756 if (triple_str
.empty())
759 size_t pos
= triple_str
.find_first_of("-.");
760 if (pos
== llvm::StringRef::npos
)
763 llvm::StringRef cpu_str
= triple_str
.substr(0, pos
);
764 llvm::StringRef remainder
= triple_str
.substr(pos
+ 1);
765 if (cpu_str
.empty() || remainder
.empty())
768 llvm::StringRef sub_str
;
769 llvm::StringRef vendor
;
771 std::tie(sub_str
, remainder
) = remainder
.split('-');
772 std::tie(vendor
, os
) = remainder
.split('-');
776 if (cpu_str
.getAsInteger(10, cpu
) || sub_str
.getAsInteger(10, sub
))
779 if (!arch
.SetArchitecture(eArchTypeMachO
, cpu
, sub
))
781 if (!vendor
.empty() && !os
.empty()) {
782 arch
.GetTriple().setVendorName(vendor
);
783 arch
.GetTriple().setOSName(os
);
789 bool ArchSpec::SetTriple(llvm::StringRef triple
) {
790 if (triple
.empty()) {
795 if (ParseMachCPUDashSubtypeTriple(triple
, *this))
798 SetTriple(llvm::Triple(llvm::Triple::normalize(triple
)));
802 bool ArchSpec::ContainsOnlyArch(const llvm::Triple
&normalized_triple
) {
803 return !normalized_triple
.getArchName().empty() &&
804 normalized_triple
.getOSName().empty() &&
805 normalized_triple
.getVendorName().empty() &&
806 normalized_triple
.getEnvironmentName().empty();
809 void ArchSpec::MergeFrom(const ArchSpec
&other
) {
810 // ios-macabi always wins over macosx.
811 if ((GetTriple().getOS() == llvm::Triple::MacOSX
||
812 GetTriple().getOS() == llvm::Triple::UnknownOS
) &&
813 other
.GetTriple().getOS() == llvm::Triple::IOS
&&
814 other
.GetTriple().getEnvironment() == llvm::Triple::MacABI
) {
819 if (!TripleVendorWasSpecified() && other
.TripleVendorWasSpecified())
820 GetTriple().setVendor(other
.GetTriple().getVendor());
821 if (!TripleOSWasSpecified() && other
.TripleOSWasSpecified())
822 GetTriple().setOS(other
.GetTriple().getOS());
823 if (GetTriple().getArch() == llvm::Triple::UnknownArch
) {
824 GetTriple().setArch(other
.GetTriple().getArch());
826 // MachO unknown64 isn't really invalid as the debugger can still obtain
827 // information from the binary, e.g. line tables. As such, we don't update
829 if (other
.GetCore() != eCore_uknownMach64
)
832 if (!TripleEnvironmentWasSpecified() &&
833 other
.TripleEnvironmentWasSpecified()) {
834 GetTriple().setEnvironment(other
.GetTriple().getEnvironment());
836 // If this and other are both arm ArchSpecs and this ArchSpec is a generic
837 // "some kind of arm" spec but the other ArchSpec is a specific arm core,
838 // adopt the specific arm core.
839 if (GetTriple().getArch() == llvm::Triple::arm
&&
840 other
.GetTriple().getArch() == llvm::Triple::arm
&&
841 IsCompatibleMatch(other
) && GetCore() == ArchSpec::eCore_arm_generic
&&
842 other
.GetCore() != ArchSpec::eCore_arm_generic
) {
843 m_core
= other
.GetCore();
846 if (GetFlags() == 0) {
847 SetFlags(other
.GetFlags());
851 bool ArchSpec::SetArchitecture(ArchitectureType arch_type
, uint32_t cpu
,
852 uint32_t sub
, uint32_t os
) {
853 m_core
= kCore_invalid
;
854 bool update_triple
= true;
855 const ArchDefinition
*arch_def
= FindArchDefinition(arch_type
);
857 const ArchDefinitionEntry
*arch_def_entry
=
858 FindArchDefinitionEntry(arch_def
, cpu
, sub
);
859 if (arch_def_entry
) {
860 const CoreDefinition
*core_def
= FindCoreDefinition(arch_def_entry
->core
);
862 m_core
= core_def
->core
;
863 update_triple
= false;
864 // Always use the architecture name because it might be more
865 // descriptive than the architecture enum ("armv7" ->
866 // llvm::Triple::arm).
867 m_triple
.setArchName(llvm::StringRef(core_def
->name
));
868 if (arch_type
== eArchTypeMachO
) {
869 m_triple
.setVendor(llvm::Triple::Apple
);
871 // Don't set the OS. It could be simulator, macosx, ios, watchos,
872 // tvos, bridgeos. We could get close with the cpu type - but we
873 // can't get it right all of the time. Better to leave this unset
874 // so other sections of code will set it when they have more
875 // information. NB: don't call m_triple.setOS
876 // (llvm::Triple::UnknownOS). That sets the OSName to "unknown" and
877 // the ArchSpec::TripleVendorWasSpecified() method says that any
878 // OSName setting means it was specified.
879 } else if (arch_type
== eArchTypeELF
) {
881 case llvm::ELF::ELFOSABI_AIX
:
882 m_triple
.setOS(llvm::Triple::OSType::AIX
);
884 case llvm::ELF::ELFOSABI_FREEBSD
:
885 m_triple
.setOS(llvm::Triple::OSType::FreeBSD
);
887 case llvm::ELF::ELFOSABI_GNU
:
888 m_triple
.setOS(llvm::Triple::OSType::Linux
);
890 case llvm::ELF::ELFOSABI_NETBSD
:
891 m_triple
.setOS(llvm::Triple::OSType::NetBSD
);
893 case llvm::ELF::ELFOSABI_OPENBSD
:
894 m_triple
.setOS(llvm::Triple::OSType::OpenBSD
);
896 case llvm::ELF::ELFOSABI_SOLARIS
:
897 m_triple
.setOS(llvm::Triple::OSType::Solaris
);
899 case llvm::ELF::ELFOSABI_STANDALONE
:
900 m_triple
.setOS(llvm::Triple::OSType::UnknownOS
);
903 } else if (arch_type
== eArchTypeCOFF
&& os
== llvm::Triple::Win32
) {
904 m_triple
.setVendor(llvm::Triple::PC
);
905 m_triple
.setOS(llvm::Triple::Win32
);
907 m_triple
.setVendor(llvm::Triple::UnknownVendor
);
908 m_triple
.setOS(llvm::Triple::UnknownOS
);
910 // Fall back onto setting the machine type if the arch by name
912 if (m_triple
.getArch() == llvm::Triple::UnknownArch
)
913 m_triple
.setArch(core_def
->machine
);
916 Log
*log(GetLog(LLDBLog::Target
| LLDBLog::Process
| LLDBLog::Platform
));
918 "Unable to find a core definition for cpu 0x%" PRIx32
923 CoreUpdated(update_triple
);
927 uint32_t ArchSpec::GetMinimumOpcodeByteSize() const {
928 const CoreDefinition
*core_def
= FindCoreDefinition(m_core
);
930 return core_def
->min_opcode_byte_size
;
934 uint32_t ArchSpec::GetMaximumOpcodeByteSize() const {
935 const CoreDefinition
*core_def
= FindCoreDefinition(m_core
);
937 return core_def
->max_opcode_byte_size
;
941 static bool IsCompatibleEnvironment(llvm::Triple::EnvironmentType lhs
,
942 llvm::Triple::EnvironmentType rhs
) {
946 // Apple simulators are a different platform than what they simulate.
947 // As the environments are different at this point, if one of them is a
948 // simulator, then they are different.
949 if (lhs
== llvm::Triple::Simulator
|| rhs
== llvm::Triple::Simulator
)
952 // If any of the environment is unknown then they are compatible
953 if (lhs
== llvm::Triple::UnknownEnvironment
||
954 rhs
== llvm::Triple::UnknownEnvironment
)
957 // If one of the environment is Android and the other one is EABI then they
958 // are considered to be compatible. This is required as a workaround for
959 // shared libraries compiled for Android without the NOTE section indicating
960 // that they are using the Android ABI.
961 if ((lhs
== llvm::Triple::Android
&& rhs
== llvm::Triple::EABI
) ||
962 (rhs
== llvm::Triple::Android
&& lhs
== llvm::Triple::EABI
) ||
963 (lhs
== llvm::Triple::GNUEABI
&& rhs
== llvm::Triple::EABI
) ||
964 (rhs
== llvm::Triple::GNUEABI
&& lhs
== llvm::Triple::EABI
) ||
965 (lhs
== llvm::Triple::GNUEABIHF
&& rhs
== llvm::Triple::EABIHF
) ||
966 (rhs
== llvm::Triple::GNUEABIHF
&& lhs
== llvm::Triple::EABIHF
))
972 bool ArchSpec::IsMatch(const ArchSpec
&rhs
, MatchType match
) const {
973 if (GetByteOrder() != rhs
.GetByteOrder() ||
974 !cores_match(GetCore(), rhs
.GetCore(), true, match
== ExactMatch
))
977 const llvm::Triple
&lhs_triple
= GetTriple();
978 const llvm::Triple
&rhs_triple
= rhs
.GetTriple();
980 const llvm::Triple::VendorType lhs_triple_vendor
= lhs_triple
.getVendor();
981 const llvm::Triple::VendorType rhs_triple_vendor
= rhs_triple
.getVendor();
983 const llvm::Triple::OSType lhs_triple_os
= lhs_triple
.getOS();
984 const llvm::Triple::OSType rhs_triple_os
= rhs_triple
.getOS();
986 bool both_windows
= lhs_triple
.isOSWindows() && rhs_triple
.isOSWindows();
988 // On Windows, the vendor field doesn't have any practical effect, but
989 // it is often set to either "pc" or "w64".
990 if ((lhs_triple_vendor
!= rhs_triple_vendor
) &&
991 (match
== ExactMatch
|| !both_windows
)) {
992 const bool rhs_vendor_specified
= rhs
.TripleVendorWasSpecified();
993 const bool lhs_vendor_specified
= TripleVendorWasSpecified();
994 // Both architectures had the vendor specified, so if they aren't equal
995 // then we return false
996 if (rhs_vendor_specified
&& lhs_vendor_specified
)
999 // Only fail if both vendor types are not unknown
1000 if (lhs_triple_vendor
!= llvm::Triple::UnknownVendor
&&
1001 rhs_triple_vendor
!= llvm::Triple::UnknownVendor
)
1005 const llvm::Triple::EnvironmentType lhs_triple_env
=
1006 lhs_triple
.getEnvironment();
1007 const llvm::Triple::EnvironmentType rhs_triple_env
=
1008 rhs_triple
.getEnvironment();
1010 if (match
== CompatibleMatch
) {
1011 // x86_64-apple-ios-macabi, x86_64-apple-macosx are compatible, no match.
1012 if ((lhs_triple_os
== llvm::Triple::IOS
&&
1013 lhs_triple_env
== llvm::Triple::MacABI
&&
1014 rhs_triple_os
== llvm::Triple::MacOSX
) ||
1015 (lhs_triple_os
== llvm::Triple::MacOSX
&&
1016 rhs_triple_os
== llvm::Triple::IOS
&&
1017 rhs_triple_env
== llvm::Triple::MacABI
))
1021 // x86_64-apple-ios-macabi and x86_64-apple-ios are not compatible.
1022 if (lhs_triple_os
== llvm::Triple::IOS
&&
1023 rhs_triple_os
== llvm::Triple::IOS
&&
1024 (lhs_triple_env
== llvm::Triple::MacABI
||
1025 rhs_triple_env
== llvm::Triple::MacABI
) &&
1026 lhs_triple_env
!= rhs_triple_env
)
1029 if (lhs_triple_os
!= rhs_triple_os
) {
1030 const bool lhs_os_specified
= TripleOSWasSpecified();
1031 const bool rhs_os_specified
= rhs
.TripleOSWasSpecified();
1032 // If both OS types are specified and different, fail.
1033 if (lhs_os_specified
&& rhs_os_specified
)
1036 // If the pair of os+env is both unspecified, match any other os+env combo.
1037 if (match
== CompatibleMatch
&&
1038 ((!lhs_os_specified
&& !lhs_triple
.hasEnvironment()) ||
1039 (!rhs_os_specified
&& !rhs_triple
.hasEnvironment())))
1043 if (match
== CompatibleMatch
&& both_windows
)
1044 return true; // The Windows environments (MSVC vs GNU) are compatible
1046 return IsCompatibleEnvironment(lhs_triple_env
, rhs_triple_env
);
1049 void ArchSpec::UpdateCore() {
1050 llvm::StringRef
arch_name(m_triple
.getArchName());
1051 const CoreDefinition
*core_def
= FindCoreDefinition(arch_name
);
1053 m_core
= core_def
->core
;
1054 // Set the byte order to the default byte order for an architecture. This
1055 // can be modified if needed for cases when cores handle both big and
1057 m_byte_order
= core_def
->default_byte_order
;
1063 //===----------------------------------------------------------------------===//
1066 void ArchSpec::CoreUpdated(bool update_triple
) {
1067 const CoreDefinition
*core_def
= FindCoreDefinition(m_core
);
1070 m_triple
= llvm::Triple(core_def
->name
, "unknown", "unknown");
1071 m_byte_order
= core_def
->default_byte_order
;
1074 m_triple
= llvm::Triple();
1075 m_byte_order
= eByteOrderInvalid
;
1079 //===----------------------------------------------------------------------===//
1082 static bool cores_match(const ArchSpec::Core core1
, const ArchSpec::Core core2
,
1083 bool try_inverse
, bool enforce_exact_match
) {
1088 case ArchSpec::kCore_any
:
1091 case ArchSpec::eCore_arm_generic
:
1092 if (enforce_exact_match
)
1095 case ArchSpec::kCore_arm_any
:
1096 if (core2
>= ArchSpec::kCore_arm_first
&& core2
<= ArchSpec::kCore_arm_last
)
1098 if (core2
>= ArchSpec::kCore_thumb_first
&&
1099 core2
<= ArchSpec::kCore_thumb_last
)
1101 if (core2
== ArchSpec::kCore_arm_any
)
1105 case ArchSpec::kCore_x86_32_any
:
1106 if ((core2
>= ArchSpec::kCore_x86_32_first
&&
1107 core2
<= ArchSpec::kCore_x86_32_last
) ||
1108 (core2
== ArchSpec::kCore_x86_32_any
))
1112 case ArchSpec::kCore_x86_64_any
:
1113 if ((core2
>= ArchSpec::kCore_x86_64_first
&&
1114 core2
<= ArchSpec::kCore_x86_64_last
) ||
1115 (core2
== ArchSpec::kCore_x86_64_any
))
1119 case ArchSpec::kCore_ppc_any
:
1120 if ((core2
>= ArchSpec::kCore_ppc_first
&&
1121 core2
<= ArchSpec::kCore_ppc_last
) ||
1122 (core2
== ArchSpec::kCore_ppc_any
))
1126 case ArchSpec::kCore_ppc64_any
:
1127 if ((core2
>= ArchSpec::kCore_ppc64_first
&&
1128 core2
<= ArchSpec::kCore_ppc64_last
) ||
1129 (core2
== ArchSpec::kCore_ppc64_any
))
1133 case ArchSpec::kCore_hexagon_any
:
1134 if ((core2
>= ArchSpec::kCore_hexagon_first
&&
1135 core2
<= ArchSpec::kCore_hexagon_last
) ||
1136 (core2
== ArchSpec::kCore_hexagon_any
))
1140 // v. https://en.wikipedia.org/wiki/ARM_Cortex-M#Silicon_customization
1141 // Cortex-M0 - ARMv6-M - armv6m
1142 // Cortex-M3 - ARMv7-M - armv7m
1143 // Cortex-M4 - ARMv7E-M - armv7em
1144 case ArchSpec::eCore_arm_armv7em
:
1145 if (!enforce_exact_match
) {
1146 if (core2
== ArchSpec::eCore_arm_generic
)
1148 if (core2
== ArchSpec::eCore_arm_armv7m
)
1150 if (core2
== ArchSpec::eCore_arm_armv6m
)
1152 if (core2
== ArchSpec::eCore_arm_armv7
)
1158 // v. https://en.wikipedia.org/wiki/ARM_Cortex-M#Silicon_customization
1159 // Cortex-M0 - ARMv6-M - armv6m
1160 // Cortex-M3 - ARMv7-M - armv7m
1161 // Cortex-M4 - ARMv7E-M - armv7em
1162 case ArchSpec::eCore_arm_armv7m
:
1163 if (!enforce_exact_match
) {
1164 if (core2
== ArchSpec::eCore_arm_generic
)
1166 if (core2
== ArchSpec::eCore_arm_armv6m
)
1168 if (core2
== ArchSpec::eCore_arm_armv7
)
1170 if (core2
== ArchSpec::eCore_arm_armv7em
)
1176 // v. https://en.wikipedia.org/wiki/ARM_Cortex-M#Silicon_customization
1177 // Cortex-M0 - ARMv6-M - armv6m
1178 // Cortex-M3 - ARMv7-M - armv7m
1179 // Cortex-M4 - ARMv7E-M - armv7em
1180 case ArchSpec::eCore_arm_armv6m
:
1181 if (!enforce_exact_match
) {
1182 if (core2
== ArchSpec::eCore_arm_generic
)
1184 if (core2
== ArchSpec::eCore_arm_armv7em
)
1186 if (core2
== ArchSpec::eCore_arm_armv7
)
1188 if (core2
== ArchSpec::eCore_arm_armv6m
)
1190 try_inverse
= false;
1194 case ArchSpec::eCore_arm_armv7f
:
1195 case ArchSpec::eCore_arm_armv7k
:
1196 case ArchSpec::eCore_arm_armv7s
:
1197 case ArchSpec::eCore_arm_armv7l
:
1198 case ArchSpec::eCore_arm_armv8l
:
1199 if (!enforce_exact_match
) {
1200 if (core2
== ArchSpec::eCore_arm_generic
)
1202 if (core2
== ArchSpec::eCore_arm_armv7
)
1204 try_inverse
= false;
1208 case ArchSpec::eCore_x86_64_x86_64h
:
1209 if (!enforce_exact_match
) {
1210 try_inverse
= false;
1211 if (core2
== ArchSpec::eCore_x86_64_x86_64
)
1216 case ArchSpec::eCore_arm_armv8
:
1217 if (!enforce_exact_match
) {
1218 if (core2
== ArchSpec::eCore_arm_arm64
)
1220 if (core2
== ArchSpec::eCore_arm_aarch64
)
1222 if (core2
== ArchSpec::eCore_arm_arm64e
)
1224 try_inverse
= false;
1228 case ArchSpec::eCore_arm_arm64e
:
1229 if (!enforce_exact_match
) {
1230 if (core2
== ArchSpec::eCore_arm_arm64
)
1232 if (core2
== ArchSpec::eCore_arm_aarch64
)
1234 if (core2
== ArchSpec::eCore_arm_armv8
)
1236 try_inverse
= false;
1239 case ArchSpec::eCore_arm_aarch64
:
1240 if (!enforce_exact_match
) {
1241 if (core2
== ArchSpec::eCore_arm_arm64
)
1243 if (core2
== ArchSpec::eCore_arm_armv8
)
1245 if (core2
== ArchSpec::eCore_arm_arm64e
)
1247 try_inverse
= false;
1251 case ArchSpec::eCore_arm_arm64
:
1252 if (!enforce_exact_match
) {
1253 if (core2
== ArchSpec::eCore_arm_aarch64
)
1255 if (core2
== ArchSpec::eCore_arm_armv8
)
1257 if (core2
== ArchSpec::eCore_arm_arm64e
)
1259 try_inverse
= false;
1263 case ArchSpec::eCore_arm_arm64_32
:
1264 if (!enforce_exact_match
) {
1265 if (core2
== ArchSpec::eCore_arm_generic
)
1267 try_inverse
= false;
1271 case ArchSpec::eCore_mips32
:
1272 if (!enforce_exact_match
) {
1273 if (core2
>= ArchSpec::kCore_mips32_first
&&
1274 core2
<= ArchSpec::kCore_mips32_last
)
1276 try_inverse
= false;
1280 case ArchSpec::eCore_mips32el
:
1281 if (!enforce_exact_match
) {
1282 if (core2
>= ArchSpec::kCore_mips32el_first
&&
1283 core2
<= ArchSpec::kCore_mips32el_last
)
1289 case ArchSpec::eCore_mips64
:
1290 if (!enforce_exact_match
) {
1291 if (core2
>= ArchSpec::kCore_mips32_first
&&
1292 core2
<= ArchSpec::kCore_mips32_last
)
1294 if (core2
>= ArchSpec::kCore_mips64_first
&&
1295 core2
<= ArchSpec::kCore_mips64_last
)
1297 try_inverse
= false;
1301 case ArchSpec::eCore_mips64el
:
1302 if (!enforce_exact_match
) {
1303 if (core2
>= ArchSpec::kCore_mips32el_first
&&
1304 core2
<= ArchSpec::kCore_mips32el_last
)
1306 if (core2
>= ArchSpec::kCore_mips64el_first
&&
1307 core2
<= ArchSpec::kCore_mips64el_last
)
1309 try_inverse
= false;
1313 case ArchSpec::eCore_mips64r2
:
1314 case ArchSpec::eCore_mips64r3
:
1315 case ArchSpec::eCore_mips64r5
:
1316 if (!enforce_exact_match
) {
1317 if (core2
>= ArchSpec::kCore_mips32_first
&& core2
<= (core1
- 10))
1319 if (core2
>= ArchSpec::kCore_mips64_first
&& core2
<= (core1
- 1))
1321 try_inverse
= false;
1325 case ArchSpec::eCore_mips64r2el
:
1326 case ArchSpec::eCore_mips64r3el
:
1327 case ArchSpec::eCore_mips64r5el
:
1328 if (!enforce_exact_match
) {
1329 if (core2
>= ArchSpec::kCore_mips32el_first
&& core2
<= (core1
- 10))
1331 if (core2
>= ArchSpec::kCore_mips64el_first
&& core2
<= (core1
- 1))
1333 try_inverse
= false;
1337 case ArchSpec::eCore_mips32r2
:
1338 case ArchSpec::eCore_mips32r3
:
1339 case ArchSpec::eCore_mips32r5
:
1340 if (!enforce_exact_match
) {
1341 if (core2
>= ArchSpec::kCore_mips32_first
&& core2
<= core1
)
1346 case ArchSpec::eCore_mips32r2el
:
1347 case ArchSpec::eCore_mips32r3el
:
1348 case ArchSpec::eCore_mips32r5el
:
1349 if (!enforce_exact_match
) {
1350 if (core2
>= ArchSpec::kCore_mips32el_first
&& core2
<= core1
)
1355 case ArchSpec::eCore_mips32r6
:
1356 if (!enforce_exact_match
) {
1357 if (core2
== ArchSpec::eCore_mips32
|| core2
== ArchSpec::eCore_mips32r6
)
1362 case ArchSpec::eCore_mips32r6el
:
1363 if (!enforce_exact_match
) {
1364 if (core2
== ArchSpec::eCore_mips32el
||
1365 core2
== ArchSpec::eCore_mips32r6el
)
1370 case ArchSpec::eCore_mips64r6
:
1371 if (!enforce_exact_match
) {
1372 if (core2
== ArchSpec::eCore_mips32
|| core2
== ArchSpec::eCore_mips32r6
)
1374 if (core2
== ArchSpec::eCore_mips64
|| core2
== ArchSpec::eCore_mips64r6
)
1379 case ArchSpec::eCore_mips64r6el
:
1380 if (!enforce_exact_match
) {
1381 if (core2
== ArchSpec::eCore_mips32el
||
1382 core2
== ArchSpec::eCore_mips32r6el
)
1384 if (core2
== ArchSpec::eCore_mips64el
||
1385 core2
== ArchSpec::eCore_mips64r6el
)
1394 return cores_match(core2
, core1
, false, enforce_exact_match
);
1398 bool lldb_private::operator<(const ArchSpec
&lhs
, const ArchSpec
&rhs
) {
1399 const ArchSpec::Core lhs_core
= lhs
.GetCore();
1400 const ArchSpec::Core rhs_core
= rhs
.GetCore();
1401 return lhs_core
< rhs_core
;
1405 bool lldb_private::operator==(const ArchSpec
&lhs
, const ArchSpec
&rhs
) {
1406 return lhs
.GetCore() == rhs
.GetCore();
1409 bool ArchSpec::IsFullySpecifiedTriple() const {
1410 if (!TripleOSWasSpecified())
1413 if (!TripleVendorWasSpecified())
1416 const unsigned unspecified
= 0;
1417 const llvm::Triple
&triple
= GetTriple();
1418 if (triple
.isOSDarwin() && triple
.getOSMajorVersion() == unspecified
)
1424 void ArchSpec::PiecewiseTripleCompare(
1425 const ArchSpec
&other
, bool &arch_different
, bool &vendor_different
,
1426 bool &os_different
, bool &os_version_different
, bool &env_different
) const {
1427 const llvm::Triple
&me(GetTriple());
1428 const llvm::Triple
&them(other
.GetTriple());
1430 arch_different
= (me
.getArch() != them
.getArch());
1432 vendor_different
= (me
.getVendor() != them
.getVendor());
1434 os_different
= (me
.getOS() != them
.getOS());
1436 os_version_different
= (me
.getOSMajorVersion() != them
.getOSMajorVersion());
1438 env_different
= (me
.getEnvironment() != them
.getEnvironment());
1441 bool ArchSpec::IsAlwaysThumbInstructions() const {
1443 if (GetTriple().getArch() == llvm::Triple::arm
||
1444 GetTriple().getArch() == llvm::Triple::thumb
) {
1445 // v. https://en.wikipedia.org/wiki/ARM_Cortex-M
1447 // Cortex-M0 through Cortex-M7 are ARM processor cores which can only
1448 // execute thumb instructions. We map the cores to arch names like this:
1450 // Cortex-M0, Cortex-M0+, Cortex-M1: armv6m Cortex-M3: armv7m Cortex-M4,
1451 // Cortex-M7: armv7em
1453 if (GetCore() == ArchSpec::Core::eCore_arm_armv7m
||
1454 GetCore() == ArchSpec::Core::eCore_arm_armv7em
||
1455 GetCore() == ArchSpec::Core::eCore_arm_armv6m
||
1456 GetCore() == ArchSpec::Core::eCore_thumbv7m
||
1457 GetCore() == ArchSpec::Core::eCore_thumbv7em
||
1458 GetCore() == ArchSpec::Core::eCore_thumbv6m
) {
1461 // Windows on ARM is always thumb.
1462 if (GetTriple().isOSWindows())
1468 void ArchSpec::DumpTriple(llvm::raw_ostream
&s
) const {
1469 const llvm::Triple
&triple
= GetTriple();
1470 llvm::StringRef arch_str
= triple
.getArchName();
1471 llvm::StringRef vendor_str
= triple
.getVendorName();
1472 llvm::StringRef os_str
= triple
.getOSName();
1473 llvm::StringRef environ_str
= triple
.getEnvironmentName();
1475 s
<< llvm::formatv("{0}-{1}-{2}", arch_str
.empty() ? "*" : arch_str
,
1476 vendor_str
.empty() ? "*" : vendor_str
,
1477 os_str
.empty() ? "*" : os_str
);
1479 if (!environ_str
.empty())
1480 s
<< "-" << environ_str
;