Cleanup system_error extensions.
llvm-svn: 149432
diff --git a/lld/lib/Core/CMakeLists.txt b/lld/lib/Core/CMakeLists.txt
index c994d8f..4ebdc4c 100644
--- a/lld/lib/Core/CMakeLists.txt
+++ b/lld/lib/Core/CMakeLists.txt
@@ -1,4 +1,5 @@
add_lld_library(lldCore
+ Error.cpp
File.cpp
NativeFileFormat.h
NativeReader.cpp
diff --git a/lld/lib/Core/Error.cpp b/lld/lib/Core/Error.cpp
new file mode 100644
index 0000000..bbf16da
--- /dev/null
+++ b/lld/lib/Core/Error.cpp
@@ -0,0 +1,92 @@
+//===- 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/Support/ErrorHandling.h"
+
+using namespace lld;
+
+class _native_reader_error_category : public llvm::_do_message {
+public:
+ virtual const char* name() const {
+ return "lld.native.reader";
+ }
+
+ virtual std::string message(int ev) const {
+ switch (ev) {
+ case native_reader_error::success:
+ return "Success";
+ case native_reader_error::unknown_file_format:
+ return "Unknown file foramt";
+ case native_reader_error::file_too_short:
+ return "file truncated";
+ case native_reader_error::file_malformed:
+ return "file malformed";
+ case native_reader_error::memory_error:
+ return "out of memory";
+ case native_reader_error::unknown_chunk_type:
+ return "unknown chunk type";
+ default:
+ llvm_unreachable("An enumerator of native_reader_error does not have a "
+ "message defined.");
+ }
+ }
+
+ virtual llvm::error_condition default_error_condition(int ev) const {
+ if (ev == native_reader_error::success)
+ return llvm::errc::success;
+ return llvm::errc::invalid_argument;
+ }
+};
+
+const llvm::error_category &lld::native_reader_category() {
+ static _native_reader_error_category o;
+ return o;
+}
+
+inline llvm::error_code make_error_code(native_reader_error e) {
+ return llvm::error_code(static_cast<int>(e), native_reader_category());
+}
+
+class _yaml_reader_error_category : public llvm::_do_message {
+public:
+ virtual const char* name() const {
+ return "lld.yaml.reader";
+ }
+
+ virtual std::string message(int ev) const {
+ switch (ev) {
+ case yaml_reader_error::success:
+ return "Success";
+ case yaml_reader_error::unknown_keyword:
+ return "Unknown keyword found in yaml file";
+ case yaml_reader_error::illegal_value:
+ return "Bad value found in yaml file";
+ default:
+ llvm_unreachable("An enumerator of yaml_reader_error does not have a "
+ "message defined.");
+ }
+ }
+
+ virtual llvm::error_condition default_error_condition(int ev) const {
+ if (ev == yaml_reader_error::success)
+ return llvm::errc::success;
+ return llvm::errc::invalid_argument;
+ }
+};
+
+const llvm::error_category &lld::yaml_reader_category() {
+ static _yaml_reader_error_category o;
+ return o;
+}
+
+inline llvm::error_code make_error_code(yaml_reader_error e) {
+ return llvm::error_code(static_cast<int>(e), yaml_reader_category());
+}
diff --git a/lld/lib/Core/NativeReader.cpp b/lld/lib/Core/NativeReader.cpp
index 0316a2e..845d6bf 100644
--- a/lld/lib/Core/NativeReader.cpp
+++ b/lld/lib/Core/NativeReader.cpp
@@ -16,8 +16,8 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/system_error.h"
+#include "lld/Core/Error.h"
#include "lld/Core/File.h"
#include "lld/Core/Atom.h"
@@ -28,53 +28,6 @@
// forward reference
class NativeFile;
-
-enum native_reader_errors {
- success = 0,
- unknown_file_format,
- file_too_short,
- file_malformed,
- unknown_chunk_type,
- memory_error,
-};
-
-class reader_error_category : public llvm::_do_message {
-public:
- virtual const char* name() const {
- return "lld.native.reader";
- }
- virtual std::string message(int ev) const;
-};
-
-const reader_error_category reader_error_category_singleton;
-
-std::string reader_error_category::message(int ev) const {
- switch (ev) {
- case success:
- return "Success";
- case unknown_file_format:
- return "Unknown file foramt";
- case file_too_short:
- return "file truncated";
- case file_malformed:
- return "file malformed";
- case memory_error:
- return "out of memory";
- case unknown_chunk_type:
- return "unknown chunk type";
- default:
- llvm_unreachable("An enumerator of native_reader_errors does not have a "
- "message defined.");
- }
-}
-
-inline llvm::error_code make_error_code(native_reader_errors e) {
- return llvm::error_code(static_cast<int>(e), reader_error_category_singleton);
-}
-
-
-
-
//
// An object of this class is instantied for each NativeDefinedAtomIvarsV1
// struct in the NCS_DefinedAtomsV1 chunk.
@@ -179,13 +132,13 @@
reinterpret_cast<const NativeChunk*>(base + sizeof(NativeFileHeader));
// make sure magic matches
if ( memcmp(header->magic, NATIVE_FILE_HEADER_MAGIC, 16) != 0 )
- return make_error_code(unknown_file_format);
-
+ return make_error_code(native_reader_error::unknown_file_format);
+
// make sure mapped file contains all needed data
const size_t fileSize = mb->getBufferSize();
if ( header->fileSize > fileSize )
- return make_error_code(file_too_short);
-
+ return make_error_code(native_reader_error::file_too_short);
+
// instantiate NativeFile object and add values to it as found
NativeFile* file = new NativeFile(mb, path);
@@ -194,10 +147,10 @@
llvm::error_code ec;
const NativeChunk* chunk = &chunks[i];
// sanity check chunk is within file
- if ( chunk->fileOffset > fileSize )
- return make_error_code(file_malformed);
- if ( (chunk->fileOffset + chunk->fileSize) > fileSize)
- return make_error_code(file_malformed);
+ if ( chunk->fileOffset > fileSize )
+ return make_error_code(native_reader_error::file_malformed);
+ if ( (chunk->fileOffset + chunk->fileSize) > fileSize)
+ return make_error_code(native_reader_error::file_malformed);
// process chunk, based on signature
switch ( chunk->signature ) {
case NCS_DefinedAtomsV1:
@@ -213,7 +166,7 @@
ec = file->processStrings(base, chunk);
break;
default:
- return make_error_code(unknown_chunk_type);
+ return make_error_code(native_reader_error::unknown_chunk_type);
}
if ( ec ) {
delete file;
@@ -224,9 +177,9 @@
result = file;
}
-
- return make_error_code(success);
+
+ return make_error_code(native_reader_error::success);
}
virtual ~NativeFile() {
@@ -266,11 +219,11 @@
uint8_t* atomsStart = reinterpret_cast<uint8_t*>
(operator new(atomsArraySize, std::nothrow));
if (atomsStart == NULL )
- return make_error_code(memory_error);
- const size_t ivarElementSize = chunk->fileSize
+ return make_error_code(native_reader_error::memory_error);
+ const size_t ivarElementSize = chunk->fileSize
/ chunk->elementCount;
if ( ivarElementSize != sizeof(NativeDefinedAtomIvarsV1) )
- return make_error_code(file_malformed);
+ return make_error_code(native_reader_error::file_malformed);
uint8_t* atomsEnd = atomsStart + atomsArraySize;
const NativeDefinedAtomIvarsV1* ivarData =
reinterpret_cast<const NativeDefinedAtomIvarsV1*>
@@ -284,14 +237,14 @@
this->_definedAtoms.arrayStart = atomsStart;
this->_definedAtoms.arrayEnd = atomsEnd;
this->_definedAtoms.elementSize = atomSize;
- return make_error_code(success);
+ return make_error_code(native_reader_error::success);
}
// set up pointers to attributes array
llvm::error_code processAttributesV1(const uint8_t* base, const NativeChunk* chunk) {
this->_attributes = base + chunk->fileOffset;
this->_attributesMaxOffset = chunk->fileSize;
- return make_error_code(success);
+ return make_error_code(native_reader_error::success);
}
// set up pointers to string pool in file
@@ -299,7 +252,7 @@
const NativeChunk* chunk) {
this->_strings = reinterpret_cast<const char*>(base + chunk->fileOffset);
this->_stringsMaxOffset = chunk->fileSize;
- return make_error_code(success);
+ return make_error_code(native_reader_error::success);
}
// set up pointers to content area in file
@@ -307,7 +260,7 @@
const NativeChunk* chunk) {
this->_contentStart = base + chunk->fileOffset;
this->_contentEnd = base + chunk->fileOffset + chunk->fileSize;
- return make_error_code(success);
+ return make_error_code(native_reader_error::success);
}
llvm::StringRef string(uint32_t offset) const {
diff --git a/lld/lib/Core/YamlReader.cpp b/lld/lib/Core/YamlReader.cpp
index 5ca8fbc..39c0643 100644
--- a/lld/lib/Core/YamlReader.cpp
+++ b/lld/lib/Core/YamlReader.cpp
@@ -11,6 +11,7 @@
#include "lld/Core/YamlReader.h"
#include "lld/Core/Atom.h"
+#include "lld/Core/Error.h"
#include "lld/Core/File.h"
#include "lld/Core/Reference.h"
@@ -29,41 +30,6 @@
namespace lld {
namespace yaml {
-enum yaml_reader_errors {
- success = 0,
- unknown_keyword,
- illegal_value
-};
-
-class reader_error_category : public llvm::_do_message {
-public:
- virtual const char* name() const {
- return "lld.yaml.reader";
- }
- virtual std::string message(int ev) const;
-};
-
-const reader_error_category reader_error_category_singleton;
-
-std::string reader_error_category::message(int ev) const {
- switch (ev) {
- case success:
- return "Success";
- case unknown_keyword:
- return "Unknown keyword found in yaml file";
- case illegal_value:
- return "Bad value found in yaml file";
- default:
- llvm_unreachable("An enumerator of yaml_reader_errors does not have a "
- "message defined.");
- }
-}
-
-inline llvm::error_code make_error_code(yaml_reader_errors e) {
- return llvm::error_code(static_cast<int>(e), reader_error_category_singleton);
-}
-
-
class YAML {
public:
struct Entry {
@@ -704,8 +670,8 @@
}
else if (strcmp(entry->key, KeyValues::sizeKeyword) == 0) {
llvm::StringRef val = entry->value;
- if ( val.getAsInteger(0, atomState._size) )
- return make_error_code(illegal_value);
+ if ( val.getAsInteger(0, atomState._size) )
+ return make_error_code(yaml_reader_error::illegal_value);
haveAtom = true;
}
else if (strcmp(entry->key, KeyValues::contentKeyword) == 0) {
@@ -720,7 +686,7 @@
inFixups = true;
}
else {
- return make_error_code(unknown_keyword);
+ return make_error_code(yaml_reader_error::unknown_keyword);
}
}
else if (depthForFixups == entry->depth) {
@@ -749,7 +715,7 @@
}
result.push_back(file);
- return make_error_code(success);
+ return make_error_code(yaml_reader_error::success);
}
//