LLVM  8.0.1
CodeViewYAMLTypeHashing.cpp
Go to the documentation of this file.
1 //===- CodeViewYAMLTypeHashing.cpp - CodeView YAMLIO type hashing ---------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines classes for handling the YAML representation of CodeView
11 // Debug Info.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 
17 #include "llvm/BinaryFormat/COFF.h"
21 
22 using namespace llvm;
23 using namespace llvm::codeview;
24 using namespace llvm::CodeViewYAML;
25 using namespace llvm::yaml;
26 
27 namespace llvm {
28 namespace yaml {
29 
31  io.mapRequired("Version", DebugH.Version);
32  io.mapRequired("HashAlgorithm", DebugH.HashAlgorithm);
33  io.mapOptional("HashValues", DebugH.Hashes);
34 }
35 
36 void ScalarTraits<GlobalHash>::output(const GlobalHash &GH, void *Ctx,
37  raw_ostream &OS) {
38  ScalarTraits<BinaryRef>::output(GH.Hash, Ctx, OS);
39 }
40 
41 StringRef ScalarTraits<GlobalHash>::input(StringRef Scalar, void *Ctx,
42  GlobalHash &GH) {
43  return ScalarTraits<BinaryRef>::input(Scalar, Ctx, GH.Hash);
44 }
45 
46 } // end namespace yaml
47 } // end namespace llvm
48 
50  assert(DebugH.size() >= 8);
51  assert((DebugH.size() - 8) % 8 == 0);
52 
54  DebugHSection DHS;
55  cantFail(Reader.readInteger(DHS.Magic));
56  cantFail(Reader.readInteger(DHS.Version));
57  cantFail(Reader.readInteger(DHS.HashAlgorithm));
58 
59  while (Reader.bytesRemaining() != 0) {
61  cantFail(Reader.readBytes(S, 8));
62  DHS.Hashes.emplace_back(S);
63  }
64  assert(Reader.bytesRemaining() == 0);
65  return DHS;
66 }
67 
69  BumpPtrAllocator &Alloc) {
70  uint32_t Size = 8 + 8 * DebugH.Hashes.size();
71  uint8_t *Data = Alloc.Allocate<uint8_t>(Size);
72  MutableArrayRef<uint8_t> Buffer(Data, Size);
74 
75  cantFail(Writer.writeInteger(DebugH.Magic));
76  cantFail(Writer.writeInteger(DebugH.Version));
77  cantFail(Writer.writeInteger(DebugH.HashAlgorithm));
78  SmallString<8> Hash;
79  for (const auto &H : DebugH.Hashes) {
80  Hash.clear();
81  raw_svector_ostream OS(Hash);
82  H.Hash.writeAsBinary(OS);
83  assert((Hash.size() == 8) && "Invalid hash size!");
84  cantFail(Writer.writeFixedString(Hash));
85  }
86  assert(Writer.bytesRemaining() == 0);
87  return Buffer;
88 }
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:704
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream&#39;s offset.
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:510
Error writeFixedString(StringRef Str)
Write the string Str to the underlying stream without a null terminator.
ArrayRef< uint8_t > toDebugH(const DebugHSection &DebugH, BumpPtrAllocator &Alloc)
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:141
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:215
#define H(x, y, z)
Definition: MD5.cpp:57
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.
uint32_t bytesRemaining() const
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 ...
uint32_t Size
Definition: Profile.cpp:47
DebugHSection fromDebugH(ArrayRef< uint8_t > DebugH)
uint32_t bytesRemaining() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
Provides read only access to a subclass of BinaryStream.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49