Path: blob/main/contrib/llvm-project/llvm/lib/ObjectYAML/OffloadYAML.cpp
35234 views
//===- OffloadYAML.cpp - Offload Binary YAMLIO implementation -------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines classes for handling the YAML representation of offload9// binaries.10//11//===----------------------------------------------------------------------===//1213#include <llvm/ObjectYAML/OffloadYAML.h>1415namespace llvm {1617namespace yaml {1819void ScalarEnumerationTraits<object::ImageKind>::enumeration(20IO &IO, object::ImageKind &Value) {21#define ECase(X) IO.enumCase(Value, #X, object::X)22ECase(IMG_None);23ECase(IMG_Object);24ECase(IMG_Bitcode);25ECase(IMG_Cubin);26ECase(IMG_Fatbinary);27ECase(IMG_PTX);28ECase(IMG_LAST);29#undef ECase30IO.enumFallback<Hex16>(Value);31}3233void ScalarEnumerationTraits<object::OffloadKind>::enumeration(34IO &IO, object::OffloadKind &Value) {35#define ECase(X) IO.enumCase(Value, #X, object::X)36ECase(OFK_None);37ECase(OFK_OpenMP);38ECase(OFK_Cuda);39ECase(OFK_HIP);40ECase(OFK_LAST);41#undef ECase42IO.enumFallback<Hex16>(Value);43}4445void MappingTraits<OffloadYAML::Binary>::mapping(IO &IO,46OffloadYAML::Binary &O) {47assert(!IO.getContext() && "The IO context is initialized already");48IO.setContext(&O);49IO.mapTag("!Offload", true);50IO.mapOptional("Version", O.Version);51IO.mapOptional("Size", O.Size);52IO.mapOptional("EntryOffset", O.EntryOffset);53IO.mapOptional("EntrySize", O.EntrySize);54IO.mapRequired("Members", O.Members);55IO.setContext(nullptr);56}5758void MappingTraits<OffloadYAML::Binary::StringEntry>::mapping(59IO &IO, OffloadYAML::Binary::StringEntry &SE) {60assert(IO.getContext() && "The IO context is not initialized");61IO.mapRequired("Key", SE.Key);62IO.mapRequired("Value", SE.Value);63}6465void MappingTraits<OffloadYAML::Binary::Member>::mapping(66IO &IO, OffloadYAML::Binary::Member &M) {67assert(IO.getContext() && "The IO context is not initialized");68IO.mapOptional("ImageKind", M.ImageKind);69IO.mapOptional("OffloadKind", M.OffloadKind);70IO.mapOptional("Flags", M.Flags);71IO.mapOptional("String", M.StringEntries);72IO.mapOptional("Content", M.Content);73}7475} // namespace yaml7677} // namespace llvm787980