LLVM 22.0.0git
TextStubCommon.cpp
Go to the documentation of this file.
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// Implements common Text Stub YAML mappings.
10//
11//===----------------------------------------------------------------------===//
12
13#include "TextStubCommon.h"
14#include "TextAPIContext.h"
16
17using namespace llvm::MachO;
18
19namespace llvm {
20namespace yaml {
21
22void ScalarTraits<FlowStringRef>::output(const FlowStringRef &Value, void *Ctx,
23 raw_ostream &OS) {
25}
27 FlowStringRef &Out) {
28 return ScalarTraits<StringRef>::input(Value, Ctx, Out.value);
29}
33
35 IO &IO, ObjCConstraintType &Constraint) {
36 IO.enumCase(Constraint, "none", ObjCConstraintType::None);
37 IO.enumCase(Constraint, "retain_release", ObjCConstraintType::Retain_Release);
38 IO.enumCase(Constraint, "retain_release_for_simulator",
40 IO.enumCase(Constraint, "retain_release_or_gc",
42 IO.enumCase(Constraint, "gc", ObjCConstraintType::GC);
43}
44
45void ScalarTraits<PlatformSet>::output(const PlatformSet &Values, void *IO,
46 raw_ostream &OS) {
47
48 const auto *Ctx = reinterpret_cast<TextAPIContext *>(IO);
49 assert((!Ctx || Ctx->FileKind != FileType::Invalid) &&
50 "File type is not set in context");
51
52 if (Ctx && Ctx->FileKind == TBD_V3 && Values.count(PLATFORM_MACOS) &&
53 Values.count(PLATFORM_MACCATALYST)) {
54 OS << "zippered";
55 return;
56 }
57
58 assert(Values.size() == 1U);
59 switch (*Values.begin()) {
60 default:
61 llvm_unreachable("unexpected platform");
62 break;
63 case PLATFORM_MACOS:
64 OS << "macosx";
65 break;
66 case PLATFORM_IOSSIMULATOR:
67 [[fallthrough]];
68 case PLATFORM_IOS:
69 OS << "ios";
70 break;
71 case PLATFORM_WATCHOSSIMULATOR:
72 [[fallthrough]];
73 case PLATFORM_WATCHOS:
74 OS << "watchos";
75 break;
76 case PLATFORM_TVOSSIMULATOR:
77 [[fallthrough]];
78 case PLATFORM_TVOS:
79 OS << "tvos";
80 break;
81 case PLATFORM_BRIDGEOS:
82 OS << "bridgeos";
83 break;
84 case PLATFORM_MACCATALYST:
85 OS << "maccatalyst";
86 break;
87 case PLATFORM_DRIVERKIT:
88 OS << "driverkit";
89 break;
90 }
91}
92
93StringRef ScalarTraits<PlatformSet>::input(StringRef Scalar, void *IO,
94 PlatformSet &Values) {
95 const auto *Ctx = reinterpret_cast<TextAPIContext *>(IO);
96 assert((!Ctx || Ctx->FileKind != FileType::Invalid) &&
97 "File type is not set in context");
98
99 if (Scalar == "zippered") {
100 if (Ctx && Ctx->FileKind == FileType::TBD_V3) {
101 Values.insert(PLATFORM_MACOS);
102 Values.insert(PLATFORM_MACCATALYST);
103 return {};
104 }
105 return "invalid platform";
106 }
107
108 auto Platform = StringSwitch<PlatformType>(Scalar)
109 .Case("macosx", PLATFORM_MACOS)
110 .Case("ios", PLATFORM_IOS)
111 .Case("watchos", PLATFORM_WATCHOS)
112 .Case("tvos", PLATFORM_TVOS)
113 .Case("bridgeos", PLATFORM_BRIDGEOS)
114 .Case("iosmac", PLATFORM_MACCATALYST)
115 .Case("maccatalyst", PLATFORM_MACCATALYST)
116 .Case("driverkit", PLATFORM_DRIVERKIT)
117 .Default(PLATFORM_UNKNOWN);
118
119 if (Platform == PLATFORM_MACCATALYST)
120 if (Ctx && Ctx->FileKind != FileType::TBD_V3)
121 return "invalid platform";
122
123 if (Platform == PLATFORM_UNKNOWN)
124 return "unknown platform";
125
126 Values.insert(Platform);
127 return {};
128}
129
131 return QuotingType::None;
132}
133
135 ArchitectureSet &Archs) {
136#define ARCHINFO(arch, name, type, subtype, numbits) \
137 IO.bitSetCase(Archs, #arch, 1U << static_cast<int>(AK_##arch));
138#include "llvm/TextAPI/Architecture.def"
139#undef ARCHINFO
140}
141
143 raw_ostream &OS) {
144 OS << Value;
145}
146StringRef ScalarTraits<Architecture>::input(StringRef Scalar, void *,
149 return {};
150}
152 return QuotingType::None;
153}
154
155void ScalarTraits<PackedVersion>::output(const PackedVersion &Value, void *,
156 raw_ostream &OS) {
157 OS << Value;
158}
159StringRef ScalarTraits<PackedVersion>::input(StringRef Scalar, void *,
160 PackedVersion &Value) {
161 if (!Value.parse32(Scalar))
162 return "invalid packed version string.";
163 return {};
164}
166 return QuotingType::None;
167}
168
169void ScalarTraits<SwiftVersion>::output(const SwiftVersion &Value, void *,
170 raw_ostream &OS) {
171 switch (Value) {
172 case 1:
173 OS << "1.0";
174 break;
175 case 2:
176 OS << "1.1";
177 break;
178 case 3:
179 OS << "2.0";
180 break;
181 case 4:
182 OS << "3.0";
183 break;
184 default:
185 OS << (unsigned)Value;
186 break;
187 }
188}
190 SwiftVersion &Value) {
191 const auto *Ctx = reinterpret_cast<TextAPIContext *>(IO);
192 assert((!Ctx || Ctx->FileKind != FileType::Invalid) &&
193 "File type is not set in context");
194
195 if (Ctx->FileKind == FileType::TBD_V4) {
196 if (Scalar.getAsInteger(10, Value))
197 return "invalid Swift ABI version.";
198 return {};
199 } else {
201 .Case("1.0", 1)
202 .Case("1.1", 2)
203 .Case("2.0", 3)
204 .Case("3.0", 4)
205 .Default(0);
206 }
207
208 if (Value != SwiftVersion(0))
209 return {};
210
211 if (Scalar.getAsInteger(10, Value))
212 return "invalid Swift ABI version.";
213
214 return StringRef();
215}
219
221
223 Value = {};
224 return {};
225}
226
230
231} // end namespace yaml.
232} // end namespace llvm.
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
std::pair< llvm::MachO::Target, std::string > UUID
const_iterator begin() const
Definition SmallSet.h:213
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Definition SmallSet.h:175
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition SmallSet.h:181
size_type size() const
Definition SmallSet.h:170
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
void enumCase(T &Val, const char *Str, const T ConstVal)
Definition YAMLTraits.h:745
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI Architecture getArchitectureFromName(StringRef Name)
Convert a name to an architecture slice.
@ Invalid
Invalid file type.
Definition FileTypes.h:17
@ TBD_V3
Text-based stub file (.tbd) version 3.0.
Definition FileTypes.h:35
@ TBD_V4
Text-based stub file (.tbd) version 4.0.
Definition FileTypes.h:38
SmallSet< PlatformType, 3 > PlatformSet
Definition Platform.h:23
ObjCConstraintType
Defines a list of Objective-C constraints.
@ Retain_Release_For_Simulator
Retain/Release for Simulator.
@ Retain_Release_Or_GC
Retain/Release or Garbage Collection.
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
QuotingType
Describe which type of quotes should be used when quoting is necessary.
Definition YAMLTraits.h:131
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
This class should be specialized by any integer type that is a union of bit values and the YAML repre...
Definition YAMLTraits.h:123
This class should be specialized by any integral type that converts to/from a YAML scalar where there...
Definition YAMLTraits.h:107
This class should be specialized by type that requires custom conversion to/from a yaml scalar.
Definition YAMLTraits.h:149