llvm::SmallString<32> getTargetDependentLibraryOption(const llvm::Triple &T, StringRef library) { llvm::SmallString<32> buffer; if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) { bool quote = library.find(' ') != StringRef::npos; buffer += "/DEFAULTLIB:"; if (quote) buffer += '"'; buffer += library; if (!library.endswith_lower(".lib")) buffer += ".lib"; if (quote) buffer += '"'; } else if (T.isPS4()) { bool quote = library.find(' ') != StringRef::npos; buffer += "\01"; if (quote) buffer += '"'; buffer += library; if (quote) buffer += '"'; } else { buffer += "-l"; buffer += library; } return buffer; }
std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) { clearAllPlatformConditionValues(); if (triple.getOS() == llvm::Triple::Darwin && triple.getVendor() == llvm::Triple::Apple) { // Rewrite darwinX.Y triples to macosx10.X'.Y ones. // It affects code generation on our platform. llvm::SmallString<16> osxBuf; llvm::raw_svector_ostream osx(osxBuf); osx << llvm::Triple::getOSTypeName(llvm::Triple::MacOSX); unsigned major, minor, micro; triple.getMacOSXVersion(major, minor, micro); osx << major << "." << minor; if (micro != 0) osx << "." << micro; triple.setOSName(osx.str()); } Target = std::move(triple); bool UnsupportedOS = false; // Set the "os" platform condition. if (Target.isMacOSX()) addPlatformConditionValue(PlatformConditionKind::OS, "OSX"); else if (triple.isTvOS()) addPlatformConditionValue(PlatformConditionKind::OS, "tvOS"); else if (triple.isWatchOS()) addPlatformConditionValue(PlatformConditionKind::OS, "watchOS"); else if (triple.isiOS()) addPlatformConditionValue(PlatformConditionKind::OS, "iOS"); else if (triple.isAndroid()) addPlatformConditionValue(PlatformConditionKind::OS, "Android"); else if (triple.isOSLinux()) addPlatformConditionValue(PlatformConditionKind::OS, "Linux"); else if (triple.isOSFreeBSD()) addPlatformConditionValue(PlatformConditionKind::OS, "FreeBSD"); else if (triple.isOSWindows()) addPlatformConditionValue(PlatformConditionKind::OS, "Windows"); else if (triple.isWindowsCygwinEnvironment()) addPlatformConditionValue(PlatformConditionKind::OS, "Cygwin"); else if (triple.isPS4()) addPlatformConditionValue(PlatformConditionKind::OS, "PS4"); else UnsupportedOS = true; bool UnsupportedArch = false; // Set the "arch" platform condition. switch (Target.getArch()) { case llvm::Triple::ArchType::arm: case llvm::Triple::ArchType::thumb: addPlatformConditionValue(PlatformConditionKind::Arch, "arm"); break; case llvm::Triple::ArchType::aarch64: addPlatformConditionValue(PlatformConditionKind::Arch, "arm64"); break; case llvm::Triple::ArchType::ppc64: addPlatformConditionValue(PlatformConditionKind::Arch, "powerpc64"); break; case llvm::Triple::ArchType::ppc64le: addPlatformConditionValue(PlatformConditionKind::Arch, "powerpc64le"); break; case llvm::Triple::ArchType::x86: addPlatformConditionValue(PlatformConditionKind::Arch, "i386"); break; case llvm::Triple::ArchType::x86_64: addPlatformConditionValue(PlatformConditionKind::Arch, "x86_64"); break; case llvm::Triple::ArchType::systemz: addPlatformConditionValue(PlatformConditionKind::Arch, "s390x"); break; default: UnsupportedArch = true; } if (UnsupportedOS || UnsupportedArch) return { UnsupportedOS, UnsupportedArch }; // Set the "_endian" platform condition. switch (Target.getArch()) { case llvm::Triple::ArchType::arm: case llvm::Triple::ArchType::thumb: addPlatformConditionValue(PlatformConditionKind::Endianness, "little"); break; case llvm::Triple::ArchType::aarch64: addPlatformConditionValue(PlatformConditionKind::Endianness, "little"); break; case llvm::Triple::ArchType::ppc64: addPlatformConditionValue(PlatformConditionKind::Endianness, "big"); break; case llvm::Triple::ArchType::ppc64le: addPlatformConditionValue(PlatformConditionKind::Endianness, "little"); break; case llvm::Triple::ArchType::x86: addPlatformConditionValue(PlatformConditionKind::Endianness, "little"); break; case llvm::Triple::ArchType::x86_64: addPlatformConditionValue(PlatformConditionKind::Endianness, "little"); break; case llvm::Triple::ArchType::systemz: addPlatformConditionValue(PlatformConditionKind::Endianness, "big"); break; default: llvm_unreachable("undefined architecture endianness"); } // Set the "runtime" platform condition. if (EnableObjCInterop) addPlatformConditionValue(PlatformConditionKind::Runtime, "_ObjC"); else addPlatformConditionValue(PlatformConditionKind::Runtime, "_Native"); // If you add anything to this list, change the default size of // PlatformConditionValues to not require an extra allocation // in the common case. return { false, false }; }