LLVM 20.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
20namespace llvm {
21namespace 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(
44 std::optional<StringRef> ExternalFilename = std::nullopt) override;
45
46 static bool classof(const RemarkSerializer *S) {
47 return S->SerializerFormat == Format::YAML;
48 }
49
50protected:
53 std::optional<StringTable> StrTab = std::nullopt);
54};
55
57 std::optional<StringRef> ExternalFilename;
58
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(
87 std::optional<StringRef> ExternalFilename = std::nullopt) override;
88
89 static bool classof(const RemarkSerializer *S) {
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
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
Format
The format used for serializing/deserializing remarks.
Definition: RemarkFormat.h:25
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:1856
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
This is the base class for a remark metadata serializer.
raw_ostream & OS
The open raw_ostream that the metadata is emitted to.
This is the base class for a remark serializer.
Format SerializerFormat
The format of the serializer.
SerializerMode Mode
The serialization mode.
std::optional< StringTable > StrTab
The string table containing all the unique strings used in the output.
raw_ostream & OS
The open raw_ostream that the remark diagnostics are emitted to.
A remark type used for both emission and parsing.
Definition: Remark.h:97
The string table used for serializing remarks.
std::optional< StringRef > ExternalFilename
YAMLMetaSerializer(raw_ostream &OS, std::optional< StringRef > ExternalFilename)
Serialize the remarks to YAML.
std::unique_ptr< MetaSerializer > metaSerializer(raw_ostream &OS, std::optional< StringRef > ExternalFilename=std::nullopt) override
Return the corresponding metadata serializer.
static bool classof(const RemarkSerializer *S)
void emit(const Remark &Remark) override
Emit a remark to the stream.
yaml::Output YAMLOutput
The YAML streamer.
YAMLStrTabMetaSerializer(raw_ostream &OS, std::optional< StringRef > ExternalFilename, const StringTable &StrTab)
const StringTable & StrTab
The string table is part of the metadata.
Serialize the remarks to YAML using a string table.
static bool classof(const RemarkSerializer *S)
YAMLStrTabRemarkSerializer(raw_ostream &OS, SerializerMode Mode, StringTable StrTab)
YAMLStrTabRemarkSerializer(raw_ostream &OS, SerializerMode Mode)
std::unique_ptr< MetaSerializer > metaSerializer(raw_ostream &OS, std::optional< StringRef > ExternalFilename=std::nullopt) override
Return the corresponding metadata serializer.
void emit(const Remark &Remark) override
Override to emit the metadata if necessary.
bool DidEmitMeta
Wether we already emitted the metadata in standalone mode.