[WebAssembly] Add new target feature in support of 'extended-const' proposal
[llvm-project.git] / llvm / lib / Remarks / RemarkStreamer.cpp
blob543b00723659e22c6b49c9146d480b60f6c328e9
1 //===- llvm/Remarks/RemarkStreamer.cpp - Remark Streamer -*- 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 contains the implementation of the main remark streamer.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Remarks/RemarkStreamer.h"
14 #include "llvm/Support/CommandLine.h"
16 using namespace llvm;
17 using namespace llvm::remarks;
19 static cl::opt<cl::boolOrDefault> EnableRemarksSection(
20 "remarks-section",
21 cl::desc(
22 "Emit a section containing remark diagnostics metadata. By default, "
23 "this is enabled for the following formats: yaml-strtab, bitstream."),
24 cl::init(cl::BOU_UNSET), cl::Hidden);
26 RemarkStreamer::RemarkStreamer(
27 std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer,
28 Optional<StringRef> FilenameIn)
29 : RemarkSerializer(std::move(RemarkSerializer)),
30 Filename(FilenameIn ? Optional<std::string>(FilenameIn->str()) : None) {}
32 Error RemarkStreamer::setFilter(StringRef Filter) {
33 Regex R = Regex(Filter);
34 std::string RegexError;
35 if (!R.isValid(RegexError))
36 return createStringError(std::make_error_code(std::errc::invalid_argument),
37 RegexError.data());
38 PassFilter = std::move(R);
39 return Error::success();
42 bool RemarkStreamer::matchesFilter(StringRef Str) {
43 if (PassFilter)
44 return PassFilter->match(Str);
45 // No filter means all strings pass.
46 return true;
49 bool RemarkStreamer::needsSection() const {
50 if (EnableRemarksSection == cl::BOU_TRUE)
51 return true;
53 if (EnableRemarksSection == cl::BOU_FALSE)
54 return false;
56 assert(EnableRemarksSection == cl::BOU_UNSET);
58 // We only need a section if we're in separate mode.
59 if (RemarkSerializer->Mode != remarks::SerializerMode::Separate)
60 return false;
62 // Only some formats need a section:
63 // * bitstream
64 // * yaml-strtab
65 switch (RemarkSerializer->SerializerFormat) {
66 case remarks::Format::YAMLStrTab:
67 case remarks::Format::Bitstream:
68 return true;
69 default:
70 return false;