LLVM 20.0.0git
DebugSubsectionRecord.cpp
Go to the documentation of this file.
1//===- DebugSubsectionRecord.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
14#include "llvm/Support/Error.h"
16#include <cassert>
17#include <cstdint>
18
19using namespace llvm;
20using namespace llvm::codeview;
21
23
25 BinaryStreamRef Data)
26 : Kind(Kind), Data(Data) {}
27
30 const DebugSubsectionHeader *Header;
31 BinaryStreamReader Reader(Stream);
32 if (auto EC = Reader.readObject(Header))
33 return EC;
34
36 static_cast<DebugSubsectionKind>(uint32_t(Header->Kind));
37 if (auto EC = Reader.readStreamRef(Info.Data, Header->Length))
38 return EC;
39 Info.Kind = Kind;
40 return Error::success();
41}
42
44 return sizeof(DebugSubsectionHeader) + Data.getLength();
45}
46
48
50
52 std::shared_ptr<DebugSubsection> Subsection)
53 : Subsection(std::move(Subsection)) {}
54
56 const DebugSubsectionRecord &Contents)
57 : Contents(Contents) {}
58
60 uint32_t DataSize = Subsection ? Subsection->calculateSerializedSize()
61 : Contents.getRecordData().getLength();
62 // The length of the entire subsection is always padded to 4 bytes,
63 // regardless of the container kind.
64 return sizeof(DebugSubsectionHeader) + alignTo(DataSize, 4);
65}
66
68 CodeViewContainer Container) const {
69 assert(Writer.getOffset() % alignOf(Container) == 0 &&
70 "Debug Subsection not properly aligned");
71
73 Header.Kind = uint32_t(Subsection ? Subsection->kind() : Contents.kind());
74 // The value written into the Header's Length field is only padded to the
75 // container's alignment
76 uint32_t DataSize = Subsection ? Subsection->calculateSerializedSize()
77 : Contents.getRecordData().getLength();
78 Header.Length = alignTo(DataSize, alignOf(Container));
79
80 if (auto EC = Writer.writeObject(Header))
81 return EC;
82 if (Subsection) {
83 if (auto EC = Subsection->commit(Writer))
84 return EC;
85 } else {
86 if (auto EC = Writer.writeStreamRef(Contents.getRecordData()))
87 return EC;
88 }
89 if (auto EC = Writer.padToAlignment(4))
90 return EC;
91
92 return Error::success();
93}
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Provides read only access to a subclass of BinaryStream.
Error readStreamRef(BinaryStreamRef &Ref)
Read the entire remainder of the underlying stream into Ref.
Error readObject(const T *&Dest)
Get a pointer to an object of type T from the underlying stream, as if by memcpy, and store the resul...
uint64_t getLength() const
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Provides write only access to a subclass of WritableBinaryStream.
Error writeStreamRef(BinaryStreamRef Ref)
Efficiently reads all data from Ref, and writes it to this stream.
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
Error padToAlignment(uint32_t Align)
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
Error commit(BinaryStreamWriter &Writer, CodeViewContainer Container) const
DebugSubsectionRecordBuilder(std::shared_ptr< DebugSubsection > Subsection)
static Error initialize(BinaryStreamRef Stream, DebugSubsectionRecord &Info)
uint32_t alignOf(CodeViewContainer Container)
Definition: CodeView.h:621
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1856
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858