OffloadYAML.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #include <llvm/ObjectYAML/OffloadYAML.h>
  14. namespace llvm {
  15. namespace yaml {
  16. void ScalarEnumerationTraits<object::ImageKind>::enumeration(
  17. IO &IO, object::ImageKind &Value) {
  18. #define ECase(X) IO.enumCase(Value, #X, object::X)
  19. ECase(IMG_None);
  20. ECase(IMG_Object);
  21. ECase(IMG_Bitcode);
  22. ECase(IMG_Cubin);
  23. ECase(IMG_Fatbinary);
  24. ECase(IMG_PTX);
  25. ECase(IMG_LAST);
  26. #undef ECase
  27. IO.enumFallback<Hex16>(Value);
  28. }
  29. void ScalarEnumerationTraits<object::OffloadKind>::enumeration(
  30. IO &IO, object::OffloadKind &Value) {
  31. #define ECase(X) IO.enumCase(Value, #X, object::X)
  32. ECase(OFK_None);
  33. ECase(OFK_OpenMP);
  34. ECase(OFK_Cuda);
  35. ECase(OFK_HIP);
  36. ECase(OFK_LAST);
  37. #undef ECase
  38. IO.enumFallback<Hex16>(Value);
  39. }
  40. void MappingTraits<OffloadYAML::Binary>::mapping(IO &IO,
  41. OffloadYAML::Binary &O) {
  42. assert(!IO.getContext() && "The IO context is initialized already");
  43. IO.setContext(&O);
  44. IO.mapTag("!Offload", true);
  45. IO.mapOptional("Version", O.Version);
  46. IO.mapOptional("Size", O.Size);
  47. IO.mapOptional("EntryOffset", O.EntryOffset);
  48. IO.mapOptional("EntrySize", O.EntrySize);
  49. IO.mapRequired("Members", O.Members);
  50. IO.setContext(nullptr);
  51. }
  52. void MappingTraits<OffloadYAML::Binary::StringEntry>::mapping(
  53. IO &IO, OffloadYAML::Binary::StringEntry &SE) {
  54. assert(IO.getContext() && "The IO context is not initialized");
  55. IO.mapRequired("Key", SE.Key);
  56. IO.mapRequired("Value", SE.Value);
  57. }
  58. void MappingTraits<OffloadYAML::Binary::Member>::mapping(
  59. IO &IO, OffloadYAML::Binary::Member &M) {
  60. assert(IO.getContext() && "The IO context is not initialized");
  61. IO.mapOptional("ImageKind", M.ImageKind);
  62. IO.mapOptional("OffloadKind", M.OffloadKind);
  63. IO.mapOptional("Flags", M.Flags);
  64. IO.mapOptional("String", M.StringEntries);
  65. IO.mapOptional("Content", M.Content);
  66. }
  67. } // namespace yaml
  68. } // namespace llvm