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