1 //===- TextStubCommon.h ---------------------------------------------------===//
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 // Defines common Text Stub YAML mappings.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_TEXTAPI_TEXT_STUB_COMMON_H
14 #define LLVM_TEXTAPI_TEXT_STUB_COMMON_H
15 
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Support/YAMLTraits.h"
18 #include "llvm/TextAPI/Architecture.h"
19 #include "llvm/TextAPI/InterfaceFile.h"
20 #include "llvm/TextAPI/Platform.h"
21 #include "llvm/TextAPI/Target.h"
22 
23 using UUID = std::pair<llvm::MachO::Target, std::string>;
24 
25 // clang-format off
26 enum TBDFlags : unsigned {
27   None                         = 0U,
28   FlatNamespace                = 1U << 0,
29   NotApplicationExtensionSafe  = 1U << 1,
30   InstallAPI                   = 1U << 2,
31   SimulatorSupport             = 1U << 3,
32   OSLibNotForSharedCache       = 1U << 4,
33   LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/OSLibNotForSharedCache),
34 };
35 // clang-format on
36 
LLVM_YAML_STRONG_TYPEDEF(llvm::StringRef,FlowStringRef)37 LLVM_YAML_STRONG_TYPEDEF(llvm::StringRef, FlowStringRef)
38 LLVM_YAML_STRONG_TYPEDEF(uint8_t, SwiftVersion)
39 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(UUID)
40 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(FlowStringRef)
41 
42 namespace llvm {
43 
44 namespace MachO {
45 class ArchitectureSet;
46 class PackedVersion;
47 
48 Expected<std::unique_ptr<InterfaceFile>>
49 getInterfaceFileFromJSON(StringRef JSON);
50 
51 Error serializeInterfaceFileToJSON(raw_ostream &OS, const InterfaceFile &File,
52                                    const FileType FileKind, bool Compact);
53 } // namespace MachO
54 
55 namespace yaml {
56 
57 template <> struct ScalarTraits<FlowStringRef> {
58   static void output(const FlowStringRef &, void *, raw_ostream &);
59   static StringRef input(StringRef, void *, FlowStringRef &);
60   static QuotingType mustQuote(StringRef);
61 };
62 
63 template <> struct ScalarEnumerationTraits<MachO::ObjCConstraintType> {
64   static void enumeration(IO &, MachO::ObjCConstraintType &);
65 };
66 
67 template <> struct ScalarTraits<MachO::PlatformSet> {
68   static void output(const MachO::PlatformSet &, void *, raw_ostream &);
69   static StringRef input(StringRef, void *, MachO::PlatformSet &);
70   static QuotingType mustQuote(StringRef);
71 };
72 
73 template <> struct ScalarBitSetTraits<MachO::ArchitectureSet> {
74   static void bitset(IO &, MachO::ArchitectureSet &);
75 };
76 
77 template <> struct ScalarTraits<MachO::Architecture> {
78   static void output(const MachO::Architecture &, void *, raw_ostream &);
79   static StringRef input(StringRef, void *, MachO::Architecture &);
80   static QuotingType mustQuote(StringRef);
81 };
82 
83 template <> struct ScalarTraits<MachO::PackedVersion> {
84   static void output(const MachO::PackedVersion &, void *, raw_ostream &);
85   static StringRef input(StringRef, void *, MachO::PackedVersion &);
86   static QuotingType mustQuote(StringRef);
87 };
88 
89 template <> struct ScalarTraits<SwiftVersion> {
90   static void output(const SwiftVersion &, void *, raw_ostream &);
91   static StringRef input(StringRef, void *, SwiftVersion &);
92   static QuotingType mustQuote(StringRef);
93 };
94 
95 // UUIDs are no longer respected but kept in the YAML parser
96 // to keep reading in older TBDs.
97 template <> struct ScalarTraits<UUID> {
98   static void output(const UUID &, void *, raw_ostream &);
99   static StringRef input(StringRef, void *, UUID &);
100   static QuotingType mustQuote(StringRef);
101 };
102 
103 } // end namespace yaml.
104 } // end namespace llvm.
105 
106 #endif // LLVM_TEXTAPI_TEXT_STUB_COMMON_H
107