LLVM 20.0.0git
RemarkFormat.cpp
Go to the documentation of this file.
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
16
17using namespace llvm;
18using namespace llvm::remarks;
19
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);
26
27 if (Result == Format::Unknown)
28 return createStringError(std::make_error_code(std::errc::invalid_argument),
29 "Unknown remark format: '%s'",
30 FormatStr.data());
31
32 return Result;
33}
34
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);
42
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;
47}
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Tagged union holding either a T or a Error.
Definition: Error.h:481
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:131
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
StringSwitch & StartsWith(StringLiteral S, T Value)
Definition: StringSwitch.h:83
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, T Value)
Definition: StringSwitch.h:90
Expected< Format > magicToFormat(StringRef Magic)
Parse and validate a magic number to a remark format.
constexpr StringLiteral Magic("REMARKS")
Expected< Format > parseFormat(StringRef FormatStr)
Parse and validate a string for the remark format.
constexpr StringLiteral ContainerMagic("RMRK")
The magic number used for identifying remark blocks.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1286