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