| 1 | //===----------------------------------------------------------------------===// |
|---|---|
| 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 | /// \file |
| 10 | /// This file implements the errors for output virtualization. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/Support/VirtualOutputError.h" |
| 15 | |
| 16 | using namespace llvm; |
| 17 | using namespace llvm::vfs; |
| 18 | |
| 19 | void OutputError::anchor() {} |
| 20 | void OutputConfigError::anchor() {} |
| 21 | void TempFileOutputError::anchor() {} |
| 22 | |
| 23 | char OutputError::ID = 0; |
| 24 | char OutputConfigError::ID = 0; |
| 25 | char TempFileOutputError::ID = 0; |
| 26 | |
| 27 | void OutputError::log(raw_ostream &OS) const { |
| 28 | OS << getOutputPath() << ": "; |
| 29 | ECError::log(OS); |
| 30 | } |
| 31 | |
| 32 | void OutputConfigError::log(raw_ostream &OS) const { |
| 33 | OutputError::log(OS); |
| 34 | OS << ": "<< Config; |
| 35 | } |
| 36 | |
| 37 | void TempFileOutputError::log(raw_ostream &OS) const { |
| 38 | OS << getTempPath() << " => "; |
| 39 | OutputError::log(OS); |
| 40 | } |
| 41 | |
| 42 | namespace { |
| 43 | class OutputErrorCategory : public std::error_category { |
| 44 | public: |
| 45 | const char *name() const noexcept override; |
| 46 | std::string message(int EV) const override; |
| 47 | }; |
| 48 | } // end namespace |
| 49 | |
| 50 | const std::error_category &vfs::output_category() { |
| 51 | static OutputErrorCategory ErrorCategory; |
| 52 | return ErrorCategory; |
| 53 | } |
| 54 | |
| 55 | const char *OutputErrorCategory::name() const noexcept { |
| 56 | return "llvm.vfs.output"; |
| 57 | } |
| 58 | |
| 59 | std::string OutputErrorCategory::message(int EV) const { |
| 60 | OutputErrorCode E = static_cast<OutputErrorCode>(EV); |
| 61 | switch (E) { |
| 62 | case OutputErrorCode::invalid_config: |
| 63 | return "invalid config"; |
| 64 | case OutputErrorCode::not_closed: |
| 65 | return "output not closed"; |
| 66 | case OutputErrorCode::already_closed: |
| 67 | return "output already closed"; |
| 68 | case OutputErrorCode::has_open_proxy: |
| 69 | return "output has open proxy"; |
| 70 | } |
| 71 | llvm_unreachable( |
| 72 | "An enumerator of OutputErrorCode does not have a message defined."); |
| 73 | } |
| 74 |