Martin Storsjo | e84a0b5 | 2018-12-19 07:24:38 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
| 9 | |
| 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" |
| 17 | |
| 18 | #include "llvm/Object/Binary.h" |
| 19 | #include "llvm/Object/COFF.h" |
| 20 | #include <cassert> |
| 21 | |
| 22 | namespace llvm { |
| 23 | namespace objcopy { |
| 24 | namespace coff { |
| 25 | |
| 26 | using namespace object; |
| 27 | using namespace COFF; |
| 28 | |
| 29 | void executeObjcopyOnBinary(const CopyConfig &Config, |
| 30 | object::COFFObjectFile &In, Buffer &Out) { |
| 31 | COFFReader Reader(In); |
Martin Storsjo | 0a5d5b1 | 2018-12-30 20:35:43 +0000 | [diff] [blame] | 32 | Expected<std::unique_ptr<Object>> ObjOrErr = Reader.create(); |
| 33 | if (!ObjOrErr) |
| 34 | reportError(Config.InputFilename, ObjOrErr.takeError()); |
| 35 | Object *Obj = ObjOrErr->get(); |
Martin Storsjo | e84a0b5 | 2018-12-19 07:24:38 +0000 | [diff] [blame] | 36 | assert(Obj && "Unable to deserialize COFF object"); |
| 37 | COFFWriter Writer(*Obj, Out); |
Martin Storsjo | 0a5d5b1 | 2018-12-30 20:35:43 +0000 | [diff] [blame] | 38 | if (Error E = Writer.write()) |
| 39 | reportError(Config.OutputFilename, std::move(E)); |
Martin Storsjo | e84a0b5 | 2018-12-19 07:24:38 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | } // end namespace coff |
| 43 | } // end namespace objcopy |
| 44 | } // end namespace llvm |