1*0b57cec5SDimitry Andric //===- MSFError.cpp - Error extensions for MSF files ------------*- C++ -*-===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric 
9*0b57cec5SDimitry Andric #include "llvm/DebugInfo/MSF/MSFError.h"
10*0b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h"
11*0b57cec5SDimitry Andric #include "llvm/Support/ManagedStatic.h"
12fe6060f1SDimitry Andric #include <string>
13*0b57cec5SDimitry Andric 
14*0b57cec5SDimitry Andric using namespace llvm;
15*0b57cec5SDimitry Andric using namespace llvm::msf;
16*0b57cec5SDimitry Andric 
17*0b57cec5SDimitry Andric namespace {
18*0b57cec5SDimitry Andric // FIXME: This class is only here to support the transition to llvm::Error. It
19*0b57cec5SDimitry Andric // will be removed once this transition is complete. Clients should prefer to
20*0b57cec5SDimitry Andric // deal with the Error value directly, rather than converting to error_code.
21*0b57cec5SDimitry Andric class MSFErrorCategory : public std::error_category {
22*0b57cec5SDimitry Andric public:
23*0b57cec5SDimitry Andric   const char *name() const noexcept override { return "llvm.msf"; }
24*0b57cec5SDimitry Andric   std::string message(int Condition) const override {
25*0b57cec5SDimitry Andric     switch (static_cast<msf_error_code>(Condition)) {
26*0b57cec5SDimitry Andric     case msf_error_code::unspecified:
27*0b57cec5SDimitry Andric       return "An unknown error has occurred.";
28*0b57cec5SDimitry Andric     case msf_error_code::insufficient_buffer:
29*0b57cec5SDimitry Andric       return "The buffer is not large enough to read the requested number of "
30*0b57cec5SDimitry Andric              "bytes.";
31fe6060f1SDimitry Andric     case msf_error_code::size_overflow:
32fe6060f1SDimitry Andric       return "Output data is larger than 4 GiB.";
33*0b57cec5SDimitry Andric     case msf_error_code::not_writable:
34*0b57cec5SDimitry Andric       return "The specified stream is not writable.";
35*0b57cec5SDimitry Andric     case msf_error_code::no_stream:
36*0b57cec5SDimitry Andric       return "The specified stream does not exist.";
37*0b57cec5SDimitry Andric     case msf_error_code::invalid_format:
38*0b57cec5SDimitry Andric       return "The data is in an unexpected format.";
39*0b57cec5SDimitry Andric     case msf_error_code::block_in_use:
40*0b57cec5SDimitry Andric       return "The block is already in use.";
41*0b57cec5SDimitry Andric     }
42*0b57cec5SDimitry Andric     llvm_unreachable("Unrecognized msf_error_code");
43*0b57cec5SDimitry Andric   }
44*0b57cec5SDimitry Andric };
45*0b57cec5SDimitry Andric } // namespace
46*0b57cec5SDimitry Andric 
47*0b57cec5SDimitry Andric static llvm::ManagedStatic<MSFErrorCategory> MSFCategory;
48*0b57cec5SDimitry Andric const std::error_category &llvm::msf::MSFErrCategory() { return *MSFCategory; }
49*0b57cec5SDimitry Andric 
50*0b57cec5SDimitry Andric char MSFError::ID;
51