|
19 | 19 | #include "llvm/Support/CommandLine.h"
|
20 | 20 | #include "llvm/Support/MemoryBuffer.h"
|
21 | 21 | #include "llvm/Support/YAMLParser.h"
|
| 22 | +#include "llvm/Support/YAMLTraits.h" |
22 | 23 |
|
23 | 24 | using namespace swift;
|
24 | 25 | using namespace fine_grained_dependencies;
|
25 | 26 |
|
| 27 | +//============================================================================== |
| 28 | +// MARK: SourceFileDepGraph YAML reading & writing |
| 29 | +//============================================================================== |
| 30 | + |
| 31 | +// This introduces a redefinition where ever std::is_same_t<size_t, uint64_t> |
| 32 | +// holds |
| 33 | +#if !(defined(__linux__) || defined(_WIN64)) |
| 34 | +LLVM_YAML_DECLARE_SCALAR_TRAITS(size_t, QuotingType::None) |
| 35 | +#endif |
| 36 | +LLVM_YAML_DECLARE_ENUM_TRAITS(swift::fine_grained_dependencies::NodeKind) |
| 37 | +LLVM_YAML_DECLARE_ENUM_TRAITS(swift::fine_grained_dependencies::DeclAspect) |
| 38 | +LLVM_YAML_DECLARE_MAPPING_TRAITS( |
| 39 | + swift::fine_grained_dependencies::DependencyKey) |
| 40 | +LLVM_YAML_DECLARE_MAPPING_TRAITS(swift::fine_grained_dependencies::DepGraphNode) |
| 41 | + |
| 42 | +namespace llvm { |
| 43 | +namespace yaml { |
| 44 | +template <> |
| 45 | +struct MappingContextTraits< |
| 46 | + swift::fine_grained_dependencies::SourceFileDepGraphNode, |
| 47 | + swift::fine_grained_dependencies::SourceFileDepGraph> { |
| 48 | + using SourceFileDepGraphNode = |
| 49 | + swift::fine_grained_dependencies::SourceFileDepGraphNode; |
| 50 | + using SourceFileDepGraph = |
| 51 | + swift::fine_grained_dependencies::SourceFileDepGraph; |
| 52 | + |
| 53 | + static void mapping(IO &io, SourceFileDepGraphNode &node, |
| 54 | + SourceFileDepGraph &g); |
| 55 | +}; |
| 56 | + |
| 57 | +template <> |
| 58 | +struct SequenceTraits< |
| 59 | + std::vector<swift::fine_grained_dependencies::SourceFileDepGraphNode *>> { |
| 60 | + using SourceFileDepGraphNode = |
| 61 | + swift::fine_grained_dependencies::SourceFileDepGraphNode; |
| 62 | + using NodeVec = std::vector<SourceFileDepGraphNode *>; |
| 63 | + static size_t size(IO &, NodeVec &vec); |
| 64 | + static SourceFileDepGraphNode &element(IO &, NodeVec &vec, size_t index); |
| 65 | +}; |
| 66 | + |
| 67 | +} // namespace yaml |
| 68 | +} // namespace llvm |
| 69 | + |
| 70 | +LLVM_YAML_DECLARE_MAPPING_TRAITS( |
| 71 | + swift::fine_grained_dependencies::SourceFileDepGraph) |
| 72 | + |
| 73 | +namespace llvm { |
| 74 | +namespace yaml { |
| 75 | +// This introduces a redefinition for Linux. |
| 76 | +#if !(defined(__linux__) || defined(_WIN64)) |
| 77 | +void ScalarTraits<size_t>::output(const size_t &Val, void *, raw_ostream &out) { |
| 78 | + out << Val; |
| 79 | +} |
| 80 | + |
| 81 | +StringRef ScalarTraits<size_t>::input(StringRef scalar, void *ctxt, |
| 82 | + size_t &value) { |
| 83 | + return scalar.getAsInteger(10, value) ? "could not parse size_t" : ""; |
| 84 | +} |
| 85 | +#endif |
| 86 | + |
| 87 | +void ScalarEnumerationTraits<swift::fine_grained_dependencies::NodeKind>:: |
| 88 | + enumeration(IO &io, swift::fine_grained_dependencies::NodeKind &value) { |
| 89 | + using NodeKind = swift::fine_grained_dependencies::NodeKind; |
| 90 | + io.enumCase(value, "topLevel", NodeKind::topLevel); |
| 91 | + io.enumCase(value, "nominal", NodeKind::nominal); |
| 92 | + io.enumCase(value, "potentialMember", NodeKind::potentialMember); |
| 93 | + io.enumCase(value, "member", NodeKind::member); |
| 94 | + io.enumCase(value, "dynamicLookup", NodeKind::dynamicLookup); |
| 95 | + io.enumCase(value, "externalDepend", NodeKind::externalDepend); |
| 96 | + io.enumCase(value, "sourceFileProvide", NodeKind::sourceFileProvide); |
| 97 | +} |
| 98 | + |
| 99 | +void ScalarEnumerationTraits<DeclAspect>::enumeration( |
| 100 | + IO &io, swift::fine_grained_dependencies::DeclAspect &value) { |
| 101 | + using DeclAspect = swift::fine_grained_dependencies::DeclAspect; |
| 102 | + io.enumCase(value, "interface", DeclAspect::interface); |
| 103 | + io.enumCase(value, "implementation", DeclAspect::implementation); |
| 104 | +} |
| 105 | + |
| 106 | +void MappingTraits<DependencyKey>::mapping( |
| 107 | + IO &io, swift::fine_grained_dependencies::DependencyKey &key) { |
| 108 | + io.mapRequired("kind", key.kind); |
| 109 | + io.mapRequired("aspect", key.aspect); |
| 110 | + io.mapRequired("context", key.context); |
| 111 | + io.mapRequired("name", key.name); |
| 112 | +} |
| 113 | + |
| 114 | +void MappingTraits<DepGraphNode>::mapping( |
| 115 | + IO &io, swift::fine_grained_dependencies::DepGraphNode &node) { |
| 116 | + io.mapRequired("key", node.key); |
| 117 | + io.mapOptional("fingerprint", node.fingerprint); |
| 118 | +} |
| 119 | + |
| 120 | +void MappingContextTraits<SourceFileDepGraphNode, SourceFileDepGraph>::mapping( |
| 121 | + IO &io, SourceFileDepGraphNode &node, SourceFileDepGraph &g) { |
| 122 | + MappingTraits<DepGraphNode>::mapping(io, node); |
| 123 | + io.mapRequired("sequenceNumber", node.sequenceNumber); |
| 124 | + std::vector<size_t> defsIDependUponVec(node.defsIDependUpon.begin(), |
| 125 | + node.defsIDependUpon.end()); |
| 126 | + io.mapRequired("defsIDependUpon", defsIDependUponVec); |
| 127 | + io.mapRequired("isProvides", node.isProvides); |
| 128 | + if (!io.outputting()) { |
| 129 | + for (size_t u : defsIDependUponVec) |
| 130 | + node.defsIDependUpon.insert(u); |
| 131 | + } |
| 132 | + assert(g.getNode(node.sequenceNumber) && "Bad sequence number"); |
| 133 | +} |
| 134 | + |
| 135 | +size_t SequenceTraits<std::vector<SourceFileDepGraphNode *>>::size( |
| 136 | + IO &, std::vector<SourceFileDepGraphNode *> &vec) { |
| 137 | + return vec.size(); |
| 138 | +} |
| 139 | + |
| 140 | +SourceFileDepGraphNode & |
| 141 | +SequenceTraits<std::vector<SourceFileDepGraphNode *>>::element( |
| 142 | + IO &, std::vector<SourceFileDepGraphNode *> &vec, size_t index) { |
| 143 | + while (vec.size() <= index) |
| 144 | + vec.push_back(new SourceFileDepGraphNode()); |
| 145 | + return *vec[index]; |
| 146 | +} |
| 147 | + |
| 148 | +void MappingTraits<SourceFileDepGraph>::mapping(IO &io, SourceFileDepGraph &g) { |
| 149 | + io.mapRequired("allNodes", g.allNodes, g); |
| 150 | +} |
| 151 | +} // namespace yaml |
| 152 | +} // namespace llvm |
| 153 | + |
26 | 154 | enum class ActionType : unsigned {
|
27 | 155 | None,
|
28 | 156 | BinaryToYAML,
|
@@ -81,7 +209,7 @@ int main(int argc, char *argv[]) {
|
81 | 209 | bool hadError =
|
82 | 210 | withOutputFile(diags, options::OutputFilename,
|
83 | 211 | [&](llvm::raw_pwrite_stream &out) {
|
84 |
| - out << fg->yamlProlog(/*hadError=*/false); |
| 212 | + out << "# Fine-grained v0\n"; |
85 | 213 | llvm::yaml::Output yamlWriter(out);
|
86 | 214 | yamlWriter << *fg;
|
87 | 215 | return false;
|
|
0 commit comments