1 //===- CodeViewYAMLTypeHashing.cpp - CodeView YAMLIO type hashing ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines classes for handling the YAML representation of CodeView
13 //===----------------------------------------------------------------------===//
15 #include "llvm/ObjectYAML/CodeViewYAMLTypeHashing.h"
16 #include "llvm/Support/BinaryByteStream.h"
17 #include "llvm/Support/BinaryStreamReader.h"
18 #include "llvm/Support/BinaryStreamWriter.h"
21 using namespace llvm::codeview;
22 using namespace llvm::CodeViewYAML;
23 using namespace llvm::yaml;
28 void MappingTraits<DebugHSection>::mapping(IO &io, DebugHSection &DebugH) {
29 io.mapRequired("Version", DebugH.Version);
30 io.mapRequired("HashAlgorithm", DebugH.HashAlgorithm);
31 io.mapOptional("HashValues", DebugH.Hashes);
34 void ScalarTraits<GlobalHash>::output(const GlobalHash &GH, void *Ctx,
36 ScalarTraits<BinaryRef>::output(GH.Hash, Ctx, OS);
39 StringRef ScalarTraits<GlobalHash>::input(StringRef Scalar, void *Ctx,
41 return ScalarTraits<BinaryRef>::input(Scalar, Ctx, GH.Hash);
44 } // end namespace yaml
45 } // end namespace llvm
47 DebugHSection llvm::CodeViewYAML::fromDebugH(ArrayRef<uint8_t> DebugH) {
48 assert(DebugH.size() >= 8);
49 assert((DebugH.size() - 8) % 20 == 0);
51 BinaryStreamReader Reader(DebugH, llvm::support::little);
53 cantFail(Reader.readInteger(DHS.Magic));
54 cantFail(Reader.readInteger(DHS.Version));
55 cantFail(Reader.readInteger(DHS.HashAlgorithm));
56 while (Reader.bytesRemaining() != 0) {
58 cantFail(Reader.readBytes(S, 20));
59 DHS.Hashes.emplace_back(S);
61 assert(Reader.bytesRemaining() == 0);
65 ArrayRef<uint8_t> llvm::CodeViewYAML::toDebugH(const DebugHSection &DebugH,
66 BumpPtrAllocator &Alloc) {
67 uint32_t Size = 8 + 20 * DebugH.Hashes.size();
68 uint8_t *Data = Alloc.Allocate<uint8_t>(Size);
69 MutableArrayRef<uint8_t> Buffer(Data, Size);
70 BinaryStreamWriter Writer(Buffer, llvm::support::little);
71 cantFail(Writer.writeInteger(DebugH.Magic));
72 cantFail(Writer.writeInteger(DebugH.Version));
73 cantFail(Writer.writeInteger(DebugH.HashAlgorithm));
75 for (const auto &H : DebugH.Hashes) {
77 raw_svector_ostream OS(Hash);
78 H.Hash.writeAsBinary(OS);
79 assert((Hash.size() == 20) && "Invalid hash size!");
80 cantFail(Writer.writeFixedString(Hash));
82 assert(Writer.bytesRemaining() == 0);