diff options
Diffstat (limited to 'include/llvm/Remarks/RemarkSerializer.h')
-rw-r--r-- | include/llvm/Remarks/RemarkSerializer.h | 70 |
1 files changed, 45 insertions, 25 deletions
diff --git a/include/llvm/Remarks/RemarkSerializer.h b/include/llvm/Remarks/RemarkSerializer.h index def5c2e16620..35752cd5f6fb 100644 --- a/include/llvm/Remarks/RemarkSerializer.h +++ b/include/llvm/Remarks/RemarkSerializer.h @@ -14,54 +14,74 @@ #define LLVM_REMARKS_REMARK_SERIALIZER_H #include "llvm/Remarks/Remark.h" +#include "llvm/Remarks/RemarkFormat.h" #include "llvm/Remarks/RemarkStringTable.h" -#include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" namespace llvm { namespace remarks { +enum class SerializerMode { + Separate, // A mode where the metadata is serialized separately from the + // remarks. Typically, this is used when the remarks need to be + // streamed to a side file and the metadata is embedded into the + // final result of the compilation. + Standalone // A mode where everything can be retrieved in the same + // file/buffer. Typically, this is used for storing remarks for + // later use. +}; + +struct MetaSerializer; + /// This is the base class for a remark serializer. /// It includes support for using a string table while emitting. -struct Serializer { +struct RemarkSerializer { + /// The format of the serializer. + Format SerializerFormat; /// The open raw_ostream that the remark diagnostics are emitted to. raw_ostream &OS; + /// The serialization mode. + SerializerMode Mode; /// The string table containing all the unique strings used in the output. /// The table can be serialized to be consumed after the compilation. Optional<StringTable> StrTab; - Serializer(raw_ostream &OS) : OS(OS), StrTab() {} + RemarkSerializer(Format SerializerFormat, raw_ostream &OS, + SerializerMode Mode) + : SerializerFormat(SerializerFormat), OS(OS), Mode(Mode), StrTab() {} /// This is just an interface. - virtual ~Serializer() = default; + virtual ~RemarkSerializer() = default; + /// Emit a remark to the stream. virtual void emit(const Remark &Remark) = 0; + /// Return the corresponding metadata serializer. + virtual std::unique_ptr<MetaSerializer> + metaSerializer(raw_ostream &OS, + Optional<StringRef> ExternalFilename = None) = 0; }; -/// Wether the serializer should use a string table while emitting. -enum class UseStringTable { No, Yes }; - -/// Serialize the remarks to YAML. One remark entry looks like this: -/// --- !<TYPE> -/// Pass: <PASSNAME> -/// Name: <REMARKNAME> -/// DebugLoc: { File: <SOURCEFILENAME>, Line: <SOURCELINE>, -/// Column: <SOURCECOLUMN> } -/// Function: <FUNCTIONNAME> -/// Args: -/// - <KEY>: <VALUE> -/// DebugLoc: { File: <FILE>, Line: <LINE>, Column: <COL> } -/// ... -struct YAMLSerializer : public Serializer { - /// The YAML streamer. - yaml::Output YAMLOutput; +/// This is the base class for a remark metadata serializer. +struct MetaSerializer { + /// The open raw_ostream that the metadata is emitted to. + raw_ostream &OS; - YAMLSerializer(raw_ostream &OS, - UseStringTable UseStringTable = remarks::UseStringTable::No); + MetaSerializer(raw_ostream &OS) : OS(OS) {} - /// Emit a remark to the stream. - void emit(const Remark &Remark) override; + /// This is just an interface. + virtual ~MetaSerializer() = default; + virtual void emit() = 0; }; +/// Create a remark serializer. +Expected<std::unique_ptr<RemarkSerializer>> +createRemarkSerializer(Format RemarksFormat, SerializerMode Mode, + raw_ostream &OS); + +/// Create a remark serializer that uses a pre-filled string table. +Expected<std::unique_ptr<RemarkSerializer>> +createRemarkSerializer(Format RemarksFormat, SerializerMode Mode, + raw_ostream &OS, remarks::StringTable StrTab); + } // end namespace remarks } // end namespace llvm |