diff options
author | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2019-07-24 16:36:35 +0000 |
---|---|---|
committer | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2019-07-24 16:36:35 +0000 |
commit | c5cc9efa075b6fcd8cfe16d59764dcbebc949b8c (patch) | |
tree | ebf1b2ea26344a71bcd96d7e7b19afb8b25d76d2 /llvm/lib/Remarks/RemarkSerializer.cpp | |
parent | 419f1a4185d551594dc453b258bc4b8417edcfeb (diff) | |
download | bcm5719-llvm-c5cc9efa075b6fcd8cfe16d59764dcbebc949b8c.tar.gz bcm5719-llvm-c5cc9efa075b6fcd8cfe16d59764dcbebc949b8c.zip |
[Remarks] Simplify the creation of remark serializers
Introduce two new functions to create a serializer, and add support for
more combinations to the YAMLStrTabSerializer.
llvm-svn: 366919
Diffstat (limited to 'llvm/lib/Remarks/RemarkSerializer.cpp')
-rw-r--r-- | llvm/lib/Remarks/RemarkSerializer.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/llvm/lib/Remarks/RemarkSerializer.cpp b/llvm/lib/Remarks/RemarkSerializer.cpp new file mode 100644 index 00000000000..b1cfd098134 --- /dev/null +++ b/llvm/lib/Remarks/RemarkSerializer.cpp @@ -0,0 +1,48 @@ +//===- RemarkSerializer.cpp -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file provides tools for serializing remarks. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Remarks/RemarkSerializer.h" +#include "llvm/Remarks/YAMLRemarkSerializer.h" + +using namespace llvm; +using namespace llvm::remarks; + +Expected<std::unique_ptr<Serializer>> +remarks::createRemarkSerializer(Format RemarksFormat, raw_ostream &OS) { + switch (RemarksFormat) { + case Format::Unknown: + return createStringError(std::errc::invalid_argument, + "Unknown remark serializer format."); + case Format::YAML: + return llvm::make_unique<YAMLSerializer>(OS); + case Format::YAMLStrTab: + return llvm::make_unique<YAMLStrTabSerializer>(OS); + } + llvm_unreachable("Unknown remarks::Format enum"); +} + +Expected<std::unique_ptr<Serializer>> +remarks::createRemarkSerializer(Format RemarksFormat, raw_ostream &OS, + remarks::StringTable StrTab) { + switch (RemarksFormat) { + case Format::Unknown: + return createStringError(std::errc::invalid_argument, + "Unknown remark serializer format."); + case Format::YAML: + return createStringError(std::errc::invalid_argument, + "Unable to use a string table with the yaml " + "format. Use 'yaml-strtab' instead."); + case Format::YAMLStrTab: + return llvm::make_unique<YAMLStrTabSerializer>(OS, std::move(StrTab)); + } + llvm_unreachable("Unknown remarks::Format enum"); +} |