diff --git a/tools/obj2yaml/CMakeLists.txt b/tools/obj2yaml/CMakeLists.txt index 9d8c32f9e42..9b895525060 100644 --- a/tools/obj2yaml/CMakeLists.txt +++ b/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/tools/obj2yaml/Error.cpp b/tools/obj2yaml/Error.cpp index abef8af58cb..9eb70c6a47b 100644 --- a/tools/obj2yaml/Error.cpp +++ b/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/tools/obj2yaml/Error.h b/tools/obj2yaml/Error.h index 982f59e236c..7be92e9aace 100644 --- a/tools/obj2yaml/Error.h +++ b/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/tools/obj2yaml/macho2yaml.cpp b/tools/obj2yaml/macho2yaml.cpp new file mode 100644 index 00000000000..c3b972dcbe3 --- /dev/null +++ b/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(&Obj)) + return macho2yaml(Out, *MachOObj); + + if (const auto *MachOObj = dyn_cast(&Obj)) + return macho2yaml(Out, *MachOObj); + + return obj2yaml_error::unsupported_obj_file_format; +} diff --git a/tools/obj2yaml/obj2yaml.cpp b/tools/obj2yaml/obj2yaml.cpp index 8c4e1f814c4..62f2f796915 100644 --- a/tools/obj2yaml/obj2yaml.cpp +++ b/tools/obj2yaml/obj2yaml.cpp @@ -24,6 +24,8 @@ static std::error_code dumpObject(const ObjectFile &Obj) { return coff2yaml(outs(), cast(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/tools/obj2yaml/obj2yaml.h b/tools/obj2yaml/obj2yaml.h index 643ab7bc434..c17b7d1642c 100644 --- a/tools/obj2yaml/obj2yaml.h +++ b/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