xref: /freebsd/contrib/llvm-project/llvm/lib/TextAPI/TextStubCommon.h (revision 47e073941f4e7ca6e9bde3fa65abbfcfed6bfa2b)
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    LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/InstallAPI),
32  };
33  // clang-format on
34  
35  LLVM_YAML_STRONG_TYPEDEF(llvm::StringRef, FlowStringRef)
36  LLVM_YAML_STRONG_TYPEDEF(uint8_t, SwiftVersion)
37  LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(UUID)
38  LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(FlowStringRef)
39  
40  namespace llvm {
41  
42  namespace MachO {
43  class ArchitectureSet;
44  class PackedVersion;
45  
46  Expected<std::unique_ptr<InterfaceFile>>
47  getInterfaceFileFromJSON(StringRef JSON);
48  
49  Error serializeInterfaceFileToJSON(raw_ostream &OS, const InterfaceFile &File,
50                                     bool Compact);
51  } // namespace MachO
52  
53  namespace yaml {
54  
55  template <> struct ScalarTraits<FlowStringRef> {
56    static void output(const FlowStringRef &, void *, raw_ostream &);
57    static StringRef input(StringRef, void *, FlowStringRef &);
58    static QuotingType mustQuote(StringRef);
59  };
60  
61  template <> struct ScalarEnumerationTraits<MachO::ObjCConstraintType> {
62    static void enumeration(IO &, MachO::ObjCConstraintType &);
63  };
64  
65  template <> struct ScalarTraits<MachO::PlatformSet> {
66    static void output(const MachO::PlatformSet &, void *, raw_ostream &);
67    static StringRef input(StringRef, void *, MachO::PlatformSet &);
68    static QuotingType mustQuote(StringRef);
69  };
70  
71  template <> struct ScalarBitSetTraits<MachO::ArchitectureSet> {
72    static void bitset(IO &, MachO::ArchitectureSet &);
73  };
74  
75  template <> struct ScalarTraits<MachO::Architecture> {
76    static void output(const MachO::Architecture &, void *, raw_ostream &);
77    static StringRef input(StringRef, void *, MachO::Architecture &);
78    static QuotingType mustQuote(StringRef);
79  };
80  
81  template <> struct ScalarTraits<MachO::PackedVersion> {
82    static void output(const MachO::PackedVersion &, void *, raw_ostream &);
83    static StringRef input(StringRef, void *, MachO::PackedVersion &);
84    static QuotingType mustQuote(StringRef);
85  };
86  
87  template <> struct ScalarTraits<SwiftVersion> {
88    static void output(const SwiftVersion &, void *, raw_ostream &);
89    static StringRef input(StringRef, void *, SwiftVersion &);
90    static QuotingType mustQuote(StringRef);
91  };
92  
93  // UUIDs are no longer respected but kept in the YAML parser
94  // to keep reading in older TBDs.
95  template <> struct ScalarTraits<UUID> {
96    static void output(const UUID &, void *, raw_ostream &);
97    static StringRef input(StringRef, void *, UUID &);
98    static QuotingType mustQuote(StringRef);
99  };
100  
101  } // end namespace yaml.
102  } // end namespace llvm.
103  
104  #endif // LLVM_TEXTAPI_TEXT_STUB_COMMON_H
105