RemarkSerializer.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //===- RemarkSerializer.cpp -----------------------------------------------===//
  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 provides tools for serializing remarks.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "llvm/Remarks/RemarkSerializer.h"
  13. #include "llvm/Remarks/BitstreamRemarkSerializer.h"
  14. #include "llvm/Remarks/YAMLRemarkSerializer.h"
  15. using namespace llvm;
  16. using namespace llvm::remarks;
  17. Expected<std::unique_ptr<RemarkSerializer>>
  18. remarks::createRemarkSerializer(Format RemarksFormat, SerializerMode Mode,
  19. raw_ostream &OS) {
  20. switch (RemarksFormat) {
  21. case Format::Unknown:
  22. return createStringError(std::errc::invalid_argument,
  23. "Unknown remark serializer format.");
  24. case Format::YAML:
  25. return std::make_unique<YAMLRemarkSerializer>(OS, Mode);
  26. case Format::YAMLStrTab:
  27. return std::make_unique<YAMLStrTabRemarkSerializer>(OS, Mode);
  28. case Format::Bitstream:
  29. return std::make_unique<BitstreamRemarkSerializer>(OS, Mode);
  30. }
  31. llvm_unreachable("Unknown remarks::Format enum");
  32. }
  33. Expected<std::unique_ptr<RemarkSerializer>>
  34. remarks::createRemarkSerializer(Format RemarksFormat, SerializerMode Mode,
  35. raw_ostream &OS, remarks::StringTable StrTab) {
  36. switch (RemarksFormat) {
  37. case Format::Unknown:
  38. return createStringError(std::errc::invalid_argument,
  39. "Unknown remark serializer format.");
  40. case Format::YAML:
  41. return std::make_unique<YAMLRemarkSerializer>(OS, Mode, std::move(StrTab));
  42. case Format::YAMLStrTab:
  43. return std::make_unique<YAMLStrTabRemarkSerializer>(OS, Mode,
  44. std::move(StrTab));
  45. case Format::Bitstream:
  46. return std::make_unique<BitstreamRemarkSerializer>(OS, Mode,
  47. std::move(StrTab));
  48. }
  49. llvm_unreachable("Unknown remarks::Format enum");
  50. }