12#include "llvm/Config/config.h"
17#include "llvm/Support/VCSRevision.h"
27template <
typename StructT>
29 static_assert(std::is_class<StructT>() &&
30 "This method must be used for writing structure types");
33 OS.
write(
reinterpret_cast<const char *
>(&S),
sizeof(StructT));
62 Parameters.Flags = dxbc::CompilerVersionFlags::Default;
64 Parameters.Flags |= dxbc::CompilerVersionFlags::Debug;
87void CompilerVersion::updateContentSize() {
119 size_t ContentEntriesSize = 0;
121 ContentEntriesSize += ContentEntry.Parameters.AlignedSizeInBytes;
132 Parameters.EntriesSizeInBytes = CompressedSize;
137 dxbc::SourceInfo::SectionType::SourceContents);
149 const dxbc::SourceInfo::Names::HeaderOnDisk &
H) {
150 const auto *HPtr =
reinterpret_cast<const uint8_t *
>(&
H);
157 size_t NameEntriesSize = 0;
159 NameEntriesSize += NameEntry.Parameters.AlignedSizeInBytes;
166 sizeof(dxbc::SourceInfo::Names::HeaderOnDisk),
167 dxbc::SourceInfo::SectionType::SourceNames);
171 size_t ArgEntriesSize = 0;
172 for (
auto [ArgName, ArgVal] :
Args) {
174 ArgEntriesSize += ArgName.size() + 1 + ArgVal.size() + 1;
183 dxbc::SourceInfo::SectionType::Args);
191 Names.GenericHeader.AlignedSizeInBytes +
192 Contents.GenericHeader.AlignedSizeInBytes +
193 Args.GenericHeader.AlignedSizeInBytes);
205 for (
const auto &NameContent : FileNamesAndContents) {
207 ContentEntry.
FileContent = NameContent.second.str();
209 BaseData.Contents.Entries.emplace_back(std::move(ContentEntry));
212 NameEntry.
FileName = NameContent.first;
214 BaseData.Names.Entries.emplace_back(std::move(NameEntry));
218 for (
auto [ArgName, ArgValue] : Args)
219 BaseData.Args.Args.emplace_back(ArgName, ArgValue);
222void SourceInfoBuilder::recomputeAfterCompression(
uint32_t CompressedSize) {
223 BaseData.Contents.computeFinalSize(CompressedSize);
228 assert(
IsFilled &&
"SourceInfo::computeEntries() must be called before "
229 "SourceInfo::computeUncompressed()");
230 assert(CompressionType &&
"Compression type must be set.");
234 BaseData.Contents.computeUncompressed(*CompressionType);
244 for (
auto &E :
BaseData.Contents.Entries) {
253 switch (
BaseData.Contents.Parameters.Type) {
254 case dxbc::SourceInfo::Contents::CompressionType::Zlib: {
257 "compressed with Zlib, but ") +
266 OS.
write(
reinterpret_cast<char *
>(CompressedData.
data()),
267 CompressedData.
size());
271 case dxbc::SourceInfo::Contents::CompressionType::None: {
277 recomputeAfterCompression(CompressedSize);
282 "SourceInfo::finalize() must be called before SourceInfo::write()");
308 if (
BaseData.Contents.Parameters.EntriesSizeInBytes !=
311 "DXContainer SRCI Contents compressed size in header ({0} bytes) "
312 "doesn't match the actual compressed size ({1} bytes)",
313 BaseData.Contents.Parameters.EntriesSizeInBytes,
324 for (
auto &E : Args.Args) {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static uint64_t align(uint64_t Size)
static void clearAndReserve(VecT &Vec, size_t N)
static void writeString(raw_ostream &OS, StringRef S)
static void writeStruct(raw_ostream &OS, StructT S)
static void writePadding(raw_ostream &OS, uint64_t Prev)
This file defines the SmallString class.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
constexpr size_t size() const
Get the string size.
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
uint64_t tell() const
tell - Return the current offset with the file.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an SmallVector or SmallString.
LLVM_ABI void compress(ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &CompressedBuffer, int Level=DefaultCompression)
LLVM_ABI bool isAvailable()
constexpr int BestSizeCompression
LLVM_ABI const char * getReasonIfUnsupported(Format F)
static constexpr uint64_t DXCONTAINER_STRUCT_ALIGNMENT
uint16_t read16le(const void *P)
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
uint32_t read32le(const void *P)
constexpr bool IsBigEndianHost
This is an optimization pass for GlobalISel generic memory operations.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
uint32_t ContentSizeInBytes
Size of the file contents following this header, including the null terminator, excluding entry paddi...
StringRef CustomVersionString
void setCommitSha(StringRef CommitSha)
void setVersionString(StringRef VersionString)
void write(raw_ostream &OS) const
dxbc::CompilerVersionHeader Parameters
dxbc::DebugNameHeader Parameters
void setFilename(StringRef DebugFilename)
void write(raw_ostream &OS) const
SmallString< 128 > CompressedContents
void write(raw_ostream &OS) const
void compute()
Compute Parameters based on Args.
dxbc::SourceInfo::Args::Header Parameters
SmallVector< Entry > Args
void computeGenericHeader(uint32_t ContentSize, dxbc::SourceInfo::SectionType Type)
dxbc::SourceInfo::SectionHeader GenericHeader
void compute()
Compute Parameters based on FileContent.
dxbc::SourceInfo::Contents::Entry Parameters
void computeUncompressed(dxbc::SourceInfo::Contents::CompressionType Type)
Compute Parameters based on the content of Args.
SmallVector< Entry > Entries
void computeFinalSize(uint32_t CompressedSize)
Update Parameters based on the compressed size of section content.
dxbc::SourceInfo::Contents::Header Parameters
void compute(uint32_t ContentSize)
Compute Parameters based on FileName and FileContent.
dxbc::SourceInfo::Names::Entry Parameters
SmallVector< Entry > Entries
void compute()
Compute headers based on the content of entries.
void compute()
Compute Parameters based on the content of sections.
dxbc::SourceInfo::Header Parameters