]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/lib/TextAPI/MachO/TextStubCommon.cpp
MFC r355940:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / lib / TextAPI / MachO / TextStubCommon.cpp
1 //===- TextStubCommon.cpp -------------------------------------------------===//
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 // Implememts common Text Stub YAML mappings.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "TextStubCommon.h"
14 #include "TextAPIContext.h"
15
16 using namespace llvm::MachO;
17
18 namespace llvm {
19 namespace yaml {
20
21 void ScalarTraits<FlowStringRef>::output(const FlowStringRef &Value, void *Ctx,
22                                          raw_ostream &OS) {
23   ScalarTraits<StringRef>::output(Value, Ctx, OS);
24 }
25 StringRef ScalarTraits<FlowStringRef>::input(StringRef Value, void *Ctx,
26                                              FlowStringRef &Out) {
27   return ScalarTraits<StringRef>::input(Value, Ctx, Out.value);
28 }
29 QuotingType ScalarTraits<FlowStringRef>::mustQuote(StringRef Name) {
30   return ScalarTraits<StringRef>::mustQuote(Name);
31 }
32
33 void ScalarEnumerationTraits<ObjCConstraintType>::enumeration(
34     IO &IO, ObjCConstraintType &Constraint) {
35   IO.enumCase(Constraint, "none", ObjCConstraintType::None);
36   IO.enumCase(Constraint, "retain_release", ObjCConstraintType::Retain_Release);
37   IO.enumCase(Constraint, "retain_release_for_simulator",
38               ObjCConstraintType::Retain_Release_For_Simulator);
39   IO.enumCase(Constraint, "retain_release_or_gc",
40               ObjCConstraintType::Retain_Release_Or_GC);
41   IO.enumCase(Constraint, "gc", ObjCConstraintType::GC);
42 }
43
44 void ScalarTraits<PlatformKind>::output(const PlatformKind &Value, void *,
45                                         raw_ostream &OS) {
46   switch (Value) {
47   default:
48     llvm_unreachable("unexpected platform");
49     break;
50   case PlatformKind::macOS:
51     OS << "macosx";
52     break;
53   case PlatformKind::iOS:
54     OS << "ios";
55     break;
56   case PlatformKind::watchOS:
57     OS << "watchos";
58     break;
59   case PlatformKind::tvOS:
60     OS << "tvos";
61     break;
62   case PlatformKind::bridgeOS:
63     OS << "bridgeos";
64     break;
65   }
66 }
67 StringRef ScalarTraits<PlatformKind>::input(StringRef Scalar, void *,
68                                             PlatformKind &Value) {
69   Value = StringSwitch<PlatformKind>(Scalar)
70               .Case("macosx", PlatformKind::macOS)
71               .Case("ios", PlatformKind::iOS)
72               .Case("watchos", PlatformKind::watchOS)
73               .Case("tvos", PlatformKind::tvOS)
74               .Case("bridgeos", PlatformKind::bridgeOS)
75               .Default(PlatformKind::unknown);
76
77   if (Value == PlatformKind::unknown)
78     return "unknown platform";
79   return {};
80 }
81 QuotingType ScalarTraits<PlatformKind>::mustQuote(StringRef) {
82   return QuotingType::None;
83 }
84
85 void ScalarBitSetTraits<ArchitectureSet>::bitset(IO &IO,
86                                                  ArchitectureSet &Archs) {
87 #define ARCHINFO(arch, type, subtype)                                          \
88   IO.bitSetCase(Archs, #arch, 1U << static_cast<int>(AK_##arch));
89 #include "llvm/TextAPI/MachO/Architecture.def"
90 #undef ARCHINFO
91 }
92
93 void ScalarTraits<Architecture>::output(const Architecture &Value, void *,
94                                         raw_ostream &OS) {
95   OS << Value;
96 }
97 StringRef ScalarTraits<Architecture>::input(StringRef Scalar, void *,
98                                             Architecture &Value) {
99   Value = getArchitectureFromName(Scalar);
100   return {};
101 }
102 QuotingType ScalarTraits<Architecture>::mustQuote(StringRef) {
103   return QuotingType::None;
104 }
105
106 void ScalarTraits<PackedVersion>::output(const PackedVersion &Value, void *,
107                                          raw_ostream &OS) {
108   OS << Value;
109 }
110 StringRef ScalarTraits<PackedVersion>::input(StringRef Scalar, void *,
111                                              PackedVersion &Value) {
112   if (!Value.parse32(Scalar))
113     return "invalid packed version string.";
114   return {};
115 }
116 QuotingType ScalarTraits<PackedVersion>::mustQuote(StringRef) {
117   return QuotingType::None;
118 }
119
120 void ScalarTraits<SwiftVersion>::output(const SwiftVersion &Value, void *,
121                                         raw_ostream &OS) {
122   switch (Value) {
123   case 1:
124     OS << "1.0";
125     break;
126   case 2:
127     OS << "1.1";
128     break;
129   case 3:
130     OS << "2.0";
131     break;
132   case 4:
133     OS << "3.0";
134     break;
135   default:
136     OS << (unsigned)Value;
137     break;
138   }
139 }
140 StringRef ScalarTraits<SwiftVersion>::input(StringRef Scalar, void *,
141                                             SwiftVersion &Value) {
142   Value = StringSwitch<SwiftVersion>(Scalar)
143               .Case("1.0", 1)
144               .Case("1.1", 2)
145               .Case("2.0", 3)
146               .Case("3.0", 4)
147               .Default(0);
148   if (Value != SwiftVersion(0))
149     return {};
150
151   if (Scalar.getAsInteger(10, Value))
152     return "invalid Swift ABI version.";
153
154   return StringRef();
155 }
156 QuotingType ScalarTraits<SwiftVersion>::mustQuote(StringRef) {
157   return QuotingType::None;
158 }
159
160 void ScalarTraits<UUID>::output(const UUID &Value, void *, raw_ostream &OS) {
161   OS << Value.first << ": " << Value.second;
162 }
163 StringRef ScalarTraits<UUID>::input(StringRef Scalar, void *, UUID &Value) {
164   auto Split = Scalar.split(':');
165   auto Arch = Split.first.trim();
166   auto UUID = Split.second.trim();
167   if (UUID.empty())
168     return "invalid uuid string pair";
169   Value.first = getArchitectureFromName(Arch);
170   Value.second = UUID;
171   return {};
172 }
173 QuotingType ScalarTraits<UUID>::mustQuote(StringRef) {
174   return QuotingType::Single;
175 }
176
177 } // end namespace yaml.
178 } // end namespace llvm.