X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fobj2yaml%2Fobj2yaml.cpp;h=ee6284da6e417229aabb99a849e8b820067319e6;hb=9f25a0678ed9f06088a09649a040a6bef362e6af;hp=38779fe45656bb310812f479a39400e7e5c325ed;hpb=f4ccd110750a3f3fe6a107d5c74c649c2a0dc407;p=oota-llvm.git diff --git a/tools/obj2yaml/obj2yaml.cpp b/tools/obj2yaml/obj2yaml.cpp index 38779fe4565..ee6284da6e4 100644 --- a/tools/obj2yaml/obj2yaml.cpp +++ b/tools/obj2yaml/obj2yaml.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "Error.h" #include "obj2yaml.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFF.h" @@ -16,16 +17,29 @@ #include "llvm/Support/Signals.h" using namespace llvm; +using namespace llvm::object; -namespace { -enum ObjectFileType { - coff -}; +static std::error_code dumpObject(const ObjectFile &Obj) { + if (Obj.isCOFF()) + return coff2yaml(outs(), cast(Obj)); + if (Obj.isELF()) + return elf2yaml(outs(), Obj); + + return obj2yaml_error::unsupported_obj_file_format; } -cl::opt InputFormat( - cl::desc("Choose input format"), - cl::values(clEnumVal(coff, "process COFF object files"), clEnumValEnd)); +static std::error_code dumpInput(StringRef File) { + ErrorOr> BinaryOrErr = createBinary(File); + if (std::error_code EC = BinaryOrErr.getError()) + return EC; + + Binary &Binary = *BinaryOrErr.get().getBinary(); + // TODO: If this is an archive, then burst it and dump each entry + if (ObjectFile *Obj = dyn_cast(&Binary)) + return dumpObject(*Obj); + + return obj2yaml_error::unrecognized_file_format; +} cl::opt InputFilename(cl::Positional, cl::desc(""), cl::init("-")); @@ -36,17 +50,9 @@ int main(int argc, char *argv[]) { PrettyStackTraceProgram X(argc, argv); llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. - // Process the input file - std::unique_ptr buf; - - // TODO: If this is an archive, then burst it and dump each entry - if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, buf)) { - errs() << "Error: '" << ec.message() << "' opening file '" << InputFilename - << "'\n"; - } else { - ec = coff2yaml(outs(), buf.release()); - if (ec) - errs() << "Error: " << ec.message() << " dumping COFF file\n"; + if (std::error_code EC = dumpInput(InputFilename)) { + errs() << "Error: '" << EC.message() << "'\n"; + return 1; } return 0;