xref: /freebsd/contrib/llvm-project/llvm/lib/Remarks/RemarkFormat.cpp (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric //===- RemarkFormat.cpp --------------------------------------------------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric //
9*0b57cec5SDimitry Andric // Implementation of utilities to handle the different remark formats.
10*0b57cec5SDimitry Andric //
11*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
12*0b57cec5SDimitry Andric 
13*0b57cec5SDimitry Andric #include "llvm/Remarks/RemarkFormat.h"
14*0b57cec5SDimitry Andric #include "llvm/ADT/StringSwitch.h"
15*0b57cec5SDimitry Andric 
16*0b57cec5SDimitry Andric using namespace llvm;
17*0b57cec5SDimitry Andric using namespace llvm::remarks;
18*0b57cec5SDimitry Andric 
19*0b57cec5SDimitry Andric Expected<Format> llvm::remarks::parseFormat(StringRef FormatStr) {
20*0b57cec5SDimitry Andric   auto Result = StringSwitch<Format>(FormatStr)
21*0b57cec5SDimitry Andric                     .Cases("", "yaml", Format::YAML)
22*0b57cec5SDimitry Andric                     .Default(Format::Unknown);
23*0b57cec5SDimitry Andric 
24*0b57cec5SDimitry Andric   if (Result == Format::Unknown)
25*0b57cec5SDimitry Andric     return createStringError(std::make_error_code(std::errc::invalid_argument),
26*0b57cec5SDimitry Andric                              "Unknown remark serializer format: '%s'",
27*0b57cec5SDimitry Andric                              FormatStr.data());
28*0b57cec5SDimitry Andric 
29*0b57cec5SDimitry Andric   return Result;
30*0b57cec5SDimitry Andric }
31