1//===- DXContainerReader.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 "DXContainerReader.h"
10
11namespace llvm {
12namespace objcopy {
13namespace dxbc {
14
15using namespace object;
16
17Expected<std::unique_ptr<Object>> DXContainerReader::create() const {
18 auto Obj = std::make_unique<Object>();
19 Obj->Header = DXContainerObj.getHeader();
20 for (const SectionRef &Part : DXContainerObj.sections()) {
21 DataRefImpl PartDRI = Part.getRawDataRefImpl();
22 Expected<StringRef> Name = DXContainerObj.getSectionName(Sec: PartDRI);
23 if (auto E = Name.takeError())
24 return E;
25 assert(Name->size() == 4 &&
26 "Valid DXIL Part name consists of 4 characters");
27 Expected<ArrayRef<uint8_t>> Data =
28 DXContainerObj.getSectionContents(Sec: PartDRI);
29 if (auto E = Data.takeError())
30 return E;
31 Obj->Parts.push_back(Elt: {.Name: *Name, .Data: *Data});
32 }
33 return std::move(Obj);
34}
35
36} // end namespace dxbc
37} // end namespace objcopy
38} // end namespace llvm
39