LLVM  10.0.0svn
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 // 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",
39  IO.enumCase(Constraint, "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;
51  OS << "macosx";
52  break;
53  case PlatformKind::iOS:
54  OS << "ios";
55  break;
57  OS << "watchos";
58  break;
59  case PlatformKind::tvOS:
60  OS << "tvos";
61  break;
63  OS << "bridgeos";
64  break;
65  }
66 }
67 StringRef ScalarTraits<PlatformKind>::input(StringRef Scalar, void *,
68  PlatformKind &Value) {
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)
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) {
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.
PlatformKind
Defines the list of MachO platforms.
Definition: InterfaceFile.h:35
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Retain/Release or Garbage Collection.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:67
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:181
bool parse32(StringRef Str)
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
std::pair< llvm::MachO::Architecture, std::string > UUID
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
ObjCConstraintType
Defines a list of Objective-C constraints.
Definition: InterfaceFile.h:45
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:478
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
Definition: Architecture.h:23
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:696
Architecture getArchitectureFromName(StringRef Name)
Convert a name to an architecture slice.
LLVM Value Representation.
Definition: Value.h:73
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48