LLVM  9.0.0svn
RemarkSerializer.h
Go to the documentation of this file.
1 //===-- RemarkSerializer.h - Remark serialization interface -----*- 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 different formats.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_REMARKS_REMARK_SERIALIZER_H
14 #define LLVM_REMARKS_REMARK_SERIALIZER_H
15 
16 #include "llvm/Remarks/Remark.h"
20 
21 namespace llvm {
22 namespace remarks {
23 
24 /// This is the base class for a remark serializer.
25 /// It includes support for using a string table while emitting.
26 struct Serializer {
27  /// The open raw_ostream that the remark diagnostics are emitted to.
29  /// The string table containing all the unique strings used in the output.
30  /// The table can be serialized to be consumed after the compilation.
32 
33  Serializer(raw_ostream &OS) : OS(OS), StrTab() {}
34 
35  /// This is just an interface.
36  virtual ~Serializer() = default;
37  virtual void emit(const Remark &Remark) = 0;
38 };
39 
40 /// Wether the serializer should use a string table while emitting.
41 enum class UseStringTable { No, Yes };
42 
43 /// Serialize the remarks to YAML. One remark entry looks like this:
44 /// --- !<TYPE>
45 /// Pass: <PASSNAME>
46 /// Name: <REMARKNAME>
47 /// DebugLoc: { File: <SOURCEFILENAME>, Line: <SOURCELINE>,
48 /// Column: <SOURCECOLUMN> }
49 /// Function: <FUNCTIONNAME>
50 /// Args:
51 /// - <KEY>: <VALUE>
52 /// DebugLoc: { File: <FILE>, Line: <LINE>, Column: <COL> }
53 /// ...
54 struct YAMLSerializer : public Serializer {
55  /// The YAML streamer.
56  yaml::Output YAMLOutput;
57 
60 
61  /// Emit a remark to the stream.
62  void emit(const Remark &Remark) override;
63 };
64 
65 } // end namespace remarks
66 } // end namespace llvm
67 
68 #endif /* LLVM_REMARKS_REMARK_SERIALIZER_H */
virtual void emit(const Remark &Remark)=0
raw_ostream & OS
The open raw_ostream that the remark diagnostics are emitted to.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
UseStringTable
Wether the serializer should use a string table while emitting.
yaml::Output YAMLOutput
The YAML streamer.
virtual ~Serializer()=default
This is just an interface.
A remark type used for both emission and parsing.
Definition: Remark.h:66
Optional< StringTable > StrTab
The string table containing all the unique strings used in the output.
Serialize the remarks to YAML.
This is the base class for a remark serializer.
Serializer(raw_ostream &OS)
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45