aboutsummaryrefslogtreecommitdiff
path: root/lib/Object/Error.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Object/Error.cpp')
-rw-r--r--lib/Object/Error.cpp43
1 files changed, 35 insertions, 8 deletions
diff --git a/lib/Object/Error.cpp b/lib/Object/Error.cpp
index 7ecc3a19af9d..2357526b7894 100644
--- a/lib/Object/Error.cpp
+++ b/lib/Object/Error.cpp
@@ -19,6 +19,9 @@ using namespace llvm;
using namespace object;
namespace {
+// FIXME: This class is only here to support the transition to llvm::Error. It
+// will be removed once this transition is complete. Clients should prefer to
+// deal with the Error value directly, rather than converting to error_code.
class _object_error_category : public std::error_category {
public:
const char* name() const LLVM_NOEXCEPT override;
@@ -47,21 +50,45 @@ std::string _object_error_category::message(int EV) const {
return "Invalid section index";
case object_error::bitcode_section_not_found:
return "Bitcode section not found in object file";
- case object_error::elf_invalid_dynamic_table_size:
- return "Invalid dynamic table size";
- case object_error::macho_small_load_command:
- return "Mach-O load command with size < 8 bytes";
- case object_error::macho_load_segment_too_many_sections:
- return "Mach-O segment load command contains too many sections";
- case object_error::macho_load_segment_too_small:
- return "Mach-O segment load command size is too small";
}
llvm_unreachable("An enumerator of object_error does not have a message "
"defined.");
}
+char BinaryError::ID = 0;
+char GenericBinaryError::ID = 0;
+
+GenericBinaryError::GenericBinaryError(Twine Msg) : Msg(Msg.str()) {}
+
+GenericBinaryError::GenericBinaryError(Twine Msg, object_error ECOverride)
+ : Msg(Msg.str()) {
+ setErrorCode(make_error_code(ECOverride));
+}
+
+void GenericBinaryError::log(raw_ostream &OS) const {
+ OS << Msg;
+}
+
static ManagedStatic<_object_error_category> error_category;
const std::error_category &object::object_category() {
return *error_category;
}
+
+llvm::Error llvm::object::isNotObjectErrorInvalidFileType(llvm::Error Err) {
+ if (auto Err2 =
+ handleErrors(std::move(Err),
+ [](std::unique_ptr<ECError> M) {
+ // Try to handle 'M'. If successful, return a success value from
+ // the handler.
+ if (M->convertToErrorCode() == object_error::invalid_file_type)
+ return Error::success();
+
+ // We failed to handle 'M' - return it from the handler.
+ // This value will be passed back from catchErrors and
+ // wind up in Err2, where it will be returned from this function.
+ return Error(std::move(M));
+ }))
+ return Err2;
+ return Err;
+}