LLVM 22.0.0git
DXContainerWriter.cpp
Go to the documentation of this file.
1//===- DXContainerWriter.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 "DXContainerWriter.h"
10
11namespace llvm {
12namespace objcopy {
13namespace dxbc {
14
15using namespace object;
16
17size_t DXContainerWriter::finalize() {
18 assert(Offsets.empty() &&
19 "Attempted to finalize writer with already computed offsets");
20 Offsets.reserve(Obj.Parts.size());
21 size_t Offset = Obj.headerSize();
22 for (const Part &P : Obj.Parts) {
23 Offsets.push_back(Offset);
24 Offset += P.size();
25 }
26 return Obj.Header.FileSize;
27}
28
30 size_t TotalSize = finalize();
31 Out.reserveExtraSpace(TotalSize);
32
33 llvm::dxbc::Header Header = Obj.Header;
35 Header.swapBytes();
36 Out.write(reinterpret_cast<const char *>(&Header),
37 sizeof(::llvm::dxbc::Header));
39 for (auto &O : Offsets)
41 Out.write(reinterpret_cast<const char *>(Offsets.data()),
42 Offsets.size() * sizeof(uint32_t));
43
44 for (const Part &P : Obj.Parts) {
45 Out.write(reinterpret_cast<const char *>(P.Name.data()), 4);
46 uint32_t Size = P.Data.size();
49 Out.write(reinterpret_cast<const char *>(&Size), sizeof(uint32_t));
50 Out.write(reinterpret_cast<const char *>(P.Data.data()), P.Data.size());
51 }
52
53 return Error::success();
54}
55
56} // end namespace dxbc
57} // end namespace objcopy
58} // end namespace llvm
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t Size
#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
bool empty() const
Definition: SmallVector.h:82
void reserve(size_type N)
Definition: SmallVector.h:664
void push_back(const T &Elt)
Definition: SmallVector.h:414
raw_ostream & write(unsigned char C)
virtual void reserveExtraSpace(uint64_t ExtraSize)
If possible, pre-allocate ExtraSize bytes for stream data.
Definition: raw_ostream.h:161
constexpr bool IsBigEndianHost
Definition: SwapByteOrder.h:26
void swapByteOrder(T &Value)
Definition: SwapByteOrder.h:61
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
::llvm::dxbc::Header Header