1d5d37dcfSZachary Turner //===- CodeViewError.cpp - Error extensions for CodeView --------*- C++ -*-===//
2d5d37dcfSZachary Turner //
3d5d37dcfSZachary Turner //                     The LLVM Compiler Infrastructure
4d5d37dcfSZachary Turner //
5d5d37dcfSZachary Turner // This file is distributed under the University of Illinois Open Source
6d5d37dcfSZachary Turner // License. See LICENSE.TXT for details.
7d5d37dcfSZachary Turner //
8d5d37dcfSZachary Turner //===----------------------------------------------------------------------===//
9d5d37dcfSZachary Turner 
10d5d37dcfSZachary Turner #include "llvm/DebugInfo/CodeView/CodeViewError.h"
11d5d37dcfSZachary Turner #include "llvm/Support/ErrorHandling.h"
12d5d37dcfSZachary Turner #include "llvm/Support/ManagedStatic.h"
13d5d37dcfSZachary Turner 
14d5d37dcfSZachary Turner using namespace llvm;
15d5d37dcfSZachary Turner using namespace llvm::codeview;
16d5d37dcfSZachary Turner 
17d5d37dcfSZachary Turner // FIXME: This class is only here to support the transition to llvm::Error. It
18d5d37dcfSZachary Turner // will be removed once this transition is complete. Clients should prefer to
19d5d37dcfSZachary Turner // deal with the Error value directly, rather than converting to error_code.
20d5d37dcfSZachary Turner class CodeViewErrorCategory : public std::error_category {
21d5d37dcfSZachary Turner public:
22990504e6SReid Kleckner   const char *name() const noexcept override { return "llvm.codeview"; }
23d5d37dcfSZachary Turner   std::string message(int Condition) const override {
24d5d37dcfSZachary Turner     switch (static_cast<cv_error_code>(Condition)) {
25d5d37dcfSZachary Turner     case cv_error_code::unspecified:
266a7efef4SAlexandre Ganea       return "An unknown CodeView error has occurred.";
27d5d37dcfSZachary Turner     case cv_error_code::insufficient_buffer:
28d5d37dcfSZachary Turner       return "The buffer is not large enough to read the requested number of "
29d5d37dcfSZachary Turner              "bytes.";
30d5d37dcfSZachary Turner     case cv_error_code::corrupt_record:
31d5d37dcfSZachary Turner       return "The CodeView record is corrupted.";
327b327d05SZachary Turner     case cv_error_code::no_records:
336a7efef4SAlexandre Ganea       return "There are no records.";
345acb4ac6SZachary Turner     case cv_error_code::operation_unsupported:
355acb4ac6SZachary Turner       return "The requested operation is not supported.";
365e3e4bb2SZachary Turner     case cv_error_code::unknown_member_record:
375e3e4bb2SZachary Turner       return "The member record is of an unknown type.";
38d5d37dcfSZachary Turner     }
39d5d37dcfSZachary Turner     llvm_unreachable("Unrecognized cv_error_code");
40d5d37dcfSZachary Turner   }
41d5d37dcfSZachary Turner };
42d5d37dcfSZachary Turner 
436a7efef4SAlexandre Ganea static llvm::ManagedStatic<CodeViewErrorCategory> CodeViewErrCategory;
44*71c43ceaSAlexandre Ganea const std::error_category &llvm::codeview::CVErrorCategory() {
45*71c43ceaSAlexandre Ganea   return *CodeViewErrCategory;
46*71c43ceaSAlexandre Ganea }
47d5d37dcfSZachary Turner 
486a7efef4SAlexandre Ganea char CodeViewError::ID;
49