diff options
author | Cyndy Ishida <cyndy_ishida@apple.com> | 2021-04-05 09:59:50 -0700 |
---|---|---|
committer | Cyndy Ishida <cyndy_ishida@apple.com> | 2021-04-05 10:24:42 -0700 |
commit | 0116d04d04f20e9ae62ba847075840c3cb298080 (patch) | |
tree | a34708fe7cf17f71131d45e1c25451b9f766f2d9 /llvm/lib/TextAPI/Target.cpp | |
parent | 5abc7250122701012414733fc3273c01a45ffd29 (diff) | |
download | llvm-0116d04d04f20e9ae62ba847075840c3cb298080.zip llvm-0116d04d04f20e9ae62ba847075840c3cb298080.tar.gz llvm-0116d04d04f20e9ae62ba847075840c3cb298080.tar.bz2 |
[TextAPI] move source code files out of subdirectory, NFC
TextAPI/ELF has moved out into InterfaceStubs, so theres no longer a
need to seperate out TextAPI between formats.
Reviewed By: ributzka, int3, #lld-macho
Differential Revision: https://reviews.llvm.org/D99811
Diffstat (limited to 'llvm/lib/TextAPI/Target.cpp')
-rw-r--r-- | llvm/lib/TextAPI/Target.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/llvm/lib/TextAPI/Target.cpp b/llvm/lib/TextAPI/Target.cpp new file mode 100644 index 0000000..4c33a58 --- /dev/null +++ b/llvm/lib/TextAPI/Target.cpp @@ -0,0 +1,76 @@ +//===- Target.cpp -----------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "llvm/TextAPI/Target.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/Support/Format.h" +#include "llvm/Support/raw_ostream.h" + +namespace llvm { +namespace MachO { + +Expected<Target> Target::create(StringRef TargetValue) { + auto Result = TargetValue.split('-'); + auto ArchitectureStr = Result.first; + auto Architecture = getArchitectureFromName(ArchitectureStr); + auto PlatformStr = Result.second; + PlatformKind Platform; + Platform = StringSwitch<PlatformKind>(PlatformStr) + .Case("macos", PlatformKind::macOS) + .Case("ios", PlatformKind::iOS) + .Case("tvos", PlatformKind::tvOS) + .Case("watchos", PlatformKind::watchOS) + .Case("bridgeos", PlatformKind::bridgeOS) + .Case("maccatalyst", PlatformKind::macCatalyst) + .Case("ios-simulator", PlatformKind::iOSSimulator) + .Case("tvos-simulator", PlatformKind::tvOSSimulator) + .Case("watchos-simulator", PlatformKind::watchOSSimulator) + .Case("driverkit", PlatformKind::driverKit) + .Default(PlatformKind::unknown); + + if (Platform == PlatformKind::unknown) { + if (PlatformStr.startswith("<") && PlatformStr.endswith(">")) { + PlatformStr = PlatformStr.drop_front().drop_back(); + unsigned long long RawValue; + if (!PlatformStr.getAsInteger(10, RawValue)) + Platform = (PlatformKind)RawValue; + } + } + + return Target{Architecture, Platform}; +} + +Target::operator std::string() const { + return (getArchitectureName(Arch) + " (" + getPlatformName(Platform) + ")") + .str(); +} + +raw_ostream &operator<<(raw_ostream &OS, const Target &Target) { + OS << std::string(Target); + return OS; +} + +PlatformSet mapToPlatformSet(ArrayRef<Target> Targets) { + PlatformSet Result; + for (const auto &Target : Targets) + Result.insert(Target.Platform); + return Result; +} + +ArchitectureSet mapToArchitectureSet(ArrayRef<Target> Targets) { + ArchitectureSet Result; + for (const auto &Target : Targets) + Result.set(Target.Arch); + return Result; +} + +} // end namespace MachO. +} // end namespace llvm. |