@@ -154,9 +154,7 @@ const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) {
154154 case CODE16: return " code16" ;
155155 case EABI: return " eabi" ;
156156 case EABIHF: return " eabihf" ;
157- case MachO: return " macho" ;
158157 case Android: return " android" ;
159- case ELF: return " elf" ;
160158 }
161159
162160 llvm_unreachable (" Invalid EnvironmentType!" );
@@ -310,12 +308,36 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
310308 .StartsWith (" gnux32" , Triple::GNUX32)
311309 .StartsWith (" code16" , Triple::CODE16)
312310 .StartsWith (" gnu" , Triple::GNU)
313- .StartsWith (" macho" , Triple::MachO)
314311 .StartsWith (" android" , Triple::Android)
315- .StartsWith (" elf" , Triple::ELF)
316312 .Default (Triple::UnknownEnvironment);
317313}
318314
315+ static Triple::ObjectFormatType parseFormat (StringRef EnvironmentName) {
316+ return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
317+ .EndsWith (" coff" , Triple::COFF)
318+ .EndsWith (" elf" , Triple::ELF)
319+ .EndsWith (" macho" , Triple::MachO)
320+ .Default (Triple::UnknownObjectFormat);
321+ }
322+
323+ static const char *getObjectFormatTypeName (Triple::ObjectFormatType Kind) {
324+ switch (Kind) {
325+ case Triple::UnknownObjectFormat: return " " ;
326+ case Triple::COFF: return " coff" ;
327+ case Triple::ELF: return " elf" ;
328+ case Triple::MachO: return " macho" ;
329+ }
330+ llvm_unreachable (" unknown object format type" );
331+ }
332+
333+ static Triple::ObjectFormatType getDefaultFormat (const Triple &T) {
334+ if (T.isOSDarwin ())
335+ return Triple::MachO;
336+ else if (T.isOSWindows ())
337+ return Triple::COFF;
338+ return Triple::ELF;
339+ }
340+
319341// / \brief Construct a triple from the string representation provided.
320342// /
321343// / This stores the string representation and parses the various pieces into
@@ -325,7 +347,10 @@ Triple::Triple(const Twine &Str)
325347 Arch(parseArch(getArchName())),
326348 Vendor(parseVendor(getVendorName())),
327349 OS(parseOS(getOSName())),
328- Environment(parseEnvironment(getEnvironmentName())) {
350+ Environment(parseEnvironment(getEnvironmentName())),
351+ ObjectFormat(parseFormat(getEnvironmentName())) {
352+ if (ObjectFormat == Triple::UnknownObjectFormat)
353+ ObjectFormat = getDefaultFormat (*this );
329354}
330355
331356// / \brief Construct a triple from string representations of the architecture,
@@ -339,7 +364,8 @@ Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
339364 Arch(parseArch(ArchStr.str())),
340365 Vendor(parseVendor(VendorStr.str())),
341366 OS(parseOS(OSStr.str())),
342- Environment() {
367+ Environment(), ObjectFormat(Triple::UnknownObjectFormat) {
368+ ObjectFormat = getDefaultFormat (*this );
343369}
344370
345371// / \brief Construct a triple from string representations of the architecture,
@@ -354,7 +380,10 @@ Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
354380 Arch(parseArch(ArchStr.str())),
355381 Vendor(parseVendor(VendorStr.str())),
356382 OS(parseOS(OSStr.str())),
357- Environment(parseEnvironment(EnvironmentStr.str())) {
383+ Environment(parseEnvironment(EnvironmentStr.str())),
384+ ObjectFormat(parseFormat(EnvironmentStr.str())) {
385+ if (ObjectFormat == Triple::UnknownObjectFormat)
386+ ObjectFormat = getDefaultFormat (*this );
358387}
359388
360389std::string Triple::normalize (StringRef Str) {
@@ -379,6 +408,7 @@ std::string Triple::normalize(StringRef Str) {
379408 EnvironmentType Environment = UnknownEnvironment;
380409 if (Components.size () > 3 )
381410 Environment = parseEnvironment (Components[3 ]);
411+ ObjectFormatType ObjectFormat = UnknownObjectFormat;
382412
383413 // Note which components are already in their final position. These will not
384414 // be moved.
@@ -420,6 +450,10 @@ std::string Triple::normalize(StringRef Str) {
420450 case 3 :
421451 Environment = parseEnvironment (Comp);
422452 Valid = Environment != UnknownEnvironment;
453+ if (!Valid) {
454+ ObjectFormat = parseFormat (Comp);
455+ Valid = ObjectFormat != UnknownObjectFormat;
456+ }
423457 break ;
424458 }
425459 if (!Valid)
@@ -641,6 +675,10 @@ void Triple::setEnvironment(EnvironmentType Kind) {
641675 setEnvironmentName (getEnvironmentTypeName (Kind));
642676}
643677
678+ void Triple::setObjectFormat (ObjectFormatType Kind) {
679+ setEnvironmentName (getObjectFormatTypeName (Kind));
680+ }
681+
644682void Triple::setArchName (StringRef Str) {
645683 // Work around a miscompilation bug for Twines in gcc 4.0.3.
646684 SmallString<64 > Triple;
0 commit comments