summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Bieneman <beanz@apple.com>2016-05-11 22:07:45 +0000
committerChris Bieneman <beanz@apple.com>2016-05-11 22:07:45 +0000
commit8cb136b8debe85547caa4b220438967fc313cfc3 (patch)
tree881d6d6729282dc5b0ee46dea8e48d354eace9ba
parentbff9dae3ff144ceea732b7a72cf203dac5d7993c (diff)
downloadbcm5719-llvm-8cb136b8debe85547caa4b220438967fc313cfc3.tar.gz
bcm5719-llvm-8cb136b8debe85547caa4b220438967fc313cfc3.zip
Initial add for MachO support for obj2yaml
Adding the initial files for adding MachO support to obj2yaml. Passing a MachO file will result in a new not_implemented error. I will be implementing obj2yaml and yaml2obj for MachO in parallel so that one can be used to test the other. llvm-svn: 269243
-rw-r--r--llvm/tools/obj2yaml/CMakeLists.txt6
-rw-r--r--llvm/tools/obj2yaml/Error.cpp2
-rw-r--r--llvm/tools/obj2yaml/Error.h3
-rw-r--r--llvm/tools/obj2yaml/macho2yaml.cpp35
-rw-r--r--llvm/tools/obj2yaml/obj2yaml.cpp2
-rw-r--r--llvm/tools/obj2yaml/obj2yaml.h2
6 files changed, 48 insertions, 2 deletions
diff --git a/llvm/tools/obj2yaml/CMakeLists.txt b/llvm/tools/obj2yaml/CMakeLists.txt
index 9d8c32f9e42..9b895525060 100644
--- a/llvm/tools/obj2yaml/CMakeLists.txt
+++ b/llvm/tools/obj2yaml/CMakeLists.txt
@@ -5,5 +5,9 @@ set(LLVM_LINK_COMPONENTS
)
add_llvm_tool(obj2yaml
- obj2yaml.cpp coff2yaml.cpp elf2yaml.cpp Error.cpp
+ obj2yaml.cpp
+ coff2yaml.cpp
+ elf2yaml.cpp
+ macho2yaml.cpp
+ Error.cpp
)
diff --git a/llvm/tools/obj2yaml/Error.cpp b/llvm/tools/obj2yaml/Error.cpp
index abef8af58cb..9eb70c6a47b 100644
--- a/llvm/tools/obj2yaml/Error.cpp
+++ b/llvm/tools/obj2yaml/Error.cpp
@@ -34,6 +34,8 @@ std::string _obj2yaml_error_category::message(int ev) const {
return "Unrecognized file type.";
case obj2yaml_error::unsupported_obj_file_format:
return "Unsupported object file format.";
+ case obj2yaml_error::not_implemented:
+ return "Feature not yet implemented.";
}
llvm_unreachable("An enumerator of obj2yaml_error does not have a message "
"defined.");
diff --git a/llvm/tools/obj2yaml/Error.h b/llvm/tools/obj2yaml/Error.h
index 982f59e236c..7be92e9aace 100644
--- a/llvm/tools/obj2yaml/Error.h
+++ b/llvm/tools/obj2yaml/Error.h
@@ -19,7 +19,8 @@ enum class obj2yaml_error {
success = 0,
file_not_found,
unrecognized_file_format,
- unsupported_obj_file_format
+ unsupported_obj_file_format,
+ not_implemented
};
inline std::error_code make_error_code(obj2yaml_error e) {
diff --git a/llvm/tools/obj2yaml/macho2yaml.cpp b/llvm/tools/obj2yaml/macho2yaml.cpp
new file mode 100644
index 00000000000..c3b972dcbe3
--- /dev/null
+++ b/llvm/tools/obj2yaml/macho2yaml.cpp
@@ -0,0 +1,35 @@
+//===------ macho2yaml.cpp - obj2yaml conversion tool -----------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Error.h"
+#include "obj2yaml.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Object/MachOUniversal.h"
+
+using namespace llvm;
+
+std::error_code macho2yaml(raw_ostream &Out,
+ const object::MachOObjectFile &Obj) {
+ return obj2yaml_error::not_implemented;
+}
+
+std::error_code macho2yaml(raw_ostream &Out,
+ const object::MachOUniversalBinary &Obj) {
+ return 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::MachOObjectFile>(&Obj))
+ return macho2yaml(Out, *MachOObj);
+
+ return obj2yaml_error::unsupported_obj_file_format;
+}
diff --git a/llvm/tools/obj2yaml/obj2yaml.cpp b/llvm/tools/obj2yaml/obj2yaml.cpp
index 8c4e1f814c4..62f2f796915 100644
--- a/llvm/tools/obj2yaml/obj2yaml.cpp
+++ b/llvm/tools/obj2yaml/obj2yaml.cpp
@@ -24,6 +24,8 @@ static std::error_code dumpObject(const ObjectFile &Obj) {
return coff2yaml(outs(), cast<COFFObjectFile>(Obj));
if (Obj.isELF())
return elf2yaml(outs(), Obj);
+ if (Obj.isMachO() || Obj.isMachOUniversalBinary())
+ return macho2yaml(outs(), Obj);
return obj2yaml_error::unsupported_obj_file_format;
}
diff --git a/llvm/tools/obj2yaml/obj2yaml.h b/llvm/tools/obj2yaml/obj2yaml.h
index 643ab7bc434..c17b7d1642c 100644
--- a/llvm/tools/obj2yaml/obj2yaml.h
+++ b/llvm/tools/obj2yaml/obj2yaml.h
@@ -21,5 +21,7 @@ std::error_code coff2yaml(llvm::raw_ostream &Out,
const llvm::object::COFFObjectFile &Obj);
std::error_code elf2yaml(llvm::raw_ostream &Out,
const llvm::object::ObjectFile &Obj);
+std::error_code macho2yaml(llvm::raw_ostream &Out,
+ const llvm::object::ObjectFile &Obj);
#endif
OpenPOWER on IntegriCloud