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 .Case("yaml-strtab", Format::YAMLStrTab) 23 .Case("bitstream", Format::Bitstream) 24 .Default(Format::Unknown); 25 26 if (Result == Format::Unknown) 27 return createStringError(std::make_error_code(std::errc::invalid_argument), 28 "Unknown remark format: '%s'", 29 FormatStr.data()); 30 31 return Result; 32 } 33