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<Serializer>> 20 remarks::createRemarkSerializer(Format RemarksFormat, raw_ostream &OS) { 21 switch (RemarksFormat) { 22 case Format::Unknown: 23 return createStringError(std::errc::invalid_argument, 24 "Unknown remark serializer format."); 25 case Format::YAML: 26 return llvm::make_unique<YAMLSerializer>(OS); 27 case Format::YAMLStrTab: 28 return llvm::make_unique<YAMLStrTabSerializer>(OS); 29 } 30 llvm_unreachable("Unknown remarks::Format enum"); 31 } 32 33 Expected<std::unique_ptr<Serializer>> 34 remarks::createRemarkSerializer(Format RemarksFormat, raw_ostream &OS, 35 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 createStringError(std::errc::invalid_argument, 42 "Unable to use a string table with the yaml " 43 "format. Use 'yaml-strtab' instead."); 44 case Format::YAMLStrTab: 45 return llvm::make_unique<YAMLStrTabSerializer>(OS, std::move(StrTab)); 46 } 47 llvm_unreachable("Unknown remarks::Format enum"); 48 } 49