1 //===----------- Triple.cpp - Triple unit tests ---------------------------===//
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 "gtest/gtest.h"
11 #include "llvm/ADT/Triple.h"
12
13 using namespace llvm;
14
15 namespace {
16
TEST(TripleTest,BasicParsing)17 TEST(TripleTest, BasicParsing) {
18 Triple T;
19
20 T = Triple("");
21 EXPECT_EQ("", T.getArchName().str());
22 EXPECT_EQ("", T.getVendorName().str());
23 EXPECT_EQ("", T.getOSName().str());
24 EXPECT_EQ("", T.getEnvironmentName().str());
25
26 T = Triple("-");
27 EXPECT_EQ("", T.getArchName().str());
28 EXPECT_EQ("", T.getVendorName().str());
29 EXPECT_EQ("", T.getOSName().str());
30 EXPECT_EQ("", T.getEnvironmentName().str());
31
32 T = Triple("--");
33 EXPECT_EQ("", T.getArchName().str());
34 EXPECT_EQ("", T.getVendorName().str());
35 EXPECT_EQ("", T.getOSName().str());
36 EXPECT_EQ("", T.getEnvironmentName().str());
37
38 T = Triple("---");
39 EXPECT_EQ("", T.getArchName().str());
40 EXPECT_EQ("", T.getVendorName().str());
41 EXPECT_EQ("", T.getOSName().str());
42 EXPECT_EQ("", T.getEnvironmentName().str());
43
44 T = Triple("----");
45 EXPECT_EQ("", T.getArchName().str());
46 EXPECT_EQ("", T.getVendorName().str());
47 EXPECT_EQ("", T.getOSName().str());
48 EXPECT_EQ("-", T.getEnvironmentName().str());
49
50 T = Triple("a");
51 EXPECT_EQ("a", T.getArchName().str());
52 EXPECT_EQ("", T.getVendorName().str());
53 EXPECT_EQ("", T.getOSName().str());
54 EXPECT_EQ("", T.getEnvironmentName().str());
55
56 T = Triple("a-b");
57 EXPECT_EQ("a", T.getArchName().str());
58 EXPECT_EQ("b", T.getVendorName().str());
59 EXPECT_EQ("", T.getOSName().str());
60 EXPECT_EQ("", T.getEnvironmentName().str());
61
62 T = Triple("a-b-c");
63 EXPECT_EQ("a", T.getArchName().str());
64 EXPECT_EQ("b", T.getVendorName().str());
65 EXPECT_EQ("c", T.getOSName().str());
66 EXPECT_EQ("", T.getEnvironmentName().str());
67
68 T = Triple("a-b-c-d");
69 EXPECT_EQ("a", T.getArchName().str());
70 EXPECT_EQ("b", T.getVendorName().str());
71 EXPECT_EQ("c", T.getOSName().str());
72 EXPECT_EQ("d", T.getEnvironmentName().str());
73 }
74
TEST(TripleTest,ParsedIDs)75 TEST(TripleTest, ParsedIDs) {
76 Triple T;
77
78 T = Triple("i386-apple-darwin");
79 EXPECT_EQ(Triple::x86, T.getArch());
80 EXPECT_EQ(Triple::Apple, T.getVendor());
81 EXPECT_EQ(Triple::Darwin, T.getOS());
82 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
83
84 T = Triple("i386-pc-elfiamcu");
85 EXPECT_EQ(Triple::x86, T.getArch());
86 EXPECT_EQ(Triple::PC, T.getVendor());
87 EXPECT_EQ(Triple::ELFIAMCU, T.getOS());
88 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
89
90 T = Triple("x86_64-pc-linux-gnu");
91 EXPECT_EQ(Triple::x86_64, T.getArch());
92 EXPECT_EQ(Triple::PC, T.getVendor());
93 EXPECT_EQ(Triple::Linux, T.getOS());
94 EXPECT_EQ(Triple::GNU, T.getEnvironment());
95
96 T = Triple("x86_64-pc-linux-musl");
97 EXPECT_EQ(Triple::x86_64, T.getArch());
98 EXPECT_EQ(Triple::PC, T.getVendor());
99 EXPECT_EQ(Triple::Linux, T.getOS());
100 EXPECT_EQ(Triple::Musl, T.getEnvironment());
101
102 T = Triple("powerpc-bgp-linux");
103 EXPECT_EQ(Triple::ppc, T.getArch());
104 EXPECT_EQ(Triple::BGP, T.getVendor());
105 EXPECT_EQ(Triple::Linux, T.getOS());
106 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
107
108 T = Triple("powerpc-bgp-cnk");
109 EXPECT_EQ(Triple::ppc, T.getArch());
110 EXPECT_EQ(Triple::BGP, T.getVendor());
111 EXPECT_EQ(Triple::CNK, T.getOS());
112 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
113
114 T = Triple("powerpc64-bgq-linux");
115 EXPECT_EQ(Triple::ppc64, T.getArch());
116 EXPECT_EQ(Triple::BGQ, T.getVendor());
117 EXPECT_EQ(Triple::Linux, T.getOS());
118 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
119
120 T = Triple("powerpc-ibm-aix");
121 EXPECT_EQ(Triple::ppc, T.getArch());
122 EXPECT_EQ(Triple::IBM, T.getVendor());
123 EXPECT_EQ(Triple::AIX, T.getOS());
124 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
125
126 T = Triple("powerpc64-ibm-aix");
127 EXPECT_EQ(Triple::ppc64, T.getArch());
128 EXPECT_EQ(Triple::IBM, T.getVendor());
129 EXPECT_EQ(Triple::AIX, T.getOS());
130 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
131
132 T = Triple("powerpc-dunno-notsure");
133 EXPECT_EQ(Triple::ppc, T.getArch());
134 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
135 EXPECT_EQ(Triple::UnknownOS, T.getOS());
136 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
137
138 T = Triple("arm-none-none-eabi");
139 EXPECT_EQ(Triple::arm, T.getArch());
140 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
141 EXPECT_EQ(Triple::UnknownOS, T.getOS());
142 EXPECT_EQ(Triple::EABI, T.getEnvironment());
143
144 T = Triple("arm-none-linux-musleabi");
145 EXPECT_EQ(Triple::arm, T.getArch());
146 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
147 EXPECT_EQ(Triple::Linux, T.getOS());
148 EXPECT_EQ(Triple::MuslEABI, T.getEnvironment());
149
150 T = Triple("armv6hl-none-linux-gnueabi");
151 EXPECT_EQ(Triple::arm, T.getArch());
152 EXPECT_EQ(Triple::Linux, T.getOS());
153 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
154 EXPECT_EQ(Triple::GNUEABI, T.getEnvironment());
155
156 T = Triple("armv7hl-none-linux-gnueabi");
157 EXPECT_EQ(Triple::arm, T.getArch());
158 EXPECT_EQ(Triple::Linux, T.getOS());
159 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
160 EXPECT_EQ(Triple::GNUEABI, T.getEnvironment());
161
162 T = Triple("amdil-unknown-unknown");
163 EXPECT_EQ(Triple::amdil, T.getArch());
164 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
165 EXPECT_EQ(Triple::UnknownOS, T.getOS());
166
167 T = Triple("amdil64-unknown-unknown");
168 EXPECT_EQ(Triple::amdil64, T.getArch());
169 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
170 EXPECT_EQ(Triple::UnknownOS, T.getOS());
171
172 T = Triple("hsail-unknown-unknown");
173 EXPECT_EQ(Triple::hsail, T.getArch());
174 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
175 EXPECT_EQ(Triple::UnknownOS, T.getOS());
176
177 T = Triple("hsail64-unknown-unknown");
178 EXPECT_EQ(Triple::hsail64, T.getArch());
179 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
180 EXPECT_EQ(Triple::UnknownOS, T.getOS());
181
182 T = Triple("sparcel-unknown-unknown");
183 EXPECT_EQ(Triple::sparcel, T.getArch());
184 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
185 EXPECT_EQ(Triple::UnknownOS, T.getOS());
186
187 T = Triple("spir-unknown-unknown");
188 EXPECT_EQ(Triple::spir, T.getArch());
189 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
190 EXPECT_EQ(Triple::UnknownOS, T.getOS());
191
192 T = Triple("spir64-unknown-unknown");
193 EXPECT_EQ(Triple::spir64, T.getArch());
194 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
195 EXPECT_EQ(Triple::UnknownOS, T.getOS());
196
197 T = Triple("x86_64-unknown-cloudabi");
198 EXPECT_EQ(Triple::x86_64, T.getArch());
199 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
200 EXPECT_EQ(Triple::CloudABI, T.getOS());
201 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
202
203 T = Triple("wasm32-unknown-unknown");
204 EXPECT_EQ(Triple::wasm32, T.getArch());
205 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
206 EXPECT_EQ(Triple::UnknownOS, T.getOS());
207 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
208
209 T = Triple("wasm64-unknown-unknown");
210 EXPECT_EQ(Triple::wasm64, T.getArch());
211 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
212 EXPECT_EQ(Triple::UnknownOS, T.getOS());
213 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
214
215 T = Triple("avr-unknown-unknown");
216 EXPECT_EQ(Triple::avr, T.getArch());
217 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
218 EXPECT_EQ(Triple::UnknownOS, T.getOS());
219 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
220
221 T = Triple("avr");
222 EXPECT_EQ(Triple::avr, T.getArch());
223 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
224 EXPECT_EQ(Triple::UnknownOS, T.getOS());
225 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
226
227 T = Triple("lanai-unknown-unknown");
228 EXPECT_EQ(Triple::lanai, T.getArch());
229 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
230 EXPECT_EQ(Triple::UnknownOS, T.getOS());
231 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
232
233 T = Triple("lanai");
234 EXPECT_EQ(Triple::lanai, T.getArch());
235 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
236 EXPECT_EQ(Triple::UnknownOS, T.getOS());
237 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
238
239 T = Triple("amdgcn-mesa-mesa3d");
240 EXPECT_EQ(Triple::amdgcn, T.getArch());
241 EXPECT_EQ(Triple::Mesa, T.getVendor());
242 EXPECT_EQ(Triple::Mesa3D, T.getOS());
243 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
244
245 T = Triple("amdgcn-amd-amdhsa");
246 EXPECT_EQ(Triple::amdgcn, T.getArch());
247 EXPECT_EQ(Triple::AMD, T.getVendor());
248 EXPECT_EQ(Triple::AMDHSA, T.getOS());
249 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
250
251 T = Triple("huh");
252 EXPECT_EQ(Triple::UnknownArch, T.getArch());
253 }
254
Join(StringRef A,StringRef B,StringRef C)255 static std::string Join(StringRef A, StringRef B, StringRef C) {
256 std::string Str = A; Str += '-'; Str += B; Str += '-'; Str += C;
257 return Str;
258 }
259
Join(StringRef A,StringRef B,StringRef C,StringRef D)260 static std::string Join(StringRef A, StringRef B, StringRef C, StringRef D) {
261 std::string Str = A; Str += '-'; Str += B; Str += '-'; Str += C; Str += '-';
262 Str += D; return Str;
263 }
264
TEST(TripleTest,Normalization)265 TEST(TripleTest, Normalization) {
266
267 EXPECT_EQ("", Triple::normalize(""));
268 EXPECT_EQ("-", Triple::normalize("-"));
269 EXPECT_EQ("--", Triple::normalize("--"));
270 EXPECT_EQ("---", Triple::normalize("---"));
271 EXPECT_EQ("----", Triple::normalize("----"));
272
273 EXPECT_EQ("a", Triple::normalize("a"));
274 EXPECT_EQ("a-b", Triple::normalize("a-b"));
275 EXPECT_EQ("a-b-c", Triple::normalize("a-b-c"));
276 EXPECT_EQ("a-b-c-d", Triple::normalize("a-b-c-d"));
277
278 EXPECT_EQ("i386-b-c", Triple::normalize("i386-b-c"));
279 EXPECT_EQ("i386-a-c", Triple::normalize("a-i386-c"));
280 EXPECT_EQ("i386-a-b", Triple::normalize("a-b-i386"));
281 EXPECT_EQ("i386-a-b-c", Triple::normalize("a-b-c-i386"));
282
283 EXPECT_EQ("a-pc-c", Triple::normalize("a-pc-c"));
284 EXPECT_EQ("-pc-b-c", Triple::normalize("pc-b-c"));
285 EXPECT_EQ("a-pc-b", Triple::normalize("a-b-pc"));
286 EXPECT_EQ("a-pc-b-c", Triple::normalize("a-b-c-pc"));
287
288 EXPECT_EQ("a-b-linux", Triple::normalize("a-b-linux"));
289 EXPECT_EQ("--linux-b-c", Triple::normalize("linux-b-c"));
290 EXPECT_EQ("a--linux-c", Triple::normalize("a-linux-c"));
291
292 EXPECT_EQ("i386-pc-a", Triple::normalize("a-pc-i386"));
293 EXPECT_EQ("i386-pc-", Triple::normalize("-pc-i386"));
294 EXPECT_EQ("-pc-linux-c", Triple::normalize("linux-pc-c"));
295 EXPECT_EQ("-pc-linux", Triple::normalize("linux-pc-"));
296
297 EXPECT_EQ("i386", Triple::normalize("i386"));
298 EXPECT_EQ("-pc", Triple::normalize("pc"));
299 EXPECT_EQ("--linux", Triple::normalize("linux"));
300
301 EXPECT_EQ("x86_64--linux-gnu", Triple::normalize("x86_64-gnu-linux"));
302
303 // Check that normalizing a permutated set of valid components returns a
304 // triple with the unpermuted components.
305 StringRef C[4];
306 for (int Arch = 1+Triple::UnknownArch; Arch <= Triple::LastArchType; ++Arch) {
307 C[0] = Triple::getArchTypeName(Triple::ArchType(Arch));
308 for (int Vendor = 1+Triple::UnknownVendor; Vendor <= Triple::LastVendorType;
309 ++Vendor) {
310 C[1] = Triple::getVendorTypeName(Triple::VendorType(Vendor));
311 for (int OS = 1+Triple::UnknownOS; OS <= Triple::LastOSType; ++OS) {
312 if (OS == Triple::Win32)
313 continue;
314
315 C[2] = Triple::getOSTypeName(Triple::OSType(OS));
316
317 std::string E = Join(C[0], C[1], C[2]);
318 EXPECT_EQ(E, Triple::normalize(Join(C[0], C[1], C[2])));
319
320 EXPECT_EQ(E, Triple::normalize(Join(C[0], C[2], C[1])));
321 EXPECT_EQ(E, Triple::normalize(Join(C[1], C[2], C[0])));
322 EXPECT_EQ(E, Triple::normalize(Join(C[1], C[0], C[2])));
323 EXPECT_EQ(E, Triple::normalize(Join(C[2], C[0], C[1])));
324 EXPECT_EQ(E, Triple::normalize(Join(C[2], C[1], C[0])));
325
326 for (int Env = 1 + Triple::UnknownEnvironment; Env <= Triple::LastEnvironmentType;
327 ++Env) {
328 C[3] = Triple::getEnvironmentTypeName(Triple::EnvironmentType(Env));
329
330 std::string F = Join(C[0], C[1], C[2], C[3]);
331 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[1], C[2], C[3])));
332
333 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[1], C[3], C[2])));
334 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[2], C[3], C[1])));
335 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[2], C[1], C[3])));
336 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[3], C[1], C[2])));
337 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[3], C[2], C[1])));
338 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[2], C[3], C[0])));
339 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[2], C[0], C[3])));
340 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[3], C[0], C[2])));
341 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[3], C[2], C[0])));
342 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[0], C[2], C[3])));
343 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[0], C[3], C[2])));
344 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[3], C[0], C[1])));
345 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[3], C[1], C[0])));
346 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[0], C[1], C[3])));
347 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[0], C[3], C[1])));
348 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[1], C[3], C[0])));
349 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[1], C[0], C[3])));
350 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[0], C[1], C[2])));
351 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[0], C[2], C[1])));
352 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[1], C[2], C[0])));
353 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[1], C[0], C[2])));
354 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[2], C[0], C[1])));
355 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[2], C[1], C[0])));
356 }
357 }
358 }
359 }
360
361 // Various real-world funky triples. The value returned by GCC's config.sub
362 // is given in the comment.
363 EXPECT_EQ("i386--windows-gnu", Triple::normalize("i386-mingw32")); // i386-pc-mingw32
364 EXPECT_EQ("x86_64--linux-gnu", Triple::normalize("x86_64-linux-gnu")); // x86_64-pc-linux-gnu
365 EXPECT_EQ("i486--linux-gnu", Triple::normalize("i486-linux-gnu")); // i486-pc-linux-gnu
366 EXPECT_EQ("i386-redhat-linux", Triple::normalize("i386-redhat-linux")); // i386-redhat-linux-gnu
367 EXPECT_EQ("i686--linux", Triple::normalize("i686-linux")); // i686-pc-linux-gnu
368 EXPECT_EQ("arm-none--eabi", Triple::normalize("arm-none-eabi")); // arm-none-eabi
369 }
370
TEST(TripleTest,MutateName)371 TEST(TripleTest, MutateName) {
372 Triple T;
373 EXPECT_EQ(Triple::UnknownArch, T.getArch());
374 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
375 EXPECT_EQ(Triple::UnknownOS, T.getOS());
376 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
377
378 T.setArchName("i386");
379 EXPECT_EQ(Triple::x86, T.getArch());
380 EXPECT_EQ("i386--", T.getTriple());
381
382 T.setVendorName("pc");
383 EXPECT_EQ(Triple::x86, T.getArch());
384 EXPECT_EQ(Triple::PC, T.getVendor());
385 EXPECT_EQ("i386-pc-", T.getTriple());
386
387 T.setOSName("linux");
388 EXPECT_EQ(Triple::x86, T.getArch());
389 EXPECT_EQ(Triple::PC, T.getVendor());
390 EXPECT_EQ(Triple::Linux, T.getOS());
391 EXPECT_EQ("i386-pc-linux", T.getTriple());
392
393 T.setEnvironmentName("gnu");
394 EXPECT_EQ(Triple::x86, T.getArch());
395 EXPECT_EQ(Triple::PC, T.getVendor());
396 EXPECT_EQ(Triple::Linux, T.getOS());
397 EXPECT_EQ("i386-pc-linux-gnu", T.getTriple());
398
399 T.setOSName("freebsd");
400 EXPECT_EQ(Triple::x86, T.getArch());
401 EXPECT_EQ(Triple::PC, T.getVendor());
402 EXPECT_EQ(Triple::FreeBSD, T.getOS());
403 EXPECT_EQ("i386-pc-freebsd-gnu", T.getTriple());
404
405 T.setOSAndEnvironmentName("darwin");
406 EXPECT_EQ(Triple::x86, T.getArch());
407 EXPECT_EQ(Triple::PC, T.getVendor());
408 EXPECT_EQ(Triple::Darwin, T.getOS());
409 EXPECT_EQ("i386-pc-darwin", T.getTriple());
410
411 T.setEnvironmentName("amdopencl");
412 EXPECT_EQ(Triple::AMDOpenCL, T.getEnvironment());
413 }
414
TEST(TripleTest,BitWidthPredicates)415 TEST(TripleTest, BitWidthPredicates) {
416 Triple T;
417 EXPECT_FALSE(T.isArch16Bit());
418 EXPECT_FALSE(T.isArch32Bit());
419 EXPECT_FALSE(T.isArch64Bit());
420
421 T.setArch(Triple::arm);
422 EXPECT_FALSE(T.isArch16Bit());
423 EXPECT_TRUE(T.isArch32Bit());
424 EXPECT_FALSE(T.isArch64Bit());
425
426 T.setArch(Triple::hexagon);
427 EXPECT_FALSE(T.isArch16Bit());
428 EXPECT_TRUE(T.isArch32Bit());
429 EXPECT_FALSE(T.isArch64Bit());
430
431 T.setArch(Triple::mips);
432 EXPECT_FALSE(T.isArch16Bit());
433 EXPECT_TRUE(T.isArch32Bit());
434 EXPECT_FALSE(T.isArch64Bit());
435
436 T.setArch(Triple::mips64);
437 EXPECT_FALSE(T.isArch16Bit());
438 EXPECT_FALSE(T.isArch32Bit());
439 EXPECT_TRUE(T.isArch64Bit());
440
441 T.setArch(Triple::msp430);
442 EXPECT_TRUE(T.isArch16Bit());
443 EXPECT_FALSE(T.isArch32Bit());
444 EXPECT_FALSE(T.isArch64Bit());
445
446 T.setArch(Triple::ppc);
447 EXPECT_FALSE(T.isArch16Bit());
448 EXPECT_TRUE(T.isArch32Bit());
449 EXPECT_FALSE(T.isArch64Bit());
450
451 T.setArch(Triple::ppc64);
452 EXPECT_FALSE(T.isArch16Bit());
453 EXPECT_FALSE(T.isArch32Bit());
454 EXPECT_TRUE(T.isArch64Bit());
455
456 T.setArch(Triple::x86);
457 EXPECT_FALSE(T.isArch16Bit());
458 EXPECT_TRUE(T.isArch32Bit());
459 EXPECT_FALSE(T.isArch64Bit());
460
461 T.setArch(Triple::x86_64);
462 EXPECT_FALSE(T.isArch16Bit());
463 EXPECT_FALSE(T.isArch32Bit());
464 EXPECT_TRUE(T.isArch64Bit());
465
466 T.setArch(Triple::amdil);
467 EXPECT_FALSE(T.isArch16Bit());
468 EXPECT_TRUE(T.isArch32Bit());
469 EXPECT_FALSE(T.isArch64Bit());
470
471 T.setArch(Triple::amdil64);
472 EXPECT_FALSE(T.isArch16Bit());
473 EXPECT_FALSE(T.isArch32Bit());
474 EXPECT_TRUE(T.isArch64Bit());
475
476 T.setArch(Triple::hsail);
477 EXPECT_FALSE(T.isArch16Bit());
478 EXPECT_TRUE(T.isArch32Bit());
479 EXPECT_FALSE(T.isArch64Bit());
480
481 T.setArch(Triple::hsail64);
482 EXPECT_FALSE(T.isArch16Bit());
483 EXPECT_FALSE(T.isArch32Bit());
484 EXPECT_TRUE(T.isArch64Bit());
485
486 T.setArch(Triple::spir);
487 EXPECT_FALSE(T.isArch16Bit());
488 EXPECT_TRUE(T.isArch32Bit());
489 EXPECT_FALSE(T.isArch64Bit());
490
491 T.setArch(Triple::spir64);
492 EXPECT_FALSE(T.isArch16Bit());
493 EXPECT_FALSE(T.isArch32Bit());
494 EXPECT_TRUE(T.isArch64Bit());
495
496 T.setArch(Triple::sparc);
497 EXPECT_FALSE(T.isArch16Bit());
498 EXPECT_TRUE(T.isArch32Bit());
499 EXPECT_FALSE(T.isArch64Bit());
500
501 T.setArch(Triple::sparcel);
502 EXPECT_FALSE(T.isArch16Bit());
503 EXPECT_TRUE(T.isArch32Bit());
504 EXPECT_FALSE(T.isArch64Bit());
505
506 T.setArch(Triple::sparcv9);
507 EXPECT_FALSE(T.isArch16Bit());
508 EXPECT_FALSE(T.isArch32Bit());
509 EXPECT_TRUE(T.isArch64Bit());
510
511 T.setArch(Triple::wasm32);
512 EXPECT_FALSE(T.isArch16Bit());
513 EXPECT_TRUE(T.isArch32Bit());
514 EXPECT_FALSE(T.isArch64Bit());
515
516 T.setArch(Triple::wasm64);
517 EXPECT_FALSE(T.isArch16Bit());
518 EXPECT_FALSE(T.isArch32Bit());
519 EXPECT_TRUE(T.isArch64Bit());
520
521 T.setArch(Triple::avr);
522 EXPECT_TRUE(T.isArch16Bit());
523 EXPECT_FALSE(T.isArch32Bit());
524 EXPECT_FALSE(T.isArch64Bit());
525
526 T.setArch(Triple::lanai);
527 EXPECT_FALSE(T.isArch16Bit());
528 EXPECT_TRUE(T.isArch32Bit());
529 EXPECT_FALSE(T.isArch64Bit());
530 }
531
TEST(TripleTest,BitWidthArchVariants)532 TEST(TripleTest, BitWidthArchVariants) {
533 Triple T;
534 EXPECT_EQ(Triple::UnknownArch, T.get32BitArchVariant().getArch());
535 EXPECT_EQ(Triple::UnknownArch, T.get64BitArchVariant().getArch());
536
537 T.setArch(Triple::UnknownArch);
538 EXPECT_EQ(Triple::UnknownArch, T.get32BitArchVariant().getArch());
539 EXPECT_EQ(Triple::UnknownArch, T.get64BitArchVariant().getArch());
540
541 T.setArch(Triple::mips);
542 EXPECT_EQ(Triple::mips, T.get32BitArchVariant().getArch());
543 EXPECT_EQ(Triple::mips64, T.get64BitArchVariant().getArch());
544
545 T.setArch(Triple::mipsel);
546 EXPECT_EQ(Triple::mipsel, T.get32BitArchVariant().getArch());
547 EXPECT_EQ(Triple::mips64el, T.get64BitArchVariant().getArch());
548
549 T.setArch(Triple::ppc);
550 EXPECT_EQ(Triple::ppc, T.get32BitArchVariant().getArch());
551 EXPECT_EQ(Triple::ppc64, T.get64BitArchVariant().getArch());
552
553 T.setArch(Triple::nvptx);
554 EXPECT_EQ(Triple::nvptx, T.get32BitArchVariant().getArch());
555 EXPECT_EQ(Triple::nvptx64, T.get64BitArchVariant().getArch());
556
557 T.setArch(Triple::sparc);
558 EXPECT_EQ(Triple::sparc, T.get32BitArchVariant().getArch());
559 EXPECT_EQ(Triple::sparcv9, T.get64BitArchVariant().getArch());
560
561 T.setArch(Triple::x86);
562 EXPECT_EQ(Triple::x86, T.get32BitArchVariant().getArch());
563 EXPECT_EQ(Triple::x86_64, T.get64BitArchVariant().getArch());
564
565 T.setArch(Triple::mips64);
566 EXPECT_EQ(Triple::mips, T.get32BitArchVariant().getArch());
567 EXPECT_EQ(Triple::mips64, T.get64BitArchVariant().getArch());
568
569 T.setArch(Triple::mips64el);
570 EXPECT_EQ(Triple::mipsel, T.get32BitArchVariant().getArch());
571 EXPECT_EQ(Triple::mips64el, T.get64BitArchVariant().getArch());
572
573 T.setArch(Triple::ppc64);
574 EXPECT_EQ(Triple::ppc, T.get32BitArchVariant().getArch());
575 EXPECT_EQ(Triple::ppc64, T.get64BitArchVariant().getArch());
576
577 T.setArch(Triple::nvptx64);
578 EXPECT_EQ(Triple::nvptx, T.get32BitArchVariant().getArch());
579 EXPECT_EQ(Triple::nvptx64, T.get64BitArchVariant().getArch());
580
581 T.setArch(Triple::sparcv9);
582 EXPECT_EQ(Triple::sparc, T.get32BitArchVariant().getArch());
583 EXPECT_EQ(Triple::sparcv9, T.get64BitArchVariant().getArch());
584
585 T.setArch(Triple::x86_64);
586 EXPECT_EQ(Triple::x86, T.get32BitArchVariant().getArch());
587 EXPECT_EQ(Triple::x86_64, T.get64BitArchVariant().getArch());
588
589 T.setArch(Triple::amdil);
590 EXPECT_EQ(Triple::amdil, T.get32BitArchVariant().getArch());
591 EXPECT_EQ(Triple::amdil64, T.get64BitArchVariant().getArch());
592
593 T.setArch(Triple::amdil64);
594 EXPECT_EQ(Triple::amdil, T.get32BitArchVariant().getArch());
595 EXPECT_EQ(Triple::amdil64, T.get64BitArchVariant().getArch());
596
597 T.setArch(Triple::hsail);
598 EXPECT_EQ(Triple::hsail, T.get32BitArchVariant().getArch());
599 EXPECT_EQ(Triple::hsail64, T.get64BitArchVariant().getArch());
600
601 T.setArch(Triple::hsail64);
602 EXPECT_EQ(Triple::hsail, T.get32BitArchVariant().getArch());
603 EXPECT_EQ(Triple::hsail64, T.get64BitArchVariant().getArch());
604
605 T.setArch(Triple::spir);
606 EXPECT_EQ(Triple::spir, T.get32BitArchVariant().getArch());
607 EXPECT_EQ(Triple::spir64, T.get64BitArchVariant().getArch());
608
609 T.setArch(Triple::spir64);
610 EXPECT_EQ(Triple::spir, T.get32BitArchVariant().getArch());
611 EXPECT_EQ(Triple::spir64, T.get64BitArchVariant().getArch());
612
613 T.setArch(Triple::wasm32);
614 EXPECT_EQ(Triple::wasm32, T.get32BitArchVariant().getArch());
615 EXPECT_EQ(Triple::wasm64, T.get64BitArchVariant().getArch());
616
617 T.setArch(Triple::wasm64);
618 EXPECT_EQ(Triple::wasm32, T.get32BitArchVariant().getArch());
619 EXPECT_EQ(Triple::wasm64, T.get64BitArchVariant().getArch());
620 }
621
TEST(TripleTest,EndianArchVariants)622 TEST(TripleTest, EndianArchVariants) {
623 Triple T;
624 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
625 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
626
627 T.setArch(Triple::UnknownArch);
628 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
629 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
630
631 T.setArch(Triple::aarch64_be);
632 EXPECT_EQ(Triple::aarch64_be, T.getBigEndianArchVariant().getArch());
633 EXPECT_EQ(Triple::aarch64, T.getLittleEndianArchVariant().getArch());
634
635 T.setArch(Triple::aarch64);
636 EXPECT_EQ(Triple::aarch64_be, T.getBigEndianArchVariant().getArch());
637 EXPECT_EQ(Triple::aarch64, T.getLittleEndianArchVariant().getArch());
638
639 T.setArch(Triple::armeb);
640 EXPECT_EQ(Triple::armeb, T.getBigEndianArchVariant().getArch());
641 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
642
643 T.setArch(Triple::arm);
644 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
645 EXPECT_EQ(Triple::arm, T.getLittleEndianArchVariant().getArch());
646 T = Triple("arm");
647 EXPECT_TRUE(T.isLittleEndian());
648 T = Triple("thumb");
649 EXPECT_TRUE(T.isLittleEndian());
650 T = Triple("armeb");
651 EXPECT_FALSE(T.isLittleEndian());
652 T = Triple("thumbeb");
653 EXPECT_FALSE(T.isLittleEndian());
654
655 T.setArch(Triple::bpfeb);
656 EXPECT_EQ(Triple::bpfeb, T.getBigEndianArchVariant().getArch());
657 EXPECT_EQ(Triple::bpfel, T.getLittleEndianArchVariant().getArch());
658
659 T.setArch(Triple::bpfel);
660 EXPECT_EQ(Triple::bpfeb, T.getBigEndianArchVariant().getArch());
661 EXPECT_EQ(Triple::bpfel, T.getLittleEndianArchVariant().getArch());
662
663 T.setArch(Triple::mips64);
664 EXPECT_EQ(Triple::mips64, T.getBigEndianArchVariant().getArch());
665 EXPECT_EQ(Triple::mips64el, T.getLittleEndianArchVariant().getArch());
666
667 T.setArch(Triple::mips64el);
668 EXPECT_EQ(Triple::mips64, T.getBigEndianArchVariant().getArch());
669 EXPECT_EQ(Triple::mips64el, T.getLittleEndianArchVariant().getArch());
670
671 T.setArch(Triple::mips);
672 EXPECT_EQ(Triple::mips, T.getBigEndianArchVariant().getArch());
673 EXPECT_EQ(Triple::mipsel, T.getLittleEndianArchVariant().getArch());
674
675 T.setArch(Triple::mipsel);
676 EXPECT_EQ(Triple::mips, T.getBigEndianArchVariant().getArch());
677 EXPECT_EQ(Triple::mipsel, T.getLittleEndianArchVariant().getArch());
678
679 T.setArch(Triple::ppc);
680 EXPECT_EQ(Triple::ppc, T.getBigEndianArchVariant().getArch());
681 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
682
683 T.setArch(Triple::ppc64);
684 EXPECT_EQ(Triple::ppc64, T.getBigEndianArchVariant().getArch());
685 EXPECT_EQ(Triple::ppc64le, T.getLittleEndianArchVariant().getArch());
686
687 T.setArch(Triple::ppc64le);
688 EXPECT_EQ(Triple::ppc64, T.getBigEndianArchVariant().getArch());
689 EXPECT_EQ(Triple::ppc64le, T.getLittleEndianArchVariant().getArch());
690
691 T.setArch(Triple::sparc);
692 EXPECT_EQ(Triple::sparc, T.getBigEndianArchVariant().getArch());
693 EXPECT_EQ(Triple::sparcel, T.getLittleEndianArchVariant().getArch());
694
695 T.setArch(Triple::sparcel);
696 EXPECT_EQ(Triple::sparc, T.getBigEndianArchVariant().getArch());
697 EXPECT_EQ(Triple::sparcel, T.getLittleEndianArchVariant().getArch());
698
699 T.setArch(Triple::thumb);
700 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
701 EXPECT_EQ(Triple::thumb, T.getLittleEndianArchVariant().getArch());
702
703 T.setArch(Triple::thumbeb);
704 EXPECT_EQ(Triple::thumbeb, T.getBigEndianArchVariant().getArch());
705 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
706
707 T.setArch(Triple::lanai);
708 EXPECT_EQ(Triple::lanai, T.getBigEndianArchVariant().getArch());
709 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
710 }
711
TEST(TripleTest,getOSVersion)712 TEST(TripleTest, getOSVersion) {
713 Triple T;
714 unsigned Major, Minor, Micro;
715
716 T = Triple("i386-apple-darwin9");
717 EXPECT_TRUE(T.isMacOSX());
718 EXPECT_FALSE(T.isiOS());
719 EXPECT_FALSE(T.isArch16Bit());
720 EXPECT_TRUE(T.isArch32Bit());
721 EXPECT_FALSE(T.isArch64Bit());
722 T.getMacOSXVersion(Major, Minor, Micro);
723 EXPECT_EQ((unsigned)10, Major);
724 EXPECT_EQ((unsigned)5, Minor);
725 EXPECT_EQ((unsigned)0, Micro);
726 T.getiOSVersion(Major, Minor, Micro);
727 EXPECT_EQ((unsigned)5, Major);
728 EXPECT_EQ((unsigned)0, Minor);
729 EXPECT_EQ((unsigned)0, Micro);
730
731 T = Triple("x86_64-apple-darwin9");
732 EXPECT_TRUE(T.isMacOSX());
733 EXPECT_FALSE(T.isiOS());
734 EXPECT_FALSE(T.isArch16Bit());
735 EXPECT_FALSE(T.isArch32Bit());
736 EXPECT_TRUE(T.isArch64Bit());
737 T.getMacOSXVersion(Major, Minor, Micro);
738 EXPECT_EQ((unsigned)10, Major);
739 EXPECT_EQ((unsigned)5, Minor);
740 EXPECT_EQ((unsigned)0, Micro);
741 T.getiOSVersion(Major, Minor, Micro);
742 EXPECT_EQ((unsigned)5, Major);
743 EXPECT_EQ((unsigned)0, Minor);
744 EXPECT_EQ((unsigned)0, Micro);
745
746 T = Triple("x86_64-apple-macosx");
747 EXPECT_TRUE(T.isMacOSX());
748 EXPECT_FALSE(T.isiOS());
749 EXPECT_FALSE(T.isArch16Bit());
750 EXPECT_FALSE(T.isArch32Bit());
751 EXPECT_TRUE(T.isArch64Bit());
752 T.getMacOSXVersion(Major, Minor, Micro);
753 EXPECT_EQ((unsigned)10, Major);
754 EXPECT_EQ((unsigned)4, Minor);
755 EXPECT_EQ((unsigned)0, Micro);
756 T.getiOSVersion(Major, Minor, Micro);
757 EXPECT_EQ((unsigned)5, Major);
758 EXPECT_EQ((unsigned)0, Minor);
759 EXPECT_EQ((unsigned)0, Micro);
760
761 T = Triple("x86_64-apple-macosx10.7");
762 EXPECT_TRUE(T.isMacOSX());
763 EXPECT_FALSE(T.isiOS());
764 EXPECT_FALSE(T.isArch16Bit());
765 EXPECT_FALSE(T.isArch32Bit());
766 EXPECT_TRUE(T.isArch64Bit());
767 T.getMacOSXVersion(Major, Minor, Micro);
768 EXPECT_EQ((unsigned)10, Major);
769 EXPECT_EQ((unsigned)7, Minor);
770 EXPECT_EQ((unsigned)0, Micro);
771 T.getiOSVersion(Major, Minor, Micro);
772 EXPECT_EQ((unsigned)5, Major);
773 EXPECT_EQ((unsigned)0, Minor);
774 EXPECT_EQ((unsigned)0, Micro);
775
776 T = Triple("armv7-apple-ios");
777 EXPECT_FALSE(T.isMacOSX());
778 EXPECT_TRUE(T.isiOS());
779 EXPECT_FALSE(T.isArch16Bit());
780 EXPECT_TRUE(T.isArch32Bit());
781 EXPECT_FALSE(T.isArch64Bit());
782 T.getMacOSXVersion(Major, Minor, Micro);
783 EXPECT_EQ((unsigned)10, Major);
784 EXPECT_EQ((unsigned)4, Minor);
785 EXPECT_EQ((unsigned)0, Micro);
786 T.getiOSVersion(Major, Minor, Micro);
787 EXPECT_EQ((unsigned)5, Major);
788 EXPECT_EQ((unsigned)0, Minor);
789 EXPECT_EQ((unsigned)0, Micro);
790
791 T = Triple("armv7-apple-ios7.0");
792 EXPECT_FALSE(T.isMacOSX());
793 EXPECT_TRUE(T.isiOS());
794 EXPECT_FALSE(T.isArch16Bit());
795 EXPECT_TRUE(T.isArch32Bit());
796 EXPECT_FALSE(T.isArch64Bit());
797 T.getMacOSXVersion(Major, Minor, Micro);
798 EXPECT_EQ((unsigned)10, Major);
799 EXPECT_EQ((unsigned)4, Minor);
800 EXPECT_EQ((unsigned)0, Micro);
801 T.getiOSVersion(Major, Minor, Micro);
802 EXPECT_EQ((unsigned)7, Major);
803 EXPECT_EQ((unsigned)0, Minor);
804 EXPECT_EQ((unsigned)0, Micro);
805 }
806
TEST(TripleTest,FileFormat)807 TEST(TripleTest, FileFormat) {
808 EXPECT_EQ(Triple::ELF, Triple("i686-unknown-linux-gnu").getObjectFormat());
809 EXPECT_EQ(Triple::ELF, Triple("i686-unknown-freebsd").getObjectFormat());
810 EXPECT_EQ(Triple::ELF, Triple("i686-unknown-netbsd").getObjectFormat());
811 EXPECT_EQ(Triple::ELF, Triple("i686--win32-elf").getObjectFormat());
812 EXPECT_EQ(Triple::ELF, Triple("i686---elf").getObjectFormat());
813
814 EXPECT_EQ(Triple::MachO, Triple("i686-apple-macosx").getObjectFormat());
815 EXPECT_EQ(Triple::MachO, Triple("i686-apple-ios").getObjectFormat());
816 EXPECT_EQ(Triple::MachO, Triple("i686---macho").getObjectFormat());
817
818 EXPECT_EQ(Triple::COFF, Triple("i686--win32").getObjectFormat());
819
820 EXPECT_EQ(Triple::ELF, Triple("i686-pc-windows-msvc-elf").getObjectFormat());
821 EXPECT_EQ(Triple::ELF, Triple("i686-pc-cygwin-elf").getObjectFormat());
822
823 Triple MSVCNormalized(Triple::normalize("i686-pc-windows-msvc-elf"));
824 EXPECT_EQ(Triple::ELF, MSVCNormalized.getObjectFormat());
825
826 Triple GNUWindowsNormalized(Triple::normalize("i686-pc-windows-gnu-elf"));
827 EXPECT_EQ(Triple::ELF, GNUWindowsNormalized.getObjectFormat());
828
829 Triple CygnusNormalised(Triple::normalize("i686-pc-windows-cygnus-elf"));
830 EXPECT_EQ(Triple::ELF, CygnusNormalised.getObjectFormat());
831
832 Triple CygwinNormalized(Triple::normalize("i686-pc-cygwin-elf"));
833 EXPECT_EQ(Triple::ELF, CygwinNormalized.getObjectFormat());
834
835 Triple T = Triple("");
836 T.setObjectFormat(Triple::ELF);
837 EXPECT_EQ(Triple::ELF, T.getObjectFormat());
838 }
839
TEST(TripleTest,NormalizeWindows)840 TEST(TripleTest, NormalizeWindows) {
841 EXPECT_EQ("i686-pc-windows-msvc", Triple::normalize("i686-pc-win32"));
842 EXPECT_EQ("i686--windows-msvc", Triple::normalize("i686-win32"));
843 EXPECT_EQ("i686-pc-windows-gnu", Triple::normalize("i686-pc-mingw32"));
844 EXPECT_EQ("i686--windows-gnu", Triple::normalize("i686-mingw32"));
845 EXPECT_EQ("i686-pc-windows-gnu", Triple::normalize("i686-pc-mingw32-w64"));
846 EXPECT_EQ("i686--windows-gnu", Triple::normalize("i686-mingw32-w64"));
847 EXPECT_EQ("i686-pc-windows-cygnus", Triple::normalize("i686-pc-cygwin"));
848 EXPECT_EQ("i686--windows-cygnus", Triple::normalize("i686-cygwin"));
849
850 EXPECT_EQ("x86_64-pc-windows-msvc", Triple::normalize("x86_64-pc-win32"));
851 EXPECT_EQ("x86_64--windows-msvc", Triple::normalize("x86_64-win32"));
852 EXPECT_EQ("x86_64-pc-windows-gnu", Triple::normalize("x86_64-pc-mingw32"));
853 EXPECT_EQ("x86_64--windows-gnu", Triple::normalize("x86_64-mingw32"));
854 EXPECT_EQ("x86_64-pc-windows-gnu", Triple::normalize("x86_64-pc-mingw32-w64"));
855 EXPECT_EQ("x86_64--windows-gnu", Triple::normalize("x86_64-mingw32-w64"));
856
857 EXPECT_EQ("i686-pc-windows-elf", Triple::normalize("i686-pc-win32-elf"));
858 EXPECT_EQ("i686--windows-elf", Triple::normalize("i686-win32-elf"));
859 EXPECT_EQ("i686-pc-windows-macho", Triple::normalize("i686-pc-win32-macho"));
860 EXPECT_EQ("i686--windows-macho", Triple::normalize("i686-win32-macho"));
861
862 EXPECT_EQ("x86_64-pc-windows-elf", Triple::normalize("x86_64-pc-win32-elf"));
863 EXPECT_EQ("x86_64--windows-elf", Triple::normalize("x86_64-win32-elf"));
864 EXPECT_EQ("x86_64-pc-windows-macho", Triple::normalize("x86_64-pc-win32-macho"));
865 EXPECT_EQ("x86_64--windows-macho", Triple::normalize("x86_64-win32-macho"));
866
867 EXPECT_EQ("i686-pc-windows-cygnus",
868 Triple::normalize("i686-pc-windows-cygnus"));
869 EXPECT_EQ("i686-pc-windows-gnu", Triple::normalize("i686-pc-windows-gnu"));
870 EXPECT_EQ("i686-pc-windows-itanium", Triple::normalize("i686-pc-windows-itanium"));
871 EXPECT_EQ("i686-pc-windows-msvc", Triple::normalize("i686-pc-windows-msvc"));
872
873 EXPECT_EQ("i686-pc-windows-elf", Triple::normalize("i686-pc-windows-elf-elf"));
874 }
875
TEST(TripleTest,getARMCPUForArch)876 TEST(TripleTest, getARMCPUForArch) {
877 // Standard ARM Architectures.
878 {
879 llvm::Triple Triple("armv4-unknown-eabi");
880 EXPECT_EQ("strongarm", Triple.getARMCPUForArch());
881 }
882 {
883 llvm::Triple Triple("armv4t-unknown-eabi");
884 EXPECT_EQ("arm7tdmi", Triple.getARMCPUForArch());
885 }
886 {
887 llvm::Triple Triple("armv5-unknown-eabi");
888 EXPECT_EQ("arm10tdmi", Triple.getARMCPUForArch());
889 }
890 {
891 llvm::Triple Triple("armv5t-unknown-eabi");
892 EXPECT_EQ("arm10tdmi", Triple.getARMCPUForArch());
893 }
894 {
895 llvm::Triple Triple("armv5e-unknown-eabi");
896 EXPECT_EQ("arm1022e", Triple.getARMCPUForArch());
897 }
898 {
899 llvm::Triple Triple("armv5tej-unknown-eabi");
900 EXPECT_EQ("arm926ej-s", Triple.getARMCPUForArch());
901 }
902 {
903 llvm::Triple Triple("armv6-unknown-eabi");
904 EXPECT_EQ("arm1136jf-s", Triple.getARMCPUForArch());
905 }
906 {
907 llvm::Triple Triple("armv6j-unknown-eabi");
908 EXPECT_EQ("arm1136jf-s", Triple.getARMCPUForArch());
909 }
910 {
911 llvm::Triple Triple("armv6k-unknown-eabi");
912 EXPECT_EQ("arm1176j-s", Triple.getARMCPUForArch());
913 }
914 {
915 llvm::Triple Triple("armv6kz-unknown-eabi");
916 EXPECT_EQ("arm1176jzf-s", Triple.getARMCPUForArch());
917 }
918 {
919 llvm::Triple Triple("armv6zk-unknown-eabi");
920 EXPECT_EQ("arm1176jzf-s", Triple.getARMCPUForArch());
921 }
922 {
923 llvm::Triple Triple("armv6t2-unknown-eabi");
924 EXPECT_EQ("arm1156t2-s", Triple.getARMCPUForArch());
925 }
926 {
927 llvm::Triple Triple("armv6m-unknown-eabi");
928 EXPECT_EQ("cortex-m0", Triple.getARMCPUForArch());
929 }
930 {
931 llvm::Triple Triple("armv7-unknown-eabi");
932 EXPECT_EQ("cortex-a8", Triple.getARMCPUForArch());
933 }
934 {
935 llvm::Triple Triple("armv7a-unknown-eabi");
936 EXPECT_EQ("cortex-a8", Triple.getARMCPUForArch());
937 }
938 {
939 llvm::Triple Triple("armv7m-unknown-eabi");
940 EXPECT_EQ("cortex-m3", Triple.getARMCPUForArch());
941 }
942 {
943 llvm::Triple Triple("armv7r-unknown-eabi");
944 EXPECT_EQ("cortex-r4", Triple.getARMCPUForArch());
945 }
946 {
947 llvm::Triple Triple("armv7r-unknown-eabi");
948 EXPECT_EQ("cortex-r4", Triple.getARMCPUForArch());
949 }
950 {
951 llvm::Triple Triple("armv7r-unknown-eabi");
952 EXPECT_EQ("cortex-r4", Triple.getARMCPUForArch());
953 }
954 {
955 llvm::Triple Triple("armv7r-unknown-eabi");
956 EXPECT_EQ("cortex-r4", Triple.getARMCPUForArch());
957 }
958 {
959 llvm::Triple Triple("armv8a-unknown-eabi");
960 EXPECT_EQ("cortex-a53", Triple.getARMCPUForArch());
961 }
962 {
963 llvm::Triple Triple("armv8.1a-unknown-eabi");
964 EXPECT_EQ("generic", Triple.getARMCPUForArch());
965 }
966 // Non-synonym names, using -march style, not default arch.
967 {
968 llvm::Triple Triple("arm");
969 EXPECT_EQ("cortex-a8", Triple.getARMCPUForArch("armv7-a"));
970 }
971 {
972 llvm::Triple Triple("arm");
973 EXPECT_EQ("cortex-m3", Triple.getARMCPUForArch("armv7-m"));
974 }
975 {
976 llvm::Triple Triple("arm");
977 EXPECT_EQ("cortex-a53", Triple.getARMCPUForArch("armv8"));
978 }
979 {
980 llvm::Triple Triple("arm");
981 EXPECT_EQ("cortex-a53", Triple.getARMCPUForArch("armv8-a"));
982 }
983 // Platform specific defaults.
984 {
985 llvm::Triple Triple("arm--nacl");
986 EXPECT_EQ("cortex-a8", Triple.getARMCPUForArch());
987 }
988 {
989 llvm::Triple Triple("armv6-unknown-freebsd");
990 EXPECT_EQ("arm1176jzf-s", Triple.getARMCPUForArch());
991 }
992 {
993 llvm::Triple Triple("thumbv6-unknown-freebsd");
994 EXPECT_EQ("arm1176jzf-s", Triple.getARMCPUForArch());
995 }
996 {
997 llvm::Triple Triple("armebv6-unknown-freebsd");
998 EXPECT_EQ("arm1176jzf-s", Triple.getARMCPUForArch());
999 }
1000 {
1001 llvm::Triple Triple("arm--win32");
1002 EXPECT_EQ("cortex-a9", Triple.getARMCPUForArch());
1003 }
1004 // Some alternative architectures
1005 {
1006 llvm::Triple Triple("xscale-unknown-eabi");
1007 EXPECT_EQ("xscale", Triple.getARMCPUForArch());
1008 }
1009 {
1010 llvm::Triple Triple("iwmmxt-unknown-eabi");
1011 EXPECT_EQ("iwmmxt", Triple.getARMCPUForArch());
1012 }
1013 {
1014 llvm::Triple Triple("armv7s-apple-ios7");
1015 EXPECT_EQ("swift", Triple.getARMCPUForArch());
1016 }
1017 {
1018 llvm::Triple Triple("armv7k-apple-ios9");
1019 EXPECT_EQ("cortex-a7", Triple.getARMCPUForArch());
1020 }
1021 {
1022 llvm::Triple Triple("armv7k-apple-watchos3");
1023 EXPECT_EQ("cortex-a7", Triple.getARMCPUForArch());
1024 }
1025 {
1026 llvm::Triple Triple("armv7k-apple-tvos9");
1027 EXPECT_EQ("cortex-a7", Triple.getARMCPUForArch());
1028 }
1029 {
1030 llvm::Triple Triple("armv7em-apple-ios7");
1031 EXPECT_EQ("cortex-m4", Triple.getARMCPUForArch());
1032 }
1033 {
1034 llvm::Triple Triple("armv7l-linux-gnueabihf");
1035 EXPECT_EQ("cortex-a8", Triple.getARMCPUForArch());
1036 }
1037 {
1038 llvm::Triple Triple("armv6sm-apple-ios7");
1039 EXPECT_EQ("cortex-m0", Triple.getARMCPUForArch());
1040 }
1041 // armeb is permitted, but armebeb is not
1042 {
1043 llvm::Triple Triple("armeb-none-eabi");
1044 EXPECT_EQ("arm7tdmi", Triple.getARMCPUForArch());
1045 }
1046 {
1047 llvm::Triple Triple("armebeb-none-eabi");
1048 EXPECT_EQ("", Triple.getARMCPUForArch());
1049 }
1050 {
1051 llvm::Triple Triple("armebv6eb-none-eabi");
1052 EXPECT_EQ("", Triple.getARMCPUForArch());
1053 }
1054 // armebv6 and armv6eb are permitted, but armebv6eb is not
1055 {
1056 llvm::Triple Triple("armebv6-non-eabi");
1057 EXPECT_EQ("arm1136jf-s", Triple.getARMCPUForArch());
1058 }
1059 {
1060 llvm::Triple Triple("armv6eb-none-eabi");
1061 EXPECT_EQ("arm1136jf-s", Triple.getARMCPUForArch());
1062 }
1063 // xscaleeb is permitted, but armebxscale is not
1064 {
1065 llvm::Triple Triple("xscaleeb-none-eabi");
1066 EXPECT_EQ("xscale", Triple.getARMCPUForArch());
1067 }
1068 {
1069 llvm::Triple Triple("armebxscale-none-eabi");
1070 EXPECT_EQ("", Triple.getARMCPUForArch());
1071 }
1072 }
1073
TEST(TripleTest,NormalizeARM)1074 TEST(TripleTest, NormalizeARM) {
1075 EXPECT_EQ("armv6--netbsd-eabi", Triple::normalize("armv6-netbsd-eabi"));
1076 EXPECT_EQ("armv7--netbsd-eabi", Triple::normalize("armv7-netbsd-eabi"));
1077 EXPECT_EQ("armv6eb--netbsd-eabi", Triple::normalize("armv6eb-netbsd-eabi"));
1078 EXPECT_EQ("armv7eb--netbsd-eabi", Triple::normalize("armv7eb-netbsd-eabi"));
1079 EXPECT_EQ("armv6--netbsd-eabihf", Triple::normalize("armv6-netbsd-eabihf"));
1080 EXPECT_EQ("armv7--netbsd-eabihf", Triple::normalize("armv7-netbsd-eabihf"));
1081 EXPECT_EQ("armv6eb--netbsd-eabihf", Triple::normalize("armv6eb-netbsd-eabihf"));
1082 EXPECT_EQ("armv7eb--netbsd-eabihf", Triple::normalize("armv7eb-netbsd-eabihf"));
1083
1084 Triple T;
1085 T = Triple("armv6--netbsd-eabi");
1086 EXPECT_EQ(Triple::arm, T.getArch());
1087 T = Triple("armv6eb--netbsd-eabi");
1088 EXPECT_EQ(Triple::armeb, T.getArch());
1089 }
1090
TEST(TripleTest,ParseARMArch)1091 TEST(TripleTest, ParseARMArch) {
1092 // ARM
1093 {
1094 Triple T = Triple("arm");
1095 EXPECT_EQ(Triple::arm, T.getArch());
1096 }
1097 {
1098 Triple T = Triple("armv6t2");
1099 EXPECT_EQ(Triple::arm, T.getArch());
1100 }
1101 {
1102 Triple T = Triple("armv8");
1103 EXPECT_EQ(Triple::arm, T.getArch());
1104 }
1105 {
1106 Triple T = Triple("armeb");
1107 EXPECT_EQ(Triple::armeb, T.getArch());
1108 }
1109 {
1110 Triple T = Triple("armv5eb");
1111 EXPECT_EQ(Triple::armeb, T.getArch());
1112 }
1113 {
1114 Triple T = Triple("armebv7m");
1115 EXPECT_EQ(Triple::armeb, T.getArch());
1116 }
1117 {
1118 Triple T = Triple("armv7eb");
1119 EXPECT_EQ(Triple::armeb, T.getArch());
1120 }
1121 // THUMB
1122 {
1123 Triple T = Triple("thumb");
1124 EXPECT_EQ(Triple::thumb, T.getArch());
1125 }
1126 {
1127 Triple T = Triple("thumbv7a");
1128 EXPECT_EQ(Triple::thumb, T.getArch());
1129 }
1130 {
1131 Triple T = Triple("thumbeb");
1132 EXPECT_EQ(Triple::thumbeb, T.getArch());
1133 }
1134 {
1135 Triple T = Triple("thumbv4teb");
1136 EXPECT_EQ(Triple::thumbeb, T.getArch());
1137 }
1138 {
1139 Triple T = Triple("thumbebv7");
1140 EXPECT_EQ(Triple::thumbeb, T.getArch());
1141 }
1142 {
1143 Triple T = Triple("armv6m");
1144 EXPECT_EQ(Triple::thumb, T.getArch());
1145 }
1146 {
1147 Triple T = Triple("thumbv2");
1148 EXPECT_EQ(Triple::UnknownArch, T.getArch());
1149 }
1150 {
1151 Triple T = Triple("thumbebv6eb");
1152 EXPECT_EQ(Triple::UnknownArch, T.getArch());
1153 }
1154 // AARCH64
1155 {
1156 Triple T = Triple("arm64");
1157 EXPECT_EQ(Triple::aarch64, T.getArch());
1158 }
1159 {
1160 Triple T = Triple("aarch64");
1161 EXPECT_EQ(Triple::aarch64, T.getArch());
1162 }
1163 {
1164 Triple T = Triple("aarch64_be");
1165 EXPECT_EQ(Triple::aarch64_be, T.getArch());
1166 }
1167 {
1168 Triple T = Triple("aarch64be");
1169 EXPECT_EQ(Triple::UnknownArch, T.getArch());
1170 }
1171 {
1172 Triple T = Triple("arm64be");
1173 EXPECT_EQ(Triple::UnknownArch, T.getArch());
1174 }
1175 }
1176 } // end anonymous namespace
1177