blob: cba23894060100175cab3473fdcb36348c5a81c8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
//===- Error.cpp - system_error extensions for lld --------------*- C++ -*-===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lld/Core/Error.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Mutex.h"
#include <string>
#include <vector>
using namespace lld;
class _NativeReaderErrorCategory : public std::error_category {
public:
const char* name() const LLVM_NOEXCEPT override {
return "lld.native.reader";
}
std::string message(int ev) const override {
switch (static_cast<NativeReaderError>(ev)) {
case NativeReaderError::success:
return "Success";
case NativeReaderError::unknown_file_format:
return "Unknown file format";
case NativeReaderError::file_too_short:
return "file truncated";
case NativeReaderError::file_malformed:
return "file malformed";
case NativeReaderError::memory_error:
return "out of memory";
case NativeReaderError::unknown_chunk_type:
return "unknown chunk type";
case NativeReaderError::conflicting_target_machine:
return "conflicting target machine";
}
llvm_unreachable("An enumerator of NativeReaderError does not have a "
"message defined.");
}
};
const std::error_category &lld::native_reader_category() {
static _NativeReaderErrorCategory o;
return o;
}
class _YamlReaderErrorCategory : public std::error_category {
public:
const char* name() const LLVM_NOEXCEPT override {
return "lld.yaml.reader";
}
std::string message(int ev) const override {
switch (static_cast<YamlReaderError>(ev)) {
case YamlReaderError::success:
return "Success";
case YamlReaderError::unknown_keyword:
return "Unknown keyword found in yaml file";
case YamlReaderError::illegal_value:
return "Bad value found in yaml file";
}
llvm_unreachable("An enumerator of YamlReaderError does not have a "
"message defined.");
}
};
const std::error_category &lld::YamlReaderCategory() {
static _YamlReaderErrorCategory o;
return o;
}
class _LinkerScriptReaderErrorCategory : public std::error_category {
public:
const char *name() const LLVM_NOEXCEPT override {
return "lld.linker-script.reader";
}
std::string message(int ev) const override {
switch (static_cast<LinkerScriptReaderError>(ev)) {
case LinkerScriptReaderError::success:
return "Success";
case LinkerScriptReaderError::parse_error:
return "Error parsing linker script";
}
llvm_unreachable("An enumerator of LinkerScriptReaderError does not have a "
"message defined.");
}
};
const std::error_category &lld::LinkerScriptReaderCategory() {
static _LinkerScriptReaderErrorCategory o;
return o;
}
class _InputGraphErrorCategory : public std::error_category {
public:
const char *name() const LLVM_NOEXCEPT override {
return "lld.inputGraph.parse";
}
std::string message(int ev) const override {
switch (static_cast<InputGraphError>(ev)) {
case InputGraphError::success:
return "Success";
case InputGraphError::failure:
return "failure";
case InputGraphError::no_more_elements:
return "no more elements";
case InputGraphError::no_more_files:
return "no more files";
}
llvm_unreachable("An enumerator of InputGraphError does not have a "
"message defined.");
}
};
const std::error_category &lld::InputGraphErrorCategory() {
static _InputGraphErrorCategory i;
return i;
}
class _ReaderErrorCategory : public std::error_category {
public:
const char *name() const LLVM_NOEXCEPT override {
return "lld.inputGraph.parse";
}
std::string message(int ev) const override {
switch (static_cast<ReaderError>(ev)) {
case ReaderError::success:
return "Success";
case ReaderError::unknown_file_format:
return "File format for the input file is not recognized by this flavor";
}
llvm_unreachable("An enumerator of ReaderError does not have a "
"message defined.");
}
};
const std::error_category &lld::ReaderErrorCategory() {
static _ReaderErrorCategory i;
return i;
}
namespace lld {
/// Temporary class to enable make_dynamic_error_code() until
/// llvm::ErrorOr<> is updated to work with error encapsulations
/// other than error_code.
class dynamic_error_category : public std::error_category {
public:
~dynamic_error_category() LLVM_NOEXCEPT {}
const char *name() const LLVM_NOEXCEPT override {
return "lld.dynamic_error";
}
std::string message(int ev) const override {
assert(ev >= 0);
assert(ev < (int)_messages.size());
// The value is an index into the string vector.
return _messages[ev];
}
int add(std::string msg) {
llvm::sys::SmartScopedLock<true> lock(_mutex);
// Value zero is always the successs value.
if (_messages.empty())
_messages.push_back("Success");
_messages.push_back(msg);
// Return the index of the string just appended.
return _messages.size() - 1;
}
private:
std::vector<std::string> _messages;
llvm::sys::SmartMutex<true> _mutex;
};
static dynamic_error_category categorySingleton;
std::error_code make_dynamic_error_code(StringRef msg) {
return std::error_code(categorySingleton.add(msg), categorySingleton);
}
std::error_code make_dynamic_error_code(const Twine &msg) {
return std::error_code(categorySingleton.add(msg.str()), categorySingleton);
}
}
|