llvm.org GIT mirror llvm / 651aa68
Improve Triple to recognize the OS in i386-mingw32. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79359 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 11 years ago
3 changed file(s) with 47 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
2828 /// behavior for particular targets. This class isolates the mapping
2929 /// from the components of the target triple to well known IDs.
3030 ///
31 /// See autoconf/config.guess for a glimpse into what they look like
32 /// in practice.
31 /// At its core the Triple class is designed to be a wrapper for a triple
32 /// string; it does not normally change or normalize the triple string, instead
33 /// it provides additional APIs to parse normalized parts out of the triple.
34 ///
35 /// One curiosity this implies is that for some odd triples the results of,
36 /// e.g., getOSName() can be very different from the result of getOS(). For
37 /// example, for 'i386-mingw32', getOS() will return MinGW32, but since
38 /// getOSName() is purely based on the string structure that will return the
39 /// empty string.
40 ///
41 /// Clients should generally avoid using getOSName() and related APIs unless
42 /// they are familiar with the triple format (this is particularly true when
43 /// rewriting a triple).
44 ///
45 /// See autoconf/config.guess for a glimpse into what they look like in
46 /// practice.
3347 class Triple {
3448 public:
3549 enum ArchType {
116116 assert(!isInitialized() && "Invalid parse call.");
117117
118118 StringRef ArchName = getArchName();
119 StringRef VendorName = getVendorName();
120 StringRef OSName = getOSName();
121
119122 if (ArchName.size() == 4 && ArchName[0] == 'i' &&
120123 ArchName[2] == '8' && ArchName[3] == '6' &&
121124 ArchName[1] - '3' < 6) // i[3-9]86
155158 else
156159 Arch = UnknownArch;
157160
158 StringRef VendorName = getVendorName();
161
162 // Handle some exceptional cases where the OS / environment components are
163 // stuck into the vendor field.
164 if (StringRef(getTriple()).count('-') == 1) {
165 StringRef VendorName = getVendorName();
166
167 if (VendorName.startswith("mingw32")) { // 'i386-mingw32', etc.
168 Vendor = PC;
169 OS = MinGW32;
170 return;
171 }
172
173 // arm-elf is another example, but we don't currently parse anything about
174 // the environment.
175 }
176
159177 if (VendorName == "apple")
160178 Vendor = Apple;
161179 else if (VendorName == "pc")
163181 else
164182 Vendor = UnknownVendor;
165183
166 StringRef OSName = getOSName();
167184 if (OSName.startswith("auroraux"))
168185 OS = AuroraUX;
169186 else if (OSName.startswith("cygwin"))
9191
9292 T = Triple("huh");
9393 EXPECT_EQ(Triple::UnknownArch, T.getArch());
94
95 // Two exceptional cases.
96
97 T = Triple("i386-mingw32");
98 EXPECT_EQ(Triple::x86, T.getArch());
99 EXPECT_EQ(Triple::PC, T.getVendor());
100 EXPECT_EQ(Triple::MinGW32, T.getOS());
101
102 T = Triple("arm-elf");
103 EXPECT_EQ(Triple::arm, T.getArch());
104 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
105 EXPECT_EQ(Triple::UnknownOS, T.getOS());
94106 }
95107
96108 TEST(TripleTest, MutateName) {