1 //===- llvm/Remarks/RemarkStreamer.cpp - Remark Streamer -*- C++ --------*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file contains the implementation of the main remark streamer.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Remarks/RemarkStreamer.h"
14 #include "llvm/Support/CommandLine.h"
18 using namespace llvm::remarks
;
20 static cl::opt
<cl::boolOrDefault
> EnableRemarksSection(
23 "Emit a section containing remark diagnostics metadata. By default, "
24 "this is enabled for the following formats: yaml-strtab, bitstream."),
25 cl::init(cl::BOU_UNSET
), cl::Hidden
);
27 RemarkStreamer::RemarkStreamer(
28 std::unique_ptr
<remarks::RemarkSerializer
> RemarkSerializer
,
29 std::optional
<StringRef
> FilenameIn
)
30 : RemarkSerializer(std::move(RemarkSerializer
)),
31 Filename(FilenameIn
? std::optional
<std::string
>(FilenameIn
->str())
34 Error
RemarkStreamer::setFilter(StringRef Filter
) {
35 Regex R
= Regex(Filter
);
36 std::string RegexError
;
37 if (!R
.isValid(RegexError
))
38 return createStringError(std::make_error_code(std::errc::invalid_argument
),
40 PassFilter
= std::move(R
);
41 return Error::success();
44 bool RemarkStreamer::matchesFilter(StringRef Str
) {
46 return PassFilter
->match(Str
);
47 // No filter means all strings pass.
51 bool RemarkStreamer::needsSection() const {
52 if (EnableRemarksSection
== cl::BOU_TRUE
)
55 if (EnableRemarksSection
== cl::BOU_FALSE
)
58 assert(EnableRemarksSection
== cl::BOU_UNSET
);
60 // We only need a section if we're in separate mode.
61 if (RemarkSerializer
->Mode
!= remarks::SerializerMode::Separate
)
64 // Only some formats need a section:
67 switch (RemarkSerializer
->SerializerFormat
) {
68 case remarks::Format::YAMLStrTab
:
69 case remarks::Format::Bitstream
: