1 //===- MSFError.cpp - Error extensions for MSF files ------------*- 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 #include "llvm/DebugInfo/MSF/MSFError.h"
10 #include "llvm/Support/ErrorHandling.h"
11 #include "llvm/Support/ManagedStatic.h"
12 #include <string>
13 
14 using namespace llvm;
15 using namespace llvm::msf;
16 
17 namespace {
18 // FIXME: This class is only here to support the transition to llvm::Error. It
19 // will be removed once this transition is complete. Clients should prefer to
20 // deal with the Error value directly, rather than converting to error_code.
21 class MSFErrorCategory : public std::error_category {
22 public:
23   const char *name() const noexcept override { return "llvm.msf"; }
24   std::string message(int Condition) const override {
25     switch (static_cast<msf_error_code>(Condition)) {
26     case msf_error_code::unspecified:
27       return "An unknown error has occurred.";
28     case msf_error_code::insufficient_buffer:
29       return "The buffer is not large enough to read the requested number of "
30              "bytes.";
31     case msf_error_code::size_overflow_4096:
32       return "Output data is larger than 4 GiB.";
33     case msf_error_code::size_overflow_8192:
34       return "Output data is larger than 8 GiB.";
35     case msf_error_code::size_overflow_16384:
36       return "Output data is larger than 16 GiB.";
37     case msf_error_code::size_overflow_32768:
38       return "Output data is larger than 32 GiB.";
39     case msf_error_code::not_writable:
40       return "The specified stream is not writable.";
41     case msf_error_code::no_stream:
42       return "The specified stream does not exist.";
43     case msf_error_code::invalid_format:
44       return "The data is in an unexpected format.";
45     case msf_error_code::block_in_use:
46       return "The block is already in use.";
47     }
48     llvm_unreachable("Unrecognized msf_error_code");
49   }
50 };
51 } // namespace
52 
53 static llvm::ManagedStatic<MSFErrorCategory> MSFCategory;
54 const std::error_category &llvm::msf::MSFErrCategory() { return *MSFCategory; }
55 
56 char MSFError::ID;
57