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 
13 #include "llvm/Remarks/RemarkSerializer.h"
14 #include "llvm/Remarks/YAMLRemarkSerializer.h"
15 
16 using namespace llvm;
17 using namespace llvm::remarks;
18 
19 Expected<std::unique_ptr<RemarkSerializer>>
20 remarks::createRemarkSerializer(Format RemarksFormat, SerializerMode Mode,
21                                 raw_ostream &OS) {
22   switch (RemarksFormat) {
23   case Format::Unknown:
24     return createStringError(std::errc::invalid_argument,
25                              "Unknown remark serializer format.");
26   case Format::YAML:
27     return llvm::make_unique<YAMLRemarkSerializer>(OS, Mode);
28   case Format::YAMLStrTab:
29     return llvm::make_unique<YAMLStrTabRemarkSerializer>(OS, Mode);
30   }
31   llvm_unreachable("Unknown remarks::Format enum");
32 }
33 
34 Expected<std::unique_ptr<RemarkSerializer>>
35 remarks::createRemarkSerializer(Format RemarksFormat, SerializerMode Mode,
36                                 raw_ostream &OS, remarks::StringTable StrTab) {
37   switch (RemarksFormat) {
38   case Format::Unknown:
39     return createStringError(std::errc::invalid_argument,
40                              "Unknown remark serializer format.");
41   case Format::YAML:
42     return createStringError(std::errc::invalid_argument,
43                              "Unable to use a string table with the yaml "
44                              "format. Use 'yaml-strtab' instead.");
45   case Format::YAMLStrTab:
46     return llvm::make_unique<YAMLStrTabRemarkSerializer>(OS, Mode,
47                                                          std::move(StrTab));
48   }
49   llvm_unreachable("Unknown remarks::Format enum");
50 }
51