|
10 | 10 | #include "clang/Basic/LLVM.h"
|
11 | 11 | #include "clang/Driver/Driver.h"
|
12 | 12 | #include "llvm/ADT/DenseSet.h"
|
| 13 | +#include "llvm/ADT/SmallSet.h" |
13 | 14 | #include "llvm/ADT/StringRef.h"
|
14 | 15 | #include "llvm/Support/Compiler.h"
|
15 | 16 | #include "llvm/Support/ErrorHandling.h"
|
@@ -201,13 +202,20 @@ struct MultilibGroupSerialization {
|
201 | 202 |
|
202 | 203 | struct MultilibSetSerialization {
|
203 | 204 | llvm::VersionTuple MultilibVersion;
|
204 |
| - std::vector<MultilibGroupSerialization> Groups; |
205 |
| - std::vector<MultilibSerialization> Multilibs; |
206 |
| - std::vector<MultilibSet::FlagMatcher> FlagMatchers; |
| 205 | + SmallVector<MultilibGroupSerialization> Groups; |
| 206 | + SmallVector<MultilibSerialization> Multilibs; |
| 207 | + SmallVector<MultilibSet::FlagMatcher> FlagMatchers; |
| 208 | + SmallVector<custom_flag::DeclarationPtr> CustomFlagDeclarations; |
207 | 209 | };
|
208 | 210 |
|
209 | 211 | } // end anonymous namespace
|
210 | 212 |
|
| 213 | +LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSerialization) |
| 214 | +LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibGroupSerialization) |
| 215 | +LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSet::FlagMatcher) |
| 216 | +LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::ValueDetail) |
| 217 | +LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::DeclarationPtr) |
| 218 | + |
211 | 219 | template <> struct llvm::yaml::MappingTraits<MultilibSerialization> {
|
212 | 220 | static void mapping(llvm::yaml::IO &io, MultilibSerialization &V) {
|
213 | 221 | io.mapOptional("Dir", V.Dir);
|
@@ -255,11 +263,63 @@ template <> struct llvm::yaml::MappingTraits<MultilibSet::FlagMatcher> {
|
255 | 263 | }
|
256 | 264 | };
|
257 | 265 |
|
| 266 | +template <> |
| 267 | +struct llvm::yaml::MappingContextTraits<custom_flag::ValueDetail, |
| 268 | + llvm::SmallSet<std::string, 32>> { |
| 269 | + static void mapping(llvm::yaml::IO &io, custom_flag::ValueDetail &V, |
| 270 | + llvm::SmallSet<std::string, 32> &) { |
| 271 | + io.mapRequired("Name", V.Name); |
| 272 | + io.mapOptional("DriverArgs", V.DriverArgs); |
| 273 | + } |
| 274 | + static std::string validate(IO &io, custom_flag::ValueDetail &V, |
| 275 | + llvm::SmallSet<std::string, 32> &NameSet) { |
| 276 | + if (V.Name.empty()) |
| 277 | + return "custom flag value requires a name"; |
| 278 | + if (!NameSet.insert(V.Name).second) |
| 279 | + return "duplicate custom flag value name: \"" + V.Name + "\""; |
| 280 | + return {}; |
| 281 | + } |
| 282 | +}; |
| 283 | + |
| 284 | +template <> |
| 285 | +struct llvm::yaml::MappingContextTraits<custom_flag::DeclarationPtr, |
| 286 | + llvm::SmallSet<std::string, 32>> { |
| 287 | + static void mapping(llvm::yaml::IO &io, custom_flag::DeclarationPtr &V, |
| 288 | + llvm::SmallSet<std::string, 32> &NameSet) { |
| 289 | + assert(!V); |
| 290 | + V = std::make_shared<custom_flag::Declaration>(); |
| 291 | + io.mapRequired("Name", V->Name); |
| 292 | + io.mapRequired("Values", V->ValueList, NameSet); |
| 293 | + std::string DefaultValueName; |
| 294 | + io.mapRequired("Default", DefaultValueName); |
| 295 | + |
| 296 | + for (auto [Idx, Value] : llvm::enumerate(V->ValueList)) { |
| 297 | + Value.Decl = V; |
| 298 | + if (Value.Name == DefaultValueName) { |
| 299 | + assert(!V->DefaultValueIdx); |
| 300 | + V->DefaultValueIdx = Idx; |
| 301 | + } |
| 302 | + } |
| 303 | + } |
| 304 | + static std::string validate(IO &io, custom_flag::DeclarationPtr &V, |
| 305 | + llvm::SmallSet<std::string, 32> &) { |
| 306 | + if (V->Name.empty()) |
| 307 | + return "custom flag requires a name"; |
| 308 | + if (V->ValueList.empty()) |
| 309 | + return "custom flag must have at least one value"; |
| 310 | + if (!V->DefaultValueIdx) |
| 311 | + return "custom flag must have a default value"; |
| 312 | + return {}; |
| 313 | + } |
| 314 | +}; |
| 315 | + |
258 | 316 | template <> struct llvm::yaml::MappingTraits<MultilibSetSerialization> {
|
259 | 317 | static void mapping(llvm::yaml::IO &io, MultilibSetSerialization &M) {
|
260 | 318 | io.mapRequired("MultilibVersion", M.MultilibVersion);
|
261 | 319 | io.mapRequired("Variants", M.Multilibs);
|
262 | 320 | io.mapOptional("Groups", M.Groups);
|
| 321 | + llvm::SmallSet<std::string, 32> NameSet; |
| 322 | + io.mapOptionalWithContext("Flags", M.CustomFlagDeclarations, NameSet); |
263 | 323 | io.mapOptional("Mappings", M.FlagMatchers);
|
264 | 324 | }
|
265 | 325 | static std::string validate(IO &io, MultilibSetSerialization &M) {
|
@@ -288,10 +348,6 @@ template <> struct llvm::yaml::MappingTraits<MultilibSetSerialization> {
|
288 | 348 | }
|
289 | 349 | };
|
290 | 350 |
|
291 |
| -LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSerialization) |
292 |
| -LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibGroupSerialization) |
293 |
| -LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSet::FlagMatcher) |
294 |
| - |
295 | 351 | llvm::ErrorOr<MultilibSet>
|
296 | 352 | MultilibSet::parseYaml(llvm::MemoryBufferRef Input,
|
297 | 353 | llvm::SourceMgr::DiagHandlerTy DiagHandler,
|
@@ -319,7 +375,8 @@ MultilibSet::parseYaml(llvm::MemoryBufferRef Input,
|
319 | 375 | }
|
320 | 376 | }
|
321 | 377 |
|
322 |
| - return MultilibSet(std::move(Multilibs), std::move(MS.FlagMatchers)); |
| 378 | + return MultilibSet(std::move(Multilibs), std::move(MS.FlagMatchers), |
| 379 | + std::move(MS.CustomFlagDeclarations)); |
323 | 380 | }
|
324 | 381 |
|
325 | 382 | LLVM_DUMP_METHOD void MultilibSet::dump() const {
|
|
0 commit comments