Path: blob/main/contrib/llvm-project/llvm/lib/Remarks/RemarkStreamer.cpp
35262 views
//===- llvm/Remarks/RemarkStreamer.cpp - Remark Streamer -*- C++ --------*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains the implementation of the main remark streamer.9//10//===----------------------------------------------------------------------===//1112#include "llvm/Remarks/RemarkStreamer.h"13#include "llvm/Support/CommandLine.h"14#include <optional>1516using namespace llvm;17using namespace llvm::remarks;1819static cl::opt<cl::boolOrDefault> EnableRemarksSection(20"remarks-section",21cl::desc(22"Emit a section containing remark diagnostics metadata. By default, "23"this is enabled for the following formats: yaml-strtab, bitstream."),24cl::init(cl::BOU_UNSET), cl::Hidden);2526RemarkStreamer::RemarkStreamer(27std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer,28std::optional<StringRef> FilenameIn)29: RemarkSerializer(std::move(RemarkSerializer)),30Filename(FilenameIn ? std::optional<std::string>(FilenameIn->str())31: std::nullopt) {}3233Error RemarkStreamer::setFilter(StringRef Filter) {34Regex R = Regex(Filter);35std::string RegexError;36if (!R.isValid(RegexError))37return createStringError(std::make_error_code(std::errc::invalid_argument),38RegexError.data());39PassFilter = std::move(R);40return Error::success();41}4243bool RemarkStreamer::matchesFilter(StringRef Str) {44if (PassFilter)45return PassFilter->match(Str);46// No filter means all strings pass.47return true;48}4950bool RemarkStreamer::needsSection() const {51if (EnableRemarksSection == cl::BOU_TRUE)52return true;5354if (EnableRemarksSection == cl::BOU_FALSE)55return false;5657assert(EnableRemarksSection == cl::BOU_UNSET);5859// We only need a section if we're in separate mode.60if (RemarkSerializer->Mode != remarks::SerializerMode::Separate)61return false;6263// Only some formats need a section:64// * bitstream65// * yaml-strtab66switch (RemarkSerializer->SerializerFormat) {67case remarks::Format::YAMLStrTab:68case remarks::Format::Bitstream:69return true;70default:71return false;72}73}747576