llvm.org GIT mirror llvm / ae200c6
Remove NoVendor and NoOS, added in commit 123990, from Triple. While it may be useful to understand "none", this is not the place for it. Tweak the fix to Normalize while there: the fix added in 123990 works correctly, but I like this way better. Finally, now that Triple understands some non-trivial environment values, teach the unittests about them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124720 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan Sands 9 years ago
3 changed file(s) with 56 addition(s) and 74 deletion(s). Raw diff Collapse all Expand all
7171 UnknownVendor,
7272
7373 Apple,
74 PC,
75 NoVendor
74 PC
7675 };
7776 enum OSType {
7877 UnknownOS,
9291 Solaris,
9392 Win32,
9493 Haiku,
95 Minix,
96 NoOS
94 Minix
9795 };
9896 enum EnvironmentType {
9997 UnknownEnvironment,
8383
8484 case Apple: return "apple";
8585 case PC: return "pc";
86 case NoVendor: return "none";
8786 }
8887
8988 return "";
109108 case Win32: return "win32";
110109 case Haiku: return "haiku";
111110 case Minix: return "minix";
112 case NoOS: return "none";
113111 }
114112
115113 return "";
298296 return Apple;
299297 else if (VendorName == "pc")
300298 return PC;
301 else if (VendorName == "none")
302 return NoVendor;
303299 else
304300 return UnknownVendor;
305301 }
337333 return Haiku;
338334 else if (OSName.startswith("minix"))
339335 return Minix;
340 else if (OSName.startswith("eabi"))
341 return NoOS;
342336 else
343337 return UnknownOS;
344338 }
362356 Arch = ParseArch(getArchName());
363357 Vendor = ParseVendor(getVendorName());
364358 OS = ParseOS(getOSName());
365 if (OS == NoOS) {
366 // Some targets don't have an OS (embedded systems)
367 Environment = ParseEnvironment(getOSName());
368 } else {
369 Environment = ParseEnvironment(getEnvironmentName());
370 }
359 Environment = ParseEnvironment(getEnvironmentName());
371360
372361 assert(isInitialized() && "Failed to initialize!");
373362 }
434423 break;
435424 case 2:
436425 OS = ParseOS(Comp);
437 // Some targets don't have an OS (embedded systems)
438 if (OS == NoOS) {
439 Environment = ParseEnvironment(Comp);
440 Valid = Environment != UnknownEnvironment;
441 } else {
442 Valid = OS != UnknownOS;
443 }
426 Valid = OS != UnknownOS;
444427 break;
445428 case 3:
446429 Environment = ParseEnvironment(Comp);
476459 do {
477460 // Insert one empty component at Idx.
478461 StringRef CurrentComponent(""); // The empty component.
479 for (unsigned i = Idx; i < Components.size(); ++i) {
480 // Skip over any fixed components.
481 while (i < array_lengthof(Found) && Found[i]) ++i;
482 // Fix problem when Components vector is not big enough
483 if (i >= Components.size())
484 Components.push_back(StringRef(""));
462 for (unsigned i = Idx; i < Components.size();) {
485463 // Place the component at the new position, getting the component
486464 // that was at this position - it will be moved right.
487465 std::swap(CurrentComponent, Components[i]);
488466 // If it was placed on top of an empty component then we are done.
489467 if (CurrentComponent.empty())
490468 break;
469 // Advance to the next component, skipping any fixed components.
470 while (++i < array_lengthof(Found) && Found[i]);
491471 }
492472 // The last component was pushed off the end - append it.
493473 if (!CurrentComponent.empty())
9292 EXPECT_EQ(Triple::UnknownOS, T.getOS());
9393 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
9494
95 T = Triple("arm-none-eabi");
95 T = Triple("arm-none-none-eabi");
9696 EXPECT_EQ(Triple::arm, T.getArch());
97 EXPECT_EQ(Triple::NoVendor, T.getVendor());
98 EXPECT_EQ(Triple::NoOS, T.getOS());
97 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
98 EXPECT_EQ(Triple::UnknownOS, T.getOS());
9999 EXPECT_EQ(Triple::EABI, T.getEnvironment());
100100
101101 T = Triple("huh");
153153 // Check that normalizing a permutated set of valid components returns a
154154 // triple with the unpermuted components.
155155 StringRef C[4];
156 C[3] = "environment";
157156 for (int Arch = 1+Triple::UnknownArch; Arch < Triple::InvalidArch; ++Arch) {
158157 C[0] = Triple::getArchTypeName(Triple::ArchType(Arch));
159158 for (int Vendor = 1+Triple::UnknownVendor; Vendor <= Triple::PC;
161160 C[1] = Triple::getVendorTypeName(Triple::VendorType(Vendor));
162161 for (int OS = 1+Triple::UnknownOS; OS <= Triple::Minix; ++OS) {
163162 C[2] = Triple::getOSTypeName(Triple::OSType(OS));
164
165 std::string E = Join(C[0], C[1], C[2]);
166 std::string F = Join(C[0], C[1], C[2], C[3]);
167 EXPECT_EQ(E, Triple::normalize(Join(C[0], C[1], C[2])));
168 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[1], C[2], C[3])));
169
170 // If a value has multiple interpretations, then the permutation
171 // test will inevitably fail. Currently this is only the case for
172 // "psp" which parses as both an architecture and an O/S.
173 if (OS == Triple::Psp)
174 continue;
175
176 EXPECT_EQ(E, Triple::normalize(Join(C[0], C[2], C[1])));
177 EXPECT_EQ(E, Triple::normalize(Join(C[1], C[2], C[0])));
178 EXPECT_EQ(E, Triple::normalize(Join(C[1], C[0], C[2])));
179 EXPECT_EQ(E, Triple::normalize(Join(C[2], C[0], C[1])));
180 EXPECT_EQ(E, Triple::normalize(Join(C[2], C[1], C[0])));
181
182 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[1], C[3], C[2])));
183 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[2], C[3], C[1])));
184 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[2], C[1], C[3])));
185 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[3], C[1], C[2])));
186 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[3], C[2], C[1])));
187 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[2], C[3], C[0])));
188 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[2], C[0], C[3])));
189 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[3], C[0], C[2])));
190 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[3], C[2], C[0])));
191 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[0], C[2], C[3])));
192 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[0], C[3], C[2])));
193 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[3], C[0], C[1])));
194 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[3], C[1], C[0])));
195 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[0], C[1], C[3])));
196 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[0], C[3], C[1])));
197 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[1], C[3], C[0])));
198 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[1], C[0], C[3])));
199 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[0], C[1], C[2])));
200 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[0], C[2], C[1])));
201 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[1], C[2], C[0])));
202 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[1], C[0], C[2])));
203 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[2], C[0], C[1])));
204 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[2], C[1], C[0])));
163 for (int Env = 1+Triple::UnknownEnvironment; Env <= Triple::MachO;
164 ++Env) {
165 C[3] = Triple::getEnvironmentTypeName(Triple::EnvironmentType(Env));
166
167 std::string E = Join(C[0], C[1], C[2]);
168 std::string F = Join(C[0], C[1], C[2], C[3]);
169 EXPECT_EQ(E, Triple::normalize(Join(C[0], C[1], C[2])));
170 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[1], C[2], C[3])));
171
172 // If a value has multiple interpretations, then the permutation
173 // test will inevitably fail. Currently this is only the case for
174 // "psp" which parses as both an architecture and an O/S.
175 if (OS == Triple::Psp)
176 continue;
177
178 EXPECT_EQ(E, Triple::normalize(Join(C[0], C[2], C[1])));
179 EXPECT_EQ(E, Triple::normalize(Join(C[1], C[2], C[0])));
180 EXPECT_EQ(E, Triple::normalize(Join(C[1], C[0], C[2])));
181 EXPECT_EQ(E, Triple::normalize(Join(C[2], C[0], C[1])));
182 EXPECT_EQ(E, Triple::normalize(Join(C[2], C[1], C[0])));
183
184 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[1], C[3], C[2])));
185 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[2], C[3], C[1])));
186 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[2], C[1], C[3])));
187 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[3], C[1], C[2])));
188 EXPECT_EQ(F, Triple::normalize(Join(C[0], C[3], C[2], C[1])));
189 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[2], C[3], C[0])));
190 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[2], C[0], C[3])));
191 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[3], C[0], C[2])));
192 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[3], C[2], C[0])));
193 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[0], C[2], C[3])));
194 EXPECT_EQ(F, Triple::normalize(Join(C[1], C[0], C[3], C[2])));
195 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[3], C[0], C[1])));
196 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[3], C[1], C[0])));
197 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[0], C[1], C[3])));
198 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[0], C[3], C[1])));
199 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[1], C[3], C[0])));
200 EXPECT_EQ(F, Triple::normalize(Join(C[2], C[1], C[0], C[3])));
201 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[0], C[1], C[2])));
202 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[0], C[2], C[1])));
203 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[1], C[2], C[0])));
204 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[1], C[0], C[2])));
205 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[2], C[0], C[1])));
206 EXPECT_EQ(F, Triple::normalize(Join(C[3], C[2], C[1], C[0])));
207 }
205208 }
206209 }
207210 }
216219 EXPECT_EQ("i486--linux-gnu", Triple::normalize("i486-linux-gnu")); // i486-pc-linux-gnu
217220 EXPECT_EQ("i386-redhat-linux", Triple::normalize("i386-redhat-linux")); // i386-redhat-linux-gnu
218221 EXPECT_EQ("i686--linux", Triple::normalize("i686-linux")); // i686-pc-linux-gnu
222 EXPECT_EQ("arm-none--eabi", Triple::normalize("arm-none-eabi")); // arm-none-eabi
219223 }
220224
221225 TEST(TripleTest, MutateName) {