[llvm-objcopy] [COFF] Use Error/Expected returns instead of calling reportError....
[llvm-core.git] / tools / llvm-objcopy / COFF / COFFObjcopy.cpp
blob9ed965cc941404d982a72dede2d4da754b44c329
1 //===- COFFObjcopy.cpp ----------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "COFFObjcopy.h"
11 #include "Buffer.h"
12 #include "CopyConfig.h"
13 #include "Object.h"
14 #include "Reader.h"
15 #include "Writer.h"
16 #include "llvm-objcopy.h"
18 #include "llvm/Object/Binary.h"
19 #include "llvm/Object/COFF.h"
20 #include <cassert>
22 namespace llvm {
23 namespace objcopy {
24 namespace coff {
26 using namespace object;
27 using namespace COFF;
29 void executeObjcopyOnBinary(const CopyConfig &Config,
30 object::COFFObjectFile &In, Buffer &Out) {
31 COFFReader Reader(In);
32 Expected<std::unique_ptr<Object>> ObjOrErr = Reader.create();
33 if (!ObjOrErr)
34 reportError(Config.InputFilename, ObjOrErr.takeError());
35 Object *Obj = ObjOrErr->get();
36 assert(Obj && "Unable to deserialize COFF object");
37 COFFWriter Writer(*Obj, Out);
38 if (Error E = Writer.write())
39 reportError(Config.OutputFilename, std::move(E));
42 } // end namespace coff
43 } // end namespace objcopy
44 } // end namespace llvm