Francis Visoiu Mistrih | b8a847c | 2019-03-06 15:20:13 +0000 | [diff] [blame] | 1 | //===- 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 | |
| 16 | using namespace llvm; |
| 17 | |
| 18 | RemarkStreamer::RemarkStreamer(StringRef Filename, raw_ostream &OS) |
| 19 | : Filename(Filename), OS(OS), |
Francis Visoiu Mistrih | 7fee2b8 | 2019-04-24 00:06:24 +0000 | [diff] [blame] | 20 | YAMLOutput(OS, reinterpret_cast<void *>(this)), StrTab() { |
Francis Visoiu Mistrih | b8a847c | 2019-03-06 15:20:13 +0000 | [diff] [blame] | 21 | assert(!Filename.empty() && "This needs to be a real filename."); |
| 22 | } |
| 23 | |
Francis Visoiu Mistrih | dd42236 | 2019-03-12 21:22:27 +0000 | [diff] [blame] | 24 | Error 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 Mistrih | b8a847c | 2019-03-06 15:20:13 +0000 | [diff] [blame] | 34 | void RemarkStreamer::emit(const DiagnosticInfoOptimizationBase &Diag) { |
Francis Visoiu Mistrih | dd42236 | 2019-03-12 21:22:27 +0000 | [diff] [blame] | 35 | if (Optional<Regex> &Filter = PassFilter) |
| 36 | if (!Filter->match(Diag.getPassName())) |
| 37 | return; |
| 38 | |
Francis Visoiu Mistrih | b8a847c | 2019-03-06 15:20:13 +0000 | [diff] [blame] | 39 | DiagnosticInfoOptimizationBase *DiagPtr = |
| 40 | const_cast<DiagnosticInfoOptimizationBase *>(&Diag); |
| 41 | YAMLOutput << DiagPtr; |
| 42 | } |