1//===- OffloadYAML.cpp - Offload Binary YAMLIO implementation -------------===//
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// This file defines classes for handling the YAML representation of offload
10// binaries.
11//
12//===----------------------------------------------------------------------===//
13
14#include <llvm/ObjectYAML/OffloadYAML.h>
15
16namespace llvm {
17
18namespace yaml {
19
20void ScalarEnumerationTraits<object::ImageKind>::enumeration(
21 IO &IO, object::ImageKind &Value) {
22#define ECase(X) IO.enumCase(Value, #X, object::X)
23 ECase(IMG_None);
24 ECase(IMG_Object);
25 ECase(IMG_Bitcode);
26 ECase(IMG_Cubin);
27 ECase(IMG_Fatbinary);
28 ECase(IMG_PTX);
29 ECase(IMG_LAST);
30#undef ECase
31 IO.enumFallback<Hex16>(Val&: Value);
32}
33
34void ScalarEnumerationTraits<object::OffloadKind>::enumeration(
35 IO &IO, object::OffloadKind &Value) {
36#define ECase(X) IO.enumCase(Value, #X, object::X)
37 ECase(OFK_None);
38 ECase(OFK_OpenMP);
39 ECase(OFK_Cuda);
40 ECase(OFK_HIP);
41 ECase(OFK_SYCL);
42 ECase(OFK_LAST);
43#undef ECase
44 IO.enumFallback<Hex16>(Val&: Value);
45}
46
47void ScalarEnumerationTraits<compression::Format>::enumeration(
48 IO &IO, compression::Format &Value) {
49 IO.enumCase(Val&: Value, Str: "zlib", ConstVal: compression::Format::Zlib);
50 IO.enumCase(Val&: Value, Str: "zstd", ConstVal: compression::Format::Zstd);
51}
52
53void MappingTraits<OffloadYAML::Binary>::mapping(IO &IO,
54 OffloadYAML::Binary &O) {
55 assert(!IO.getContext() && "The IO context is initialized already");
56 IO.setContext(&O);
57 IO.mapTag(Tag: "!Offload", Default: true);
58 IO.mapOptional(Key: "Version", Val&: O.Version);
59 IO.mapOptional(Key: "Size", Val&: O.Size);
60 IO.mapOptional(Key: "EntriesOffset", Val&: O.EntriesOffset);
61 IO.mapOptional(Key: "EntriesCount", Val&: O.EntriesCount);
62 IO.mapOptional(Key: "Compression", Val&: O.Compression);
63 IO.mapRequired(Key: "Members", Val&: O.Members);
64 IO.setContext(nullptr);
65}
66
67void MappingTraits<OffloadYAML::Binary::StringEntry>::mapping(
68 IO &IO, OffloadYAML::Binary::StringEntry &SE) {
69 assert(IO.getContext() && "The IO context is not initialized");
70 IO.mapRequired(Key: "Key", Val&: SE.Key);
71 IO.mapRequired(Key: "Value", Val&: SE.Value);
72}
73
74void MappingTraits<OffloadYAML::Binary::Member>::mapping(
75 IO &IO, OffloadYAML::Binary::Member &M) {
76 assert(IO.getContext() && "The IO context is not initialized");
77 IO.mapOptional(Key: "ImageKind", Val&: M.ImageKind);
78 IO.mapOptional(Key: "OffloadKind", Val&: M.OffloadKind);
79 IO.mapOptional(Key: "Flags", Val&: M.Flags);
80 IO.mapOptional(Key: "String", Val&: M.StringEntries);
81 IO.mapOptional(Key: "Content", Val&: M.Content);
82}
83
84} // namespace yaml
85
86} // namespace llvm
87