summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
authorChris Bieneman <beanz@apple.com>2016-05-12 01:52:33 +0000
committerChris Bieneman <beanz@apple.com>2016-05-12 01:52:33 +0000
commitde60ad33b37e19cbf73b53feed6428886d358f02 (patch)
treedebc8251e5d1c6a43bf33bd502318004fdad07f9 /llvm/tools
parent9926a5e31de0834d7a70bf1837777b94a72e5111 (diff)
downloadbcm5719-llvm-de60ad33b37e19cbf73b53feed6428886d358f02.tar.gz
bcm5719-llvm-de60ad33b37e19cbf73b53feed6428886d358f02.zip
[obj2yaml] Adding Error/Expected to macho2yaml
I figure if I'm adding Mach support I may as well use the new fancy Error model. llvm-svn: 269264
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/obj2yaml/Error.cpp12
-rw-r--r--llvm/tools/obj2yaml/Error.h18
-rw-r--r--llvm/tools/obj2yaml/macho2yaml.cpp26
3 files changed, 45 insertions, 11 deletions
diff --git a/llvm/tools/obj2yaml/Error.cpp b/llvm/tools/obj2yaml/Error.cpp
index 9eb70c6a47b..9c2aeefef2f 100644
--- a/llvm/tools/obj2yaml/Error.cpp
+++ b/llvm/tools/obj2yaml/Error.cpp
@@ -42,8 +42,18 @@ std::string _obj2yaml_error_category::message(int ev) const {
}
namespace llvm {
- const std::error_category &obj2yaml_category() {
+
+const std::error_category &obj2yaml_category() {
static _obj2yaml_error_category o;
return o;
}
+
+char Obj2YamlError::ID = 0;
+
+void Obj2YamlError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
+
+std::error_code Obj2YamlError::convertToErrorCode() const {
+ return std::error_code(static_cast<int>(Code), obj2yaml_category());
+}
+
} // namespace llvm
diff --git a/llvm/tools/obj2yaml/Error.h b/llvm/tools/obj2yaml/Error.h
index 7be92e9aace..f4e191c872c 100644
--- a/llvm/tools/obj2yaml/Error.h
+++ b/llvm/tools/obj2yaml/Error.h
@@ -10,6 +10,8 @@
#ifndef LLVM_TOOLS_OBJ2YAML_ERROR_H
#define LLVM_TOOLS_OBJ2YAML_ERROR_H
+#include "llvm/Support/Error.h"
+
#include <system_error>
namespace llvm {
@@ -27,6 +29,22 @@ inline std::error_code make_error_code(obj2yaml_error e) {
return std::error_code(static_cast<int>(e), obj2yaml_category());
}
+class Obj2YamlError : public ErrorInfo<Obj2YamlError> {
+public:
+ static char ID;
+ Obj2YamlError(obj2yaml_error C) : Code(C) {}
+ Obj2YamlError(const std::string &ErrMsg) : ErrMsg(std::move(ErrMsg)) {}
+ Obj2YamlError(obj2yaml_error C, std::string ErrMsg)
+ : ErrMsg(std::move(ErrMsg)), Code(C) {}
+ void log(raw_ostream &OS) const override;
+ const std::string &getErrorMessage() const { return ErrMsg; }
+ std::error_code convertToErrorCode() const override;
+
+private:
+ std::string ErrMsg;
+ obj2yaml_error Code;
+};
+
} // namespace llvm
namespace std {
diff --git a/llvm/tools/obj2yaml/macho2yaml.cpp b/llvm/tools/obj2yaml/macho2yaml.cpp
index c3b972dcbe3..76f99c8dc36 100644
--- a/llvm/tools/obj2yaml/macho2yaml.cpp
+++ b/llvm/tools/obj2yaml/macho2yaml.cpp
@@ -14,22 +14,28 @@
using namespace llvm;
-std::error_code macho2yaml(raw_ostream &Out,
- const object::MachOObjectFile &Obj) {
- return obj2yaml_error::not_implemented;
+Error macho2yaml(raw_ostream &Out, const object::MachOObjectFile &Obj) {
+ return make_error<Obj2YamlError>(obj2yaml_error::not_implemented);
}
-std::error_code macho2yaml(raw_ostream &Out,
- const object::MachOUniversalBinary &Obj) {
- return obj2yaml_error::not_implemented;
+Error macho2yaml(raw_ostream &Out, const object::MachOUniversalBinary &Obj) {
+ return make_error<Obj2YamlError>(obj2yaml_error::not_implemented);
}
std::error_code macho2yaml(raw_ostream &Out, const object::ObjectFile &Obj) {
- if (const auto *MachOObj = dyn_cast<object::MachOUniversalBinary>(&Obj))
- return macho2yaml(Out, *MachOObj);
+ if (const auto *MachOObj = dyn_cast<object::MachOUniversalBinary>(&Obj)) {
+ if (auto Err = macho2yaml(Out, *MachOObj)) {
+ return errorToErrorCode(std::move(Err));
+ }
+ return obj2yaml_error::success;
+ }
- if (const auto *MachOObj = dyn_cast<object::MachOObjectFile>(&Obj))
- return macho2yaml(Out, *MachOObj);
+ if (const auto *MachOObj = dyn_cast<object::MachOObjectFile>(&Obj)) {
+ if (auto Err = macho2yaml(Out, *MachOObj)) {
+ return errorToErrorCode(std::move(Err));
+ }
+ return obj2yaml_error::success;
+ }
return obj2yaml_error::unsupported_obj_file_format;
}
OpenPOWER on IntegriCloud