Francis Visoiu Mistrih | c5cc9ef | 2019-07-24 16:36:35 +0000 | [diff] [blame] | 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 | |
Francis Visoiu Mistrih | ff4b515 | 2019-07-24 19:47:57 +0000 | [diff] [blame] | 19 | Expected<std::unique_ptr<RemarkSerializer>> |
Francis Visoiu Mistrih | 5ed3d14 | 2019-07-30 16:01:40 +0000 | [diff] [blame^] | 20 | remarks::createRemarkSerializer(Format RemarksFormat, SerializerMode Mode, |
| 21 | raw_ostream &OS) { |
Francis Visoiu Mistrih | c5cc9ef | 2019-07-24 16:36:35 +0000 | [diff] [blame] | 22 | switch (RemarksFormat) { |
| 23 | case Format::Unknown: |
| 24 | return createStringError(std::errc::invalid_argument, |
| 25 | "Unknown remark serializer format."); |
| 26 | case Format::YAML: |
Francis Visoiu Mistrih | 5ed3d14 | 2019-07-30 16:01:40 +0000 | [diff] [blame^] | 27 | return llvm::make_unique<YAMLRemarkSerializer>(OS, Mode); |
Francis Visoiu Mistrih | c5cc9ef | 2019-07-24 16:36:35 +0000 | [diff] [blame] | 28 | case Format::YAMLStrTab: |
Francis Visoiu Mistrih | 5ed3d14 | 2019-07-30 16:01:40 +0000 | [diff] [blame^] | 29 | return llvm::make_unique<YAMLStrTabRemarkSerializer>(OS, Mode); |
Francis Visoiu Mistrih | c5cc9ef | 2019-07-24 16:36:35 +0000 | [diff] [blame] | 30 | } |
| 31 | llvm_unreachable("Unknown remarks::Format enum"); |
| 32 | } |
| 33 | |
Francis Visoiu Mistrih | ff4b515 | 2019-07-24 19:47:57 +0000 | [diff] [blame] | 34 | Expected<std::unique_ptr<RemarkSerializer>> |
Francis Visoiu Mistrih | 5ed3d14 | 2019-07-30 16:01:40 +0000 | [diff] [blame^] | 35 | remarks::createRemarkSerializer(Format RemarksFormat, SerializerMode Mode, |
| 36 | raw_ostream &OS, remarks::StringTable StrTab) { |
Francis Visoiu Mistrih | c5cc9ef | 2019-07-24 16:36:35 +0000 | [diff] [blame] | 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: |
Francis Visoiu Mistrih | 5ed3d14 | 2019-07-30 16:01:40 +0000 | [diff] [blame^] | 46 | return llvm::make_unique<YAMLStrTabRemarkSerializer>(OS, Mode, |
| 47 | std::move(StrTab)); |
Francis Visoiu Mistrih | c5cc9ef | 2019-07-24 16:36:35 +0000 | [diff] [blame] | 48 | } |
| 49 | llvm_unreachable("Unknown remarks::Format enum"); |
| 50 | } |