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" |
Francis Visoiu Mistrih | 84e8097 | 2019-07-31 00:13:51 +0000 | [diff] [blame] | 14 | #include "llvm/Remarks/BitstreamRemarkSerializer.h" |
Francis Visoiu Mistrih | c5cc9ef | 2019-07-24 16:36:35 +0000 | [diff] [blame] | 15 | #include "llvm/Remarks/YAMLRemarkSerializer.h" |
| 16 | |
| 17 | using namespace llvm; |
| 18 | using namespace llvm::remarks; |
| 19 | |
Francis Visoiu Mistrih | ff4b515 | 2019-07-24 19:47:57 +0000 | [diff] [blame] | 20 | Expected<std::unique_ptr<RemarkSerializer>> |
Francis Visoiu Mistrih | 5ed3d14 | 2019-07-30 16:01:40 +0000 | [diff] [blame] | 21 | remarks::createRemarkSerializer(Format RemarksFormat, SerializerMode Mode, |
| 22 | raw_ostream &OS) { |
Francis Visoiu Mistrih | c5cc9ef | 2019-07-24 16:36:35 +0000 | [diff] [blame] | 23 | switch (RemarksFormat) { |
| 24 | case Format::Unknown: |
| 25 | return createStringError(std::errc::invalid_argument, |
| 26 | "Unknown remark serializer format."); |
| 27 | case Format::YAML: |
Jonas Devlieghere | 0eaee54 | 2019-08-15 15:54:37 +0000 | [diff] [blame] | 28 | return std::make_unique<YAMLRemarkSerializer>(OS, Mode); |
Francis Visoiu Mistrih | c5cc9ef | 2019-07-24 16:36:35 +0000 | [diff] [blame] | 29 | case Format::YAMLStrTab: |
Jonas Devlieghere | 0eaee54 | 2019-08-15 15:54:37 +0000 | [diff] [blame] | 30 | return std::make_unique<YAMLStrTabRemarkSerializer>(OS, Mode); |
Francis Visoiu Mistrih | 84e8097 | 2019-07-31 00:13:51 +0000 | [diff] [blame] | 31 | case Format::Bitstream: |
Jonas Devlieghere | 0eaee54 | 2019-08-15 15:54:37 +0000 | [diff] [blame] | 32 | return std::make_unique<BitstreamRemarkSerializer>(OS, Mode); |
Francis Visoiu Mistrih | c5cc9ef | 2019-07-24 16:36:35 +0000 | [diff] [blame] | 33 | } |
| 34 | llvm_unreachable("Unknown remarks::Format enum"); |
| 35 | } |
| 36 | |
Francis Visoiu Mistrih | ff4b515 | 2019-07-24 19:47:57 +0000 | [diff] [blame] | 37 | Expected<std::unique_ptr<RemarkSerializer>> |
Francis Visoiu Mistrih | 5ed3d14 | 2019-07-30 16:01:40 +0000 | [diff] [blame] | 38 | remarks::createRemarkSerializer(Format RemarksFormat, SerializerMode Mode, |
| 39 | raw_ostream &OS, remarks::StringTable StrTab) { |
Francis Visoiu Mistrih | c5cc9ef | 2019-07-24 16:36:35 +0000 | [diff] [blame] | 40 | switch (RemarksFormat) { |
| 41 | case Format::Unknown: |
| 42 | return createStringError(std::errc::invalid_argument, |
| 43 | "Unknown remark serializer format."); |
| 44 | case Format::YAML: |
Francis Visoiu Mistrih | 77383d8 | 2019-09-16 22:45:17 +0000 | [diff] [blame] | 45 | return std::make_unique<YAMLRemarkSerializer>(OS, Mode, std::move(StrTab)); |
Francis Visoiu Mistrih | c5cc9ef | 2019-07-24 16:36:35 +0000 | [diff] [blame] | 46 | case Format::YAMLStrTab: |
Jonas Devlieghere | 0eaee54 | 2019-08-15 15:54:37 +0000 | [diff] [blame] | 47 | return std::make_unique<YAMLStrTabRemarkSerializer>(OS, Mode, |
Francis Visoiu Mistrih | 77383d8 | 2019-09-16 22:45:17 +0000 | [diff] [blame] | 48 | std::move(StrTab)); |
Francis Visoiu Mistrih | 84e8097 | 2019-07-31 00:13:51 +0000 | [diff] [blame] | 49 | case Format::Bitstream: |
Jonas Devlieghere | 0eaee54 | 2019-08-15 15:54:37 +0000 | [diff] [blame] | 50 | return std::make_unique<BitstreamRemarkSerializer>(OS, Mode, |
Francis Visoiu Mistrih | 77383d8 | 2019-09-16 22:45:17 +0000 | [diff] [blame] | 51 | std::move(StrTab)); |
Francis Visoiu Mistrih | c5cc9ef | 2019-07-24 16:36:35 +0000 | [diff] [blame] | 52 | } |
| 53 | llvm_unreachable("Unknown remarks::Format enum"); |
| 54 | } |