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
16using namespace llvm;
17using namespace llvm::vfs;
18
19void OutputError::anchor() {}
20void OutputConfigError::anchor() {}
21void TempFileOutputError::anchor() {}
22
23char OutputError::ID = 0;
24char OutputConfigError::ID = 0;
25char TempFileOutputError::ID = 0;
26
27void OutputError::log(raw_ostream &OS) const {
28 OS << getOutputPath() << ": ";
29 ECError::log(OS);
30}
31
32void OutputConfigError::log(raw_ostream &OS) const {
33 OutputError::log(OS);
34 OS << ": " << Config;
35}
36
37void TempFileOutputError::log(raw_ostream &OS) const {
38 OS << getTempPath() << " => ";
39 OutputError::log(OS);
40}
41
42namespace {
43class OutputErrorCategory : public std::error_category {
44public:
45 const char *name() const noexcept override;
46 std::string message(int EV) const override;
47};
48} // end namespace
49
50const std::error_category &vfs::output_category() {
51 static OutputErrorCategory ErrorCategory;
52 return ErrorCategory;
53}
54
55const char *OutputErrorCategory::name() const noexcept {
56 return "llvm.vfs.output";
57}
58
59std::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