Path: blob/main/contrib/llvm-project/llvm/lib/TextAPI/Target.cpp
35262 views
//===- Target.cpp -----------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/TextAPI/Target.h"9#include "llvm/ADT/StringSwitch.h"10#include "llvm/ADT/Twine.h"11#include "llvm/Support/raw_ostream.h"1213namespace llvm {14namespace MachO {1516Expected<Target> Target::create(StringRef TargetValue) {17auto Result = TargetValue.split('-');18auto ArchitectureStr = Result.first;19auto Architecture = getArchitectureFromName(ArchitectureStr);20auto PlatformStr = Result.second;21PlatformType Platform;22Platform = StringSwitch<PlatformType>(PlatformStr)23#define PLATFORM(platform, id, name, build_name, target, tapi_target, \24marketing) \25.Case(#tapi_target, PLATFORM_##platform)26#include "llvm/BinaryFormat/MachO.def"27.Default(PLATFORM_UNKNOWN);2829if (Platform == PLATFORM_UNKNOWN) {30if (PlatformStr.starts_with("<") && PlatformStr.ends_with(">")) {31PlatformStr = PlatformStr.drop_front().drop_back();32unsigned long long RawValue;33if (!PlatformStr.getAsInteger(10, RawValue))34Platform = (PlatformType)RawValue;35}36}3738return Target{Architecture, Platform};39}4041Target::operator std::string() const {42auto Version = MinDeployment.empty() ? "" : MinDeployment.getAsString();4344return (getArchitectureName(Arch) + " (" + getPlatformName(Platform) +45Version + ")")46.str();47}4849raw_ostream &operator<<(raw_ostream &OS, const Target &Target) {50OS << std::string(Target);51return OS;52}5354PlatformVersionSet mapToPlatformVersionSet(ArrayRef<Target> Targets) {55PlatformVersionSet Result;56for (const auto &Target : Targets)57Result.insert({Target.Platform, Target.MinDeployment});58return Result;59}6061PlatformSet mapToPlatformSet(ArrayRef<Target> Targets) {62PlatformSet Result;63for (const auto &Target : Targets)64Result.insert(Target.Platform);65return Result;66}6768ArchitectureSet mapToArchitectureSet(ArrayRef<Target> Targets) {69ArchitectureSet Result;70for (const auto &Target : Targets)71Result.set(Target.Arch);72return Result;73}7475std::string getTargetTripleName(const Target &Targ) {76auto Version =77Targ.MinDeployment.empty() ? "" : Targ.MinDeployment.getAsString();7879return (getArchitectureName(Targ.Arch) + "-apple-" +80getOSAndEnvironmentName(Targ.Platform, Version))81.str();82}8384} // end namespace MachO.85} // end namespace llvm.868788