LLVM 22.0.0git
DXContainerObjcopy.cpp
Go to the documentation of this file.
1//===- DXContainerObjcopy.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
10#include "DXContainerReader.h"
11#include "DXContainerWriter.h"
14
15namespace llvm {
16namespace objcopy {
17namespace dxbc {
18
19using namespace object;
20
22 std::function<bool(const Part &)> RemovePred = [](const Part &) {
23 return false;
24 };
25
26 if (!Config.ToRemove.empty())
27 RemovePred = [&Config](const Part &P) {
28 return Config.ToRemove.matches(P.Name);
29 };
30
31 if (auto E = Obj.removeParts(RemovePred))
32 return E;
33
34 Obj.recomputeHeader();
35 return Error::success();
36}
37
39 const DXContainerConfig &,
41 DXContainerReader Reader(In);
42 Expected<std::unique_ptr<Object>> ObjOrErr = Reader.create();
43 if (!ObjOrErr)
44 return createFileError(Config.InputFilename, ObjOrErr.takeError());
45 Object *Obj = ObjOrErr->get();
46 assert(Obj && "Unable to deserialize DXContainer object");
47
48 if (Error E = handleArgs(Config, *Obj))
49 return E;
50
51 DXContainerWriter Writer(*Obj, Out);
52 if (Error E = Writer.write())
53 return createFileError(Config.OutputFilename, std::move(E));
54 return Error::success();
55}
56
57} // end namespace dxbc
58} // end namespace objcopy
59} // end namespace llvm
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
RelaxConfig Config
Definition: ELF_riscv.cpp:506
#define P(N)
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
static ErrorSuccess success()
Create a success value.
Definition: Error.h:336
Tagged union holding either a T or a Error.
Definition: Error.h:485
Error takeError()
Take ownership of the stored error.
Definition: Error.h:612
reference get()
Returns a reference to the stored T value.
Definition: Error.h:582
Expected< std::unique_ptr< Object > > create() const
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
Error executeObjcopyOnBinary(const CommonConfig &Config, const DXContainerConfig &, object::DXContainerObjectFile &In, raw_ostream &Out)
Apply the transformations described by Config and DXContainerConfig to In and writes the result into ...
static Error handleArgs(const CommonConfig &Config, Object &Obj)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Definition: Error.h:1399
Error removeParts(PartPred ToRemove)