blob: d2a4ed4adf49c0e1f19c7b18511cfc414bc66d2c [file] [log] [blame]
Francis Visoiu Mistrihb8a847c2019-03-06 15:20:13 +00001//===- llvm/IR/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 remark outputting as part of
10// LLVMContext.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/IR/RemarkStreamer.h"
15
16using namespace llvm;
17
18RemarkStreamer::RemarkStreamer(StringRef Filename, raw_ostream &OS)
19 : Filename(Filename), OS(OS),
Francis Visoiu Mistrih7fee2b82019-04-24 00:06:24 +000020 YAMLOutput(OS, reinterpret_cast<void *>(this)), StrTab() {
Francis Visoiu Mistrihb8a847c2019-03-06 15:20:13 +000021 assert(!Filename.empty() && "This needs to be a real filename.");
22}
23
Francis Visoiu Mistrihdd422362019-03-12 21:22:27 +000024Error RemarkStreamer::setFilter(StringRef Filter) {
25 Regex R = Regex(Filter);
26 std::string RegexError;
27 if (!R.isValid(RegexError))
28 return createStringError(std::make_error_code(std::errc::invalid_argument),
29 RegexError.data());
30 PassFilter = std::move(R);
31 return Error::success();
32}
33
Francis Visoiu Mistrihb8a847c2019-03-06 15:20:13 +000034void RemarkStreamer::emit(const DiagnosticInfoOptimizationBase &Diag) {
Francis Visoiu Mistrihdd422362019-03-12 21:22:27 +000035 if (Optional<Regex> &Filter = PassFilter)
36 if (!Filter->match(Diag.getPassName()))
37 return;
38
Francis Visoiu Mistrihb8a847c2019-03-06 15:20:13 +000039 DiagnosticInfoOptimizationBase *DiagPtr =
40 const_cast<DiagnosticInfoOptimizationBase *>(&Diag);
41 YAMLOutput << DiagPtr;
42}