1 //===- XCOFFObjcopy.cpp ---------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/ObjCopy/CommonConfig.h"
10 #include "llvm/ObjCopy/XCOFF/XCOFFConfig.h"
11 #include "llvm/ObjCopy/XCOFF/XCOFFObjcopy.h"
12 #include "llvm/Support/Errc.h"
13 #include "XCOFFObject.h"
14 #include "XCOFFReader.h"
15 #include "XCOFFWriter.h"
16 
17 namespace llvm {
18 namespace objcopy {
19 namespace xcoff {
20 
21 using namespace object;
22 
23 static Error handleArgs(const CommonConfig &Config, Object &Obj) {
24   return Error::success();
25 }
26 
27 Error executeObjcopyOnBinary(const CommonConfig &Config, const XCOFFConfig &,
28                              XCOFFObjectFile &In, raw_ostream &Out) {
29   XCOFFReader Reader(In);
30   Expected<std::unique_ptr<Object>> ObjOrErr = Reader.create();
31   if (!ObjOrErr)
32     return createFileError(Config.InputFilename, ObjOrErr.takeError());
33   Object *Obj = ObjOrErr->get();
34   assert(Obj && "Unable to deserialize XCOFF object");
35   if (Error E = handleArgs(Config, *Obj))
36     return createFileError(Config.InputFilename, std::move(E));
37   XCOFFWriter Writer(*Obj, Out);
38   if (Error E = Writer.write())
39     return createFileError(Config.OutputFilename, std::move(E));
40   return Error::success();
41 }
42 
43 } // end namespace xcoff
44 } // end namespace objcopy
45 } // end namespace llvm
46