summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/RemarkStreamer.cpp
blob: 022c17d6722bf61b1450aaed065e917ca27c8414 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//===- llvm/IR/RemarkStreamer.cpp - Remark Streamer -*- C++ -------------*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains the implementation of the remark outputting as part of
// LLVMContext.
//
//===----------------------------------------------------------------------===//

#include "llvm/IR/RemarkStreamer.h"

using namespace llvm;

RemarkStreamer::RemarkStreamer(StringRef Filename, raw_ostream &OS)
    : Filename(Filename), OS(OS),
      YAMLOutput(OS, reinterpret_cast<void *>(this)) {
  assert(!Filename.empty() && "This needs to be a real filename.");
}

Error RemarkStreamer::setFilter(StringRef Filter) {
  Regex R = Regex(Filter);
  std::string RegexError;
  if (!R.isValid(RegexError))
    return createStringError(std::make_error_code(std::errc::invalid_argument),
                             RegexError.data());
  PassFilter = std::move(R);
  return Error::success();
}

void RemarkStreamer::emit(const DiagnosticInfoOptimizationBase &Diag) {
  if (Optional<Regex> &Filter = PassFilter)
    if (!Filter->match(Diag.getPassName()))
      return;

  DiagnosticInfoOptimizationBase *DiagPtr =
      const_cast<DiagnosticInfoOptimizationBase *>(&Diag);
  YAMLOutput << DiagPtr;
}
OpenPOWER on IntegriCloud