LLVM 22.0.0git
CodeViewYAMLTypeHashing.cpp
Go to the documentation of this file.
1//===- CodeViewYAMLTypeHashing.cpp - CodeView YAMLIO type hashing ---------===//
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// This file defines classes for handling the YAML representation of CodeView
10// Debug Info.
11//
12//===----------------------------------------------------------------------===//
13
15
18
19using namespace llvm;
20using namespace llvm::codeview;
21using namespace llvm::CodeViewYAML;
22using namespace llvm::yaml;
23
24namespace llvm {
25namespace yaml {
26
27void MappingTraits<DebugHSection>::mapping(IO &io, DebugHSection &DebugH) {
28 io.mapRequired("Version", DebugH.Version);
29 io.mapRequired("HashAlgorithm", DebugH.HashAlgorithm);
30 io.mapOptional("HashValues", DebugH.Hashes);
31}
32
33void ScalarTraits<GlobalHash>::output(const GlobalHash &GH, void *Ctx,
34 raw_ostream &OS) {
36}
37
38StringRef ScalarTraits<GlobalHash>::input(StringRef Scalar, void *Ctx,
39 GlobalHash &GH) {
41}
42
43} // end namespace yaml
44} // end namespace llvm
45
47 assert(DebugH.size() >= 8);
48 assert((DebugH.size() - 8) % 8 == 0);
49
51 DebugHSection DHS;
52 cantFail(Reader.readInteger(DHS.Magic));
53 cantFail(Reader.readInteger(DHS.Version));
55
56 while (Reader.bytesRemaining() != 0) {
58 cantFail(Reader.readBytes(S, 8));
59 DHS.Hashes.emplace_back(S);
60 }
61 assert(Reader.bytesRemaining() == 0);
62 return DHS;
63}
64
67 uint32_t Size = 8 + 8 * DebugH.Hashes.size();
68 uint8_t *Data = Alloc.Allocate<uint8_t>(Size);
71
72 cantFail(Writer.writeInteger(DebugH.Magic));
73 cantFail(Writer.writeInteger(DebugH.Version));
74 cantFail(Writer.writeInteger(DebugH.HashAlgorithm));
75 SmallString<8> Hash;
76 for (const auto &H : DebugH.Hashes) {
77 Hash.clear();
78 raw_svector_ostream OS(Hash);
79 H.Hash.writeAsBinary(OS);
80 assert((Hash.size() == 8) && "Invalid hash size!");
81 cantFail(Writer.writeFixedString(Hash));
82 }
83 assert(Writer.bytesRemaining() == 0);
84 return Buffer;
85}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define H(x, y, z)
Definition MD5.cpp:57
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition ArrayRef.h:147
Provides read only access to a subclass of BinaryStream.
LLVM_ABI Error readBytes(ArrayRef< uint8_t > &Buffer, uint32_t Size)
Read Size bytes from the underlying stream at the current offset and and set Buffer to the resulting ...
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream's offset.
Provides write only access to a subclass of WritableBinaryStream.
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
LLVM_ABI Error writeFixedString(StringRef Str)
Write the string Str to the underlying stream without a null terminator.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition ArrayRef.h:303
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
A raw_ostream that writes to an SmallVector or SmallString.
void mapOptional(const char *Key, T &Val)
Definition YAMLTraits.h:810
void mapRequired(const char *Key, T &Val)
Definition YAMLTraits.h:800
ArrayRef< uint8_t > toDebugH(const DebugHSection &DebugH, BumpPtrAllocator &Alloc)
DebugHSection fromDebugH(ArrayRef< uint8_t > DebugH)
This is an optimization pass for GlobalISel generic memory operations.
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition Error.h:769
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
Definition YAMLTraits.h:62
This class should be specialized by type that requires custom conversion to/from a yaml scalar.
Definition YAMLTraits.h:149