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#include "llvm/Remarks/BitstreamRemarkContainer.h"
16
17using namespace llvm;
18using namespace llvm::remarks;
19
20Expected<Format> llvm::remarks::parseFormat(StringRef FormatStr) {
21 auto Result = StringSwitch<Format>(FormatStr)
22 .Cases(S0: "", S1: "yaml", Value: Format::YAML)
23 .Case(S: "yaml-strtab", Value: Format::YAMLStrTab)
24 .Case(S: "bitstream", Value: Format::Bitstream)
25 .Default(Value: Format::Unknown);
26
27 if (Result == Format::Unknown)
28 return createStringError(EC: std::make_error_code(e: std::errc::invalid_argument),
29 Fmt: "Unknown remark format: '%s'",
30 Vals: FormatStr.data());
31
32 return Result;
33}
34
35Expected<Format> llvm::remarks::magicToFormat(StringRef MagicStr) {
36 auto Result =
37 StringSwitch<Format>(MagicStr)
38 .StartsWith(S: "--- ", Value: Format::YAML) // This is only an assumption.
39 .StartsWith(S: remarks::Magic, Value: Format::YAMLStrTab)
40 .StartsWith(S: remarks::ContainerMagic, Value: Format::Bitstream)
41 .Default(Value: Format::Unknown);
42
43 if (Result == Format::Unknown)
44 return createStringError(EC: std::make_error_code(e: std::errc::invalid_argument),
45 Fmt: "Unknown remark magic: '%s'", Vals: MagicStr.data());
46 return Result;
47}
48

source code of llvm/lib/Remarks/RemarkFormat.cpp