[clang] Add test for CWG190 "Layout-compatible POD-struct types" (#121668)
[llvm-project.git] / llvm / lib / Remarks / RemarkFormat.cpp
blob5006421a3c638d24d2e56e1f663cef4a17265de3
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.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Remarks/RemarkFormat.h"
14 #include "llvm/ADT/StringSwitch.h"
15 #include "llvm/Remarks/BitstreamRemarkContainer.h"
17 using namespace llvm;
18 using namespace llvm::remarks;
20 Expected<Format> llvm::remarks::parseFormat(StringRef FormatStr) {
21 auto Result = StringSwitch<Format>(FormatStr)
22 .Cases("", "yaml", Format::YAML)
23 .Case("yaml-strtab", Format::YAMLStrTab)
24 .Case("bitstream", Format::Bitstream)
25 .Default(Format::Unknown);
27 if (Result == Format::Unknown)
28 return createStringError(std::make_error_code(std::errc::invalid_argument),
29 "Unknown remark format: '%s'",
30 FormatStr.data());
32 return Result;
35 Expected<Format> llvm::remarks::magicToFormat(StringRef MagicStr) {
36 auto Result =
37 StringSwitch<Format>(MagicStr)
38 .StartsWith("--- ", Format::YAML) // This is only an assumption.
39 .StartsWith(remarks::Magic, Format::YAMLStrTab)
40 .StartsWith(remarks::ContainerMagic, Format::Bitstream)
41 .Default(Format::Unknown);
43 if (Result == Format::Unknown)
44 return createStringError(std::make_error_code(std::errc::invalid_argument),
45 "Unknown remark magic: '%s'", MagicStr.data());
46 return Result;