LLVM  17.0.0git
YAMLRemarkSerializer.h
Go to the documentation of this file.
1 //===-- YAMLRemarkSerializer.h - YAML Remark serialization ---*- C++ -*-===//
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 // This file provides an interface for serializing remarks to YAML.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_REMARKS_YAMLREMARKSERIALIZER_H
14 #define LLVM_REMARKS_YAMLREMARKSERIALIZER_H
15 
18 #include <optional>
19 
20 namespace llvm {
21 namespace remarks {
22 
23 /// Serialize the remarks to YAML. One remark entry looks like this:
24 /// --- !<TYPE>
25 /// Pass: <PASSNAME>
26 /// Name: <REMARKNAME>
27 /// DebugLoc: { File: <SOURCEFILENAME>, Line: <SOURCELINE>,
28 /// Column: <SOURCECOLUMN> }
29 /// Function: <FUNCTIONNAME>
30 /// Args:
31 /// - <KEY>: <VALUE>
32 /// DebugLoc: { File: <FILE>, Line: <LINE>, Column: <COL> }
33 /// ...
35  /// The YAML streamer.
36  yaml::Output YAMLOutput;
37 
39  std::optional<StringTable> StrTab = std::nullopt);
40 
41  void emit(const Remark &Remark) override;
42  std::unique_ptr<MetaSerializer> metaSerializer(
43  raw_ostream &OS,
44  std::optional<StringRef> ExternalFilename = std::nullopt) override;
45 
46  static bool classof(const RemarkSerializer *S) {
47  return S->SerializerFormat == Format::YAML;
48  }
49 
50 protected:
53  std::optional<StringTable> StrTab = std::nullopt);
54 };
55 
57  std::optional<StringRef> ExternalFilename;
58 
59  YAMLMetaSerializer(raw_ostream &OS, std::optional<StringRef> ExternalFilename)
61 
62  void emit() override;
63 };
64 
65 /// Serialize the remarks to YAML using a string table. An remark entry looks
66 /// like the regular YAML remark but instead of string entries it's using
67 /// numbers that map to an index in the string table.
69  /// Wether we already emitted the metadata in standalone mode.
70  /// This should be set to true after the first invocation of `emit`.
71  bool DidEmitMeta = false;
72 
75  // We always need a string table for this type of serializer.
76  StrTab.emplace();
77  }
81 
82  /// Override to emit the metadata if necessary.
83  void emit(const Remark &Remark) override;
84 
85  std::unique_ptr<MetaSerializer> metaSerializer(
86  raw_ostream &OS,
87  std::optional<StringRef> ExternalFilename = std::nullopt) override;
88 
89  static bool classof(const RemarkSerializer *S) {
90  return S->SerializerFormat == Format::YAMLStrTab;
91  }
92 };
93 
95  /// The string table is part of the metadata.
97 
99  std::optional<StringRef> ExternalFilename,
100  const StringTable &StrTab)
102 
103  void emit() override;
104 };
105 
106 } // end namespace remarks
107 } // end namespace llvm
108 
109 #endif // LLVM_REMARKS_YAMLREMARKSERIALIZER_H
llvm::remarks::SerializerMode
SerializerMode
Definition: RemarkSerializer.h:28
llvm::remarks::YAMLRemarkSerializer::classof
static bool classof(const RemarkSerializer *S)
Definition: YAMLRemarkSerializer.h:46
llvm::remarks::YAMLStrTabRemarkSerializer::metaSerializer
std::unique_ptr< MetaSerializer > metaSerializer(raw_ostream &OS, std::optional< StringRef > ExternalFilename=std::nullopt) override
Return the corresponding metadata serializer.
Definition: YAMLRemarkSerializer.cpp:198
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::remarks::StringTable
The string table used for serializing remarks.
Definition: RemarkStringTable.h:36
llvm::remarks::YAMLStrTabRemarkSerializer::DidEmitMeta
bool DidEmitMeta
Wether we already emitted the metadata in standalone mode.
Definition: YAMLRemarkSerializer.h:71
llvm::remarks::YAMLRemarkSerializer::YAMLOutput
yaml::Output YAMLOutput
The YAML streamer.
Definition: YAMLRemarkSerializer.h:36
llvm::remarks::RemarkSerializer::OS
raw_ostream & OS
The open raw_ostream that the remark diagnostics are emitted to.
Definition: RemarkSerializer.h:46
llvm::remarks::RemarkSerializer::SerializerFormat
Format SerializerFormat
The format of the serializer.
Definition: RemarkSerializer.h:44
llvm::remarks::RemarkSerializer::Mode
SerializerMode Mode
The serialization mode.
Definition: RemarkSerializer.h:48
llvm::remarks::YAMLStrTabMetaSerializer::emit
void emit() override
Definition: YAMLRemarkSerializer.cpp:250
llvm::remarks::YAMLStrTabMetaSerializer::YAMLStrTabMetaSerializer
YAMLStrTabMetaSerializer(raw_ostream &OS, std::optional< StringRef > ExternalFilename, const StringTable &StrTab)
Definition: YAMLRemarkSerializer.h:98
llvm::remarks::YAMLMetaSerializer::ExternalFilename
std::optional< StringRef > ExternalFilename
Definition: YAMLRemarkSerializer.h:57
llvm::remarks::YAMLRemarkSerializer::YAMLRemarkSerializer
YAMLRemarkSerializer(raw_ostream &OS, SerializerMode Mode, std::optional< StringTable > StrTab=std::nullopt)
Definition: YAMLRemarkSerializer.cpp:160
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::remarks::Remark
A remark type used for both emission and parsing.
Definition: Remark.h:67
llvm::remarks::RemarkSerializer
This is the base class for a remark serializer.
Definition: RemarkSerializer.h:42
llvm::remarks::YAMLMetaSerializer::emit
void emit() override
Definition: YAMLRemarkSerializer.cpp:242
llvm::remarks::YAMLRemarkSerializer::metaSerializer
std::unique_ptr< MetaSerializer > metaSerializer(raw_ostream &OS, std::optional< StringRef > ExternalFilename=std::nullopt) override
Return the corresponding metadata serializer.
Definition: YAMLRemarkSerializer.cpp:179
llvm::remarks::Format::YAML
@ YAML
llvm::remarks::Format::YAMLStrTab
@ YAMLStrTab
llvm::remarks::YAMLStrTabRemarkSerializer::YAMLStrTabRemarkSerializer
YAMLStrTabRemarkSerializer(raw_ostream &OS, SerializerMode Mode)
Definition: YAMLRemarkSerializer.h:73
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1862
llvm::remarks::YAMLStrTabRemarkSerializer::classof
static bool classof(const RemarkSerializer *S)
Definition: YAMLRemarkSerializer.h:89
llvm::remarks::MetaSerializer::OS
raw_ostream & OS
The open raw_ostream that the metadata is emitted to.
Definition: RemarkSerializer.h:70
llvm::remarks::YAMLStrTabMetaSerializer::StrTab
const StringTable & StrTab
The string table is part of the metadata.
Definition: YAMLRemarkSerializer.h:96
YAMLTraits.h
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::remarks::YAMLStrTabRemarkSerializer::emit
void emit(const Remark &Remark) override
Override to emit the metadata if necessary.
Definition: YAMLRemarkSerializer.cpp:184
llvm::remarks::MetaSerializer
This is the base class for a remark metadata serializer.
Definition: RemarkSerializer.h:68
std
Definition: BitVector.h:851
llvm::remarks::YAMLMetaSerializer::YAMLMetaSerializer
YAMLMetaSerializer(raw_ostream &OS, std::optional< StringRef > ExternalFilename)
Definition: YAMLRemarkSerializer.h:59
llvm::remarks::YAMLStrTabMetaSerializer
Definition: YAMLRemarkSerializer.h:94
llvm::remarks::YAMLRemarkSerializer::emit
void emit(const Remark &Remark) override
Emit a remark to the stream.
Definition: YAMLRemarkSerializer.cpp:172
llvm::remarks::YAMLRemarkSerializer
Serialize the remarks to YAML.
Definition: YAMLRemarkSerializer.h:34
llvm::remarks::YAMLStrTabRemarkSerializer::YAMLStrTabRemarkSerializer
YAMLStrTabRemarkSerializer(raw_ostream &OS, SerializerMode Mode, StringTable StrTab)
Definition: YAMLRemarkSerializer.h:78
llvm::remarks::YAMLStrTabRemarkSerializer
Serialize the remarks to YAML using a string table.
Definition: YAMLRemarkSerializer.h:68
llvm::remarks::YAMLMetaSerializer
Definition: YAMLRemarkSerializer.h:56
RemarkSerializer.h
llvm::remarks::RemarkSerializer::StrTab
std::optional< StringTable > StrTab
The string table containing all the unique strings used in the output.
Definition: RemarkSerializer.h:51
llvm::remarks::Format
Format
The format used for serializing/deserializing remarks.
Definition: RemarkFormat.h:25