[debug] Use poison instead of undef to set a killed dbg.assign address [NFC] (#119760)
[llvm-project.git] / llvm / lib / ObjectYAML / CodeViewYAMLTypeHashing.cpp
blob980e5b6a790e33acf4258369103f59e34f1a14fd
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.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/ObjectYAML/CodeViewYAMLTypeHashing.h"
16 #include "llvm/Support/BinaryStreamReader.h"
17 #include "llvm/Support/BinaryStreamWriter.h"
19 using namespace llvm;
20 using namespace llvm::codeview;
21 using namespace llvm::CodeViewYAML;
22 using namespace llvm::yaml;
24 namespace llvm {
25 namespace yaml {
27 void 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);
33 void ScalarTraits<GlobalHash>::output(const GlobalHash &GH, void *Ctx,
34 raw_ostream &OS) {
35 ScalarTraits<BinaryRef>::output(GH.Hash, Ctx, OS);
38 StringRef ScalarTraits<GlobalHash>::input(StringRef Scalar, void *Ctx,
39 GlobalHash &GH) {
40 return ScalarTraits<BinaryRef>::input(Scalar, Ctx, GH.Hash);
43 } // end namespace yaml
44 } // end namespace llvm
46 DebugHSection llvm::CodeViewYAML::fromDebugH(ArrayRef<uint8_t> DebugH) {
47 assert(DebugH.size() >= 8);
48 assert((DebugH.size() - 8) % 8 == 0);
50 BinaryStreamReader Reader(DebugH, llvm::endianness::little);
51 DebugHSection DHS;
52 cantFail(Reader.readInteger(DHS.Magic));
53 cantFail(Reader.readInteger(DHS.Version));
54 cantFail(Reader.readInteger(DHS.HashAlgorithm));
56 while (Reader.bytesRemaining() != 0) {
57 ArrayRef<uint8_t> S;
58 cantFail(Reader.readBytes(S, 8));
59 DHS.Hashes.emplace_back(S);
61 assert(Reader.bytesRemaining() == 0);
62 return DHS;
65 ArrayRef<uint8_t> llvm::CodeViewYAML::toDebugH(const DebugHSection &DebugH,
66 BumpPtrAllocator &Alloc) {
67 uint32_t Size = 8 + 8 * DebugH.Hashes.size();
68 uint8_t *Data = Alloc.Allocate<uint8_t>(Size);
69 MutableArrayRef<uint8_t> Buffer(Data, Size);
70 BinaryStreamWriter Writer(Buffer, llvm::endianness::little);
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));
83 assert(Writer.bytesRemaining() == 0);
84 return Buffer;