LLVM 23.0.0git
DXContainerInfo.cpp
Go to the documentation of this file.
1//===- llvm/MC/DXContainerInfo.cpp - DXContainer Info -----*- C++ -------*-===//
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
12#include "llvm/Config/config.h"
14#include "llvm/Support/VCSRevision.h"
15#include <type_traits>
16
17using namespace llvm;
18using namespace llvm::mcdxbc;
19
20template <typename StructT>
21static void writeStruct(raw_ostream &OS, StructT S) {
22 static_assert(std::is_class<StructT>() &&
23 "This method must be used for writing structure types");
25 S.swapBytes();
26 OS.write(reinterpret_cast<const char *>(&S), sizeof(StructT));
27}
28
29static void writeString(raw_ostream &OS, StringRef S) {
30 OS.write(S.data(), S.size());
31 // Write null terminator.
32 OS.write_zeros(1);
33}
34
35void DebugName::setFilename(StringRef DebugFilename) {
36 Parameters.NameLength = DebugFilename.size();
37 Filename = DebugFilename;
38}
39
42 writeString(OS, Filename.substr(0, Parameters.NameLength));
43}
44
46 Parameters.Major = LLVM_VERSION_MAJOR;
47 Parameters.Minor = LLVM_VERSION_MINOR;
48 Parameters.Flags = dxbc::CompilerVersionFlags::Default;
49#ifndef NDEBUG
50 Parameters.Flags |= dxbc::CompilerVersionFlags::Debug;
51#endif
52 Parameters.CommitCount = 0;
53 Parameters.ContentSizeInBytes = 0;
54#ifdef LLVM_REVISION
55 CommitSha = LLVM_REVISION;
56#else
57 CommitSha = "";
58#endif
59 CustomVersionString = PACKAGE_VERSION;
60 updateContentSize();
61}
62
64 this->CommitSha = CommitSha;
65 updateContentSize();
66}
67
69 this->CustomVersionString = VersionString;
70 updateContentSize();
71}
72
73void CompilerVersion::updateContentSize() {
76}
77
80 SmallString<64> Content;
81 raw_svector_ostream ContentStream(Content);
82 writeString(ContentStream, CommitSha);
83 writeString(ContentStream, CustomVersionString);
84 Content.resize(Parameters.ContentSizeInBytes);
85 OS.write(Content.data(), Parameters.ContentSizeInBytes);
86}
static void writeString(raw_ostream &OS, StringRef S)
static void writeStruct(raw_ostream &OS, StructT S)
This file defines the SmallString class.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
void resize(size_type N)
pointer data()
Return a pointer to the vector's buffer, even if empty().
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:138
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an SmallVector or SmallString.
constexpr bool IsBigEndianHost
This is an optimization pass for GlobalISel generic memory operations.
uint32_t ContentSizeInBytes
Byte size of CommitSha and CustomVersionString, padding not included.
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