[MIPS GlobalISel] Select float constants
[llvm-complete.git] / lib / TextAPI / MachO / TextStubCommon.cpp
blob805a9000512082d44e0f448c39e7b01d6cf09838
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.
11 //===----------------------------------------------------------------------===//
13 #include "TextStubCommon.h"
14 #include "TextAPIContext.h"
16 using namespace llvm::MachO;
18 namespace llvm {
19 namespace yaml {
21 void ScalarTraits<FlowStringRef>::output(const FlowStringRef &Value, void *Ctx,
22 raw_ostream &OS) {
23 ScalarTraits<StringRef>::output(Value, Ctx, OS);
25 StringRef ScalarTraits<FlowStringRef>::input(StringRef Value, void *Ctx,
26 FlowStringRef &Out) {
27 return ScalarTraits<StringRef>::input(Value, Ctx, Out.value);
29 QuotingType ScalarTraits<FlowStringRef>::mustQuote(StringRef Name) {
30 return ScalarTraits<StringRef>::mustQuote(Name);
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);
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;
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);
77 if (Value == PlatformKind::unknown)
78 return "unknown platform";
79 return {};
81 QuotingType ScalarTraits<PlatformKind>::mustQuote(StringRef) {
82 return QuotingType::None;
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>(Architecture::arch));
89 #include "llvm/TextAPI/MachO/Architecture.def"
90 #undef ARCHINFO
93 void ScalarTraits<Architecture>::output(const Architecture &Value, void *,
94 raw_ostream &OS) {
95 OS << Value;
97 StringRef ScalarTraits<Architecture>::input(StringRef Scalar, void *,
98 Architecture &Value) {
99 Value = getArchitectureFromName(Scalar);
100 return {};
102 QuotingType ScalarTraits<Architecture>::mustQuote(StringRef) {
103 return QuotingType::None;
106 void ScalarTraits<PackedVersion>::output(const PackedVersion &Value, void *,
107 raw_ostream &OS) {
108 OS << Value;
110 StringRef ScalarTraits<PackedVersion>::input(StringRef Scalar, void *,
111 PackedVersion &Value) {
112 if (!Value.parse32(Scalar))
113 return "invalid packed version string.";
114 return {};
116 QuotingType ScalarTraits<PackedVersion>::mustQuote(StringRef) {
117 return QuotingType::None;
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;
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 {};
151 if (Scalar.getAsInteger(10, Value))
152 return "invalid Swift ABI version.";
154 return StringRef();
156 QuotingType ScalarTraits<SwiftVersion>::mustQuote(StringRef) {
157 return QuotingType::None;
160 void ScalarTraits<UUID>::output(const UUID &Value, void *, raw_ostream &OS) {
161 OS << Value.first << ": " << Value.second;
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 {};
173 QuotingType ScalarTraits<UUID>::mustQuote(StringRef) {
174 return QuotingType::Single;
177 } // end namespace yaml.
178 } // end namespace llvm.