1 //===- OffloadYAML.h - Offload Binary YAMLIO implementation -----*- C++ -*-===//
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 /// \file
10 /// This file declares classes for handling the YAML representation of
11 /// offloading binaries.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_OBJECTYAML_OFFLOADYAML_H
16 #define LLVM_OBJECTYAML_OFFLOADYAML_H
17 
18 #include "llvm/ADT/MapVector.h"
19 #include "llvm/Object/OffloadBinary.h"
20 #include "llvm/ObjectYAML/YAML.h"
21 #include "llvm/Support/YAMLTraits.h"
22 
23 namespace llvm {
24 namespace OffloadYAML {
25 
26 struct Binary {
27   struct StringEntry {
28     StringRef Key;
29     StringRef Value;
30   };
31 
32   struct Member {
33     Optional<object::ImageKind> ImageKind;
34     Optional<object::OffloadKind> OffloadKind;
35     Optional<uint32_t> Flags;
36     Optional<std::vector<StringEntry>> StringEntries;
37     Optional<yaml::BinaryRef> Content;
38   };
39 
40   Optional<uint32_t> Version;
41   Optional<uint64_t> Size;
42   Optional<uint64_t> EntryOffset;
43   Optional<uint64_t> EntrySize;
44   std::vector<Member> Members;
45 };
46 
47 } // end namespace OffloadYAML
48 } // end namespace llvm
49 
50 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::OffloadYAML::Binary::Member)
51 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::OffloadYAML::Binary::StringEntry)
52 
53 namespace llvm {
54 namespace yaml {
55 
56 template <> struct ScalarEnumerationTraits<object::ImageKind> {
57   static void enumeration(IO &IO, object::ImageKind &Value);
58 };
59 
60 template <> struct ScalarEnumerationTraits<object::OffloadKind> {
61   static void enumeration(IO &IO, object::OffloadKind &Value);
62 };
63 
64 template <> struct MappingTraits<OffloadYAML::Binary> {
65   static void mapping(IO &IO, OffloadYAML::Binary &O);
66 };
67 
68 template <> struct MappingTraits<OffloadYAML::Binary::StringEntry> {
69   static void mapping(IO &IO, OffloadYAML::Binary::StringEntry &M);
70 };
71 
72 template <> struct MappingTraits<OffloadYAML::Binary::Member> {
73   static void mapping(IO &IO, OffloadYAML::Binary::Member &M);
74 };
75 
76 } // end namespace yaml
77 } // end namespace llvm
78 
79 #endif // LLVM_OBJECTYAML_OFFLOADYAML_H
80