Cyndy Ishida | 81669d5 | 2019-09-20 14:32:34 +0000 | [diff] [blame^] | 1 | //===- llvm/TextAPI/MachO/Platform.cpp - Platform ---------------*- 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 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Implementations of Platform Helper functions. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "llvm/ADT/ArrayRef.h" |
| 14 | #include "llvm/ADT/Triple.h" |
| 15 | #include "llvm/TextAPI/MachO/Platform.h" |
| 16 | |
| 17 | namespace llvm { |
| 18 | namespace MachO { |
| 19 | |
| 20 | PlatformKind mapToPlatformKind(const Triple &Target) { |
| 21 | switch (Target.getOS()) { |
| 22 | default: |
| 23 | return PlatformKind::unknown; |
| 24 | case Triple::MacOSX: |
| 25 | return PlatformKind::macOS; |
| 26 | case Triple::IOS: |
| 27 | return PlatformKind::iOS; |
| 28 | case Triple::TvOS: |
| 29 | return PlatformKind::tvOS; |
| 30 | case Triple::WatchOS: |
| 31 | return PlatformKind::watchOS; |
| 32 | // TODO: add bridgeOS once in llvm::Triple |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | PlatformSet mapToPlatformSet(ArrayRef<Triple> Targets) { |
| 37 | PlatformSet Result; |
| 38 | for (const auto &Target : Targets) |
| 39 | Result.insert(mapToPlatformKind(Target)); |
| 40 | return Result; |
| 41 | } |
| 42 | |
| 43 | StringRef getPlatformName(PlatformKind Platform) { |
| 44 | switch (Platform) { |
| 45 | case PlatformKind::unknown: |
| 46 | return "unknown"; |
| 47 | case PlatformKind::macOS: |
| 48 | return "macOS"; |
| 49 | case PlatformKind::iOS: |
| 50 | return "iOS"; |
| 51 | case PlatformKind::tvOS: |
| 52 | return "tvOS"; |
| 53 | case PlatformKind::watchOS: |
| 54 | return "watchOS"; |
| 55 | case PlatformKind::bridgeOS: |
| 56 | return "bridgeOS"; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | } // end namespace MachO. |
| 61 | } // end namespace llvm. |