File tree Expand file tree Collapse file tree 4 files changed +50
-0
lines changed
Expand file tree Collapse file tree 4 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ source_group("Source Files\\DXContainer" REGULAR_EXPRESSION
4444add_llvm_component_library(LLVMObjCopy
4545 Archive.cpp
4646 DXContainer/DXContainerObjcopy.cpp
47+ DXContainer/DXContainerObject.cpp
4748 DXContainer/DXContainerReader.cpp
4849 DXContainer/DXContainerWriter.cpp
4950 CommonConfig.cpp
Original file line number Diff line number Diff line change @@ -19,6 +19,18 @@ namespace dxbc {
1919using namespace object ;
2020
2121static Error handleArgs (const CommonConfig &Config, Object &Obj) {
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+
2234 return Error::success ();
2335}
2436
Original file line number Diff line number Diff line change 1+ // ===- DXContainerObject.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 " DXContainerObject.h"
10+
11+ namespace llvm {
12+ namespace objcopy {
13+ namespace dxbc {
14+
15+ Error Object::removeParts (PartPred ToRemove) {
16+ erase_if (Parts, ToRemove);
17+ recomputeHeader ();
18+ return Error::success ();
19+ }
20+
21+ void Object::recomputeHeader () {
22+ Header.FileSize = headerSize ();
23+ Header.PartCount = Parts.size ();
24+ for (const Part &P : Parts)
25+ Header.FileSize += P.size ();
26+ }
27+
28+ } // end namespace dxbc
29+ } // end namespace objcopy
30+ } // end namespace llvm
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ struct Part {
3030 }
3131};
3232
33+ using PartPred = llvm::function_ref<bool (const Part &)>;
34+
3335struct Object {
3436 ::llvm::dxbc::Header Header;
3537 SmallVector<Part> Parts;
@@ -38,6 +40,11 @@ struct Object {
3840 return sizeof (::llvm::dxbc::Header) // base header
3941 + sizeof (uint32_t ) * Parts.size (); // part offset values
4042 }
43+
44+ Error removeParts (PartPred ToRemove);
45+
46+ private:
47+ void recomputeHeader ();
4148};
4249
4350} // end namespace dxbc
You can’t perform that action at this time.
0 commit comments