aboutsummaryrefslogtreecommitdiff
path: root/deps/lld/lib/Core/Error.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-08-28 04:09:09 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-08-28 04:09:09 -0400
commitd7a539906d2dd49872abb161f3d3364c9641ccd2 (patch)
tree0d9c04fdc537326431a34ca2e7797c976fa4b91b /deps/lld/lib/Core/Error.cpp
parent2a49c876be76dc98996a3251310728ad32b22363 (diff)
parent1525e2c0561bb598b1e94ad9cdced5dd22e7d66d (diff)
downloadzig-d7a539906d2dd49872abb161f3d3364c9641ccd2.tar.gz
zig-d7a539906d2dd49872abb161f3d3364c9641ccd2.zip
Merge branch 'embed-lld'
Zig now depends on LLVM 5.0.0. For the latest version that supports LLVM 4.0.1, use 2a49c876be76dc98996a3251310728ad32b22363. Unfortunately we had to embed LLD into Zig due to some MACH-O related LLD bugs. One of them is already upstream and another is awaiting feedback on the llvm-dev mailing list. You can use cmake option -DZIG_FORCE_EXTERNAL_LLD=ON to still use external LLD if you want to live with the MACH-O bugs or if your system LLD is patched. Closes #273
Diffstat (limited to 'deps/lld/lib/Core/Error.cpp')
-rw-r--r--deps/lld/lib/Core/Error.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/deps/lld/lib/Core/Error.cpp b/deps/lld/lib/Core/Error.cpp
new file mode 100644
index 0000000000..6fc76f7ca3
--- /dev/null
+++ b/deps/lld/lib/Core/Error.cpp
@@ -0,0 +1,93 @@
+//===- 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 <mutex>
+#include <string>
+#include <vector>
+
+using namespace lld;
+
+namespace {
+class _YamlReaderErrorCategory : public std::error_category {
+public:
+ const char* name() const noexcept override {
+ return "lld.yaml.reader";
+ }
+
+ std::string message(int ev) const override {
+ switch (static_cast<YamlReaderError>(ev)) {
+ 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.");
+ }
+};
+} // end anonymous namespace
+
+const std::error_category &lld::YamlReaderCategory() {
+ static _YamlReaderErrorCategory o;
+ return o;
+}
+
+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() override = default;
+
+ const char *name() const 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) {
+ std::lock_guard<std::recursive_mutex> 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;
+ std::recursive_mutex _mutex;
+};
+
+static dynamic_error_category categorySingleton;
+
+std::error_code make_dynamic_error_code(StringRef msg) {
+ return std::error_code(categorySingleton.add(msg), categorySingleton);
+}
+
+char GenericError::ID = 0;
+
+GenericError::GenericError(Twine Msg) : Msg(Msg.str()) { }
+
+void GenericError::log(raw_ostream &OS) const {
+ OS << Msg;
+}
+
+} // namespace lld