[InstCombine] Signed saturation patterns
[llvm-complete.git] / lib / TextAPI / MachO / Target.cpp
blobaee8ef421425ff602ac201447801b38ffc6d536d
1 //===- tapi/Core/Target.cpp - Target ----------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/SmallString.h"
10 #include "llvm/ADT/SmallVector.h"
11 #include "llvm/ADT/StringExtras.h"
12 #include "llvm/ADT/StringSwitch.h"
13 #include "llvm/Support/Format.h"
14 #include "llvm/Support/raw_ostream.h"
15 #include "llvm/TextAPI/MachO/Target.h"
17 namespace llvm {
18 namespace MachO {
20 Expected<Target> Target::create(StringRef TargetValue) {
21 auto Result = TargetValue.split('-');
22 auto ArchitectureStr = Result.first;
23 auto Architecture = getArchitectureFromName(ArchitectureStr);
24 auto PlatformStr = Result.second;
25 PlatformKind Platform;
26 Platform = StringSwitch<PlatformKind>(PlatformStr)
27 .Case("macos", PlatformKind::macOS)
28 .Case("ios", PlatformKind::iOS)
29 .Case("tvos", PlatformKind::tvOS)
30 .Case("watchos", PlatformKind::watchOS)
31 .Case("bridgeos", PlatformKind::bridgeOS)
32 .Case("maccatalyst", PlatformKind::macCatalyst)
33 .Case("ios-simulator", PlatformKind::iOSSimulator)
34 .Case("tvos-simulator", PlatformKind::tvOSSimulator)
35 .Case("watchos-simulator", PlatformKind::watchOSSimulator)
36 .Default(PlatformKind::unknown);
38 if (Platform == PlatformKind::unknown) {
39 if (PlatformStr.startswith("<") && PlatformStr.endswith(">")) {
40 PlatformStr = PlatformStr.drop_front().drop_back();
41 unsigned long long RawValue;
42 if (!PlatformStr.getAsInteger(10, RawValue))
43 Platform = (PlatformKind)RawValue;
47 return Target{Architecture, Platform};
50 Target::operator std::string() const {
51 return (getArchitectureName(Arch) + " (" + getPlatformName(Platform) + ")")
52 .str();
55 raw_ostream &operator<<(raw_ostream &OS, const Target &Target) {
56 OS << std::string(Target);
57 return OS;
60 PlatformSet mapToPlatformSet(ArrayRef<Target> Targets) {
61 PlatformSet Result;
62 for (const auto &Target : Targets)
63 Result.insert(Target.Platform);
64 return Result;
67 ArchitectureSet mapToArchitectureSet(ArrayRef<Target> Targets) {
68 ArchitectureSet Result;
69 for (const auto &Target : Targets)
70 Result.set(Target.Arch);
71 return Result;
74 } // end namespace MachO.
75 } // end namespace llvm.