1 //===- RemarkFormat.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 // Implementation of utilities to handle the different remark formats. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "llvm/Remarks/RemarkFormat.h" 14 #include "llvm/ADT/StringSwitch.h" 15 16 using namespace llvm; 17 using namespace llvm::remarks; 18 19 Expected<Format> llvm::remarks::parseFormat(StringRef FormatStr) { 20 auto Result = StringSwitch<Format>(FormatStr) 21 .Cases("", "yaml", Format::YAML) 22 .Default(Format::Unknown); 23 24 if (Result == Format::Unknown) 25 return createStringError(std::make_error_code(std::errc::invalid_argument), 26 "Unknown remark serializer format: '%s'", 27 FormatStr.data()); 28 29 return Result; 30 } 31