LLVM  14.0.0git
Error.cpp
Go to the documentation of this file.
1 //===- Error.cpp - system_error extensions for Object -----------*- 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 // This defines a new error_category for the Object library.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/Object/Error.h"
14 #include "llvm/ADT/Twine.h"
17 
18 using namespace llvm;
19 using namespace object;
20 
21 namespace {
22 // FIXME: This class is only here to support the transition to llvm::Error. It
23 // will be removed once this transition is complete. Clients should prefer to
24 // deal with the Error value directly, rather than converting to error_code.
25 class _object_error_category : public std::error_category {
26 public:
27  const char* name() const noexcept override;
28  std::string message(int ev) const override;
29 };
30 }
31 
32 const char *_object_error_category::name() const noexcept {
33  return "llvm.object";
34 }
35 
36 std::string _object_error_category::message(int EV) const {
37  object_error E = static_cast<object_error>(EV);
38  switch (E) {
40  return "No object file for requested architecture";
42  return "The file was not recognized as a valid object file";
44  return "Invalid data was encountered while parsing the file";
46  return "The end of the file was unexpectedly encountered";
48  return "String table must end with a null terminator";
50  return "Invalid section index";
52  return "Bitcode section not found in object file";
54  return "Invalid symbol index";
55  }
56  llvm_unreachable("An enumerator of object_error does not have a message "
57  "defined.");
58 }
59 
60 void BinaryError::anchor() {}
61 char BinaryError::ID = 0;
62 char GenericBinaryError::ID = 0;
63 
64 GenericBinaryError::GenericBinaryError(const Twine &Msg) : Msg(Msg.str()) {}
65 
67  object_error ECOverride)
68  : Msg(Msg.str()) {
69  setErrorCode(make_error_code(ECOverride));
70 }
71 
73  OS << Msg;
74 }
75 
77 
79  return *error_category;
80 }
81 
83  return handleErrors(std::move(Err), [](std::unique_ptr<ECError> M) -> Error {
84  // Try to handle 'M'. If successful, return a success value from
85  // the handler.
86  if (M->convertToErrorCode() == object_error::invalid_file_type)
87  return Error::success();
88 
89  // We failed to handle 'M' - return it from the handler.
90  // This value will be passed back from catchErrors and
91  // wind up in Err2, where it will be returned from this function.
92  return Error(std::move(M));
93  });
94 }
llvm::object::object_error::unexpected_eof
@ unexpected_eof
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::handleErrors
Error handleErrors(Error E, HandlerTs &&... Hs)
Pass the ErrorInfo(s) contained in E to their respective handlers.
Definition: Error.h:945
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::object::object_error::bitcode_section_not_found
@ bitcode_section_not_found
llvm::object::GenericBinaryError::ID
static char ID
Definition: Error.h:69
ErrorHandling.h
ManagedStatic.h
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::object::object_error::invalid_symbol_index
@ invalid_symbol_index
llvm::object::make_error_code
std::error_code make_error_code(object_error e)
Definition: Error.h:41
llvm::object::GenericBinaryError::log
void log(raw_ostream &OS) const override
Definition: Error.cpp:72
Error.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::object::object_error
object_error
Definition: Error.h:29
Twine.h
llvm::ManagedStatic
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:83
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::object::BinaryError::ID
static char ID
Definition: Error.h:56
llvm::object::object_error::parse_failed
@ parse_failed
llvm::object::object_error::invalid_file_type
@ invalid_file_type
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
llvm::object::object_error::string_table_non_null_end
@ string_table_non_null_end
const
aarch64 promote const
Definition: AArch64PromoteConstant.cpp:232
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
message
message(STATUS "Targeting ${t}") add_subdirectory($
Definition: CMakeLists.txt:33
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:134
llvm::object::object_category
const std::error_category & object_category()
Definition: Error.cpp:78
llvm::object::object_error::invalid_section_index
@ invalid_section_index
llvm::object::isNotObjectErrorInvalidFileType
Error isNotObjectErrorInvalidFileType(llvm::Error Err)
isNotObjectErrorInvalidFileType() is used when looping through the children of an archive after calli...
Definition: Error.cpp:82
name
static const char * name
Definition: SVEIntrinsicOpts.cpp:78
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
std
Definition: BitVector.h:838
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::object::object_error::arch_not_found
@ arch_not_found
error_category
static ManagedStatic< _object_error_category > error_category
Definition: Error.cpp:76
llvm::object::GenericBinaryError::GenericBinaryError
GenericBinaryError(const Twine &Msg)
Definition: Error.cpp:64