LLVM  14.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 
16 #include "llvm/BinaryFormat/COFF.h"
20 
21 using namespace llvm;
22 using namespace llvm::codeview;
23 using namespace llvm::CodeViewYAML;
24 using namespace llvm::yaml;
25 
26 namespace llvm {
27 namespace yaml {
28 
30  io.mapRequired("Version", DebugH.Version);
31  io.mapRequired("HashAlgorithm", DebugH.HashAlgorithm);
32  io.mapOptional("HashValues", DebugH.Hashes);
33 }
34 
35 void ScalarTraits<GlobalHash>::output(const GlobalHash &GH, void *Ctx,
36  raw_ostream &OS) {
38 }
39 
41  GlobalHash &GH) {
42  return ScalarTraits<BinaryRef>::input(Scalar, Ctx, GH.Hash);
43 }
44 
45 } // end namespace yaml
46 } // end namespace llvm
47 
49  assert(DebugH.size() >= 8);
50  assert((DebugH.size() - 8) % 8 == 0);
51 
53  DebugHSection DHS;
54  cantFail(Reader.readInteger(DHS.Magic));
55  cantFail(Reader.readInteger(DHS.Version));
56  cantFail(Reader.readInteger(DHS.HashAlgorithm));
57 
58  while (Reader.bytesRemaining() != 0) {
60  cantFail(Reader.readBytes(S, 8));
61  DHS.Hashes.emplace_back(S);
62  }
63  assert(Reader.bytesRemaining() == 0);
64  return DHS;
65 }
66 
68  BumpPtrAllocator &Alloc) {
69  uint32_t Size = 8 + 8 * DebugH.Hashes.size();
70  uint8_t *Data = Alloc.Allocate<uint8_t>(Size);
73 
74  cantFail(Writer.writeInteger(DebugH.Magic));
75  cantFail(Writer.writeInteger(DebugH.Version));
76  cantFail(Writer.writeInteger(DebugH.HashAlgorithm));
77  SmallString<8> Hash;
78  for (const auto &H : DebugH.Hashes) {
79  Hash.clear();
80  raw_svector_ostream OS(Hash);
81  H.Hash.writeAsBinary(OS);
82  assert((Hash.size() == 8) && "Invalid hash size!");
83  cantFail(Writer.writeFixedString(Hash));
84  }
85  assert(Writer.bytesRemaining() == 0);
86  return Buffer;
87 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
BinaryStreamReader.h
llvm::BinaryStreamReader::bytesRemaining
uint32_t bytesRemaining() const
Definition: BinaryStreamReader.h:257
llvm::CodeViewYAML::DebugHSection::Version
uint16_t Version
Definition: CodeViewYAMLTypeHashing.h:44
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::BinaryStreamWriter::writeInteger
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
Definition: BinaryStreamWriter.h:64
llvm::CodeViewYAML::GlobalHash
Definition: CodeViewYAMLTypeHashing.h:31
llvm::BinaryStreamReader::readBytes
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 ...
Definition: BinaryStreamReader.cpp:37
llvm::BinaryStreamWriter::writeFixedString
Error writeFixedString(StringRef Str)
Write the string Str to the underlying stream without a null terminator.
Definition: BinaryStreamWriter.cpp:56
BinaryByteStream.h
llvm::BinaryStreamWriter
Provides write only access to a subclass of WritableBinaryStream.
Definition: BinaryStreamWriter.h:31
output
Current output
Definition: README.txt:1350
COFF.h
llvm::yaml::MappingTraits
Definition: ModuleSummaryIndex.h:52
llvm::Data
@ Data
Definition: SIMachineScheduler.h:56
llvm::CodeViewYAML::DebugHSection::HashAlgorithm
uint16_t HashAlgorithm
Definition: CodeViewYAMLTypeHashing.h:45
llvm::MutableArrayRef< uint8_t >
llvm::BumpPtrAllocatorImpl::Allocate
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:145
llvm::support::little
@ little
Definition: Endian.h:27
llvm::BinaryStreamWriter::bytesRemaining
uint32_t bytesRemaining() const
Definition: BinaryStreamWriter.h:186
CodeViewYAMLTypeHashing.h
llvm::CodeViewYAML::DebugHSection::Magic
uint32_t Magic
Definition: CodeViewYAMLTypeHashing.h:43
llvm::BinaryStreamReader::readInteger
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream's offset.
Definition: BinaryStreamReader.h:75
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
input
The initial backend is deliberately restricted to z10 We should add support for later architectures at some point If an asm ties an i32 r result to an i64 input
Definition: README.txt:10
llvm::SmallString< 8 >
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:31
llvm::CodeViewYAML::DebugHSection::Hashes
std::vector< GlobalHash > Hashes
Definition: CodeViewYAMLTypeHashing.h:46
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::CodeViewYAML
Definition: CodeViewYAMLDebugSections.h:37
llvm::CodeViewYAML::toDebugH
ArrayRef< uint8_t > toDebugH(const DebugHSection &DebugH, BumpPtrAllocator &Alloc)
Definition: CodeViewYAMLTypeHashing.cpp:67
llvm::CodeViewYAML::fromDebugH
DebugHSection fromDebugH(ArrayRef< uint8_t > DebugH)
Definition: CodeViewYAMLTypeHashing.cpp:48
llvm::ArrayRef< uint8_t >
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::cantFail
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:737
uint32_t
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
H
#define H(x, y, z)
Definition: MD5.cpp:58
llvm::CodeViewYAML::DebugHSection
Definition: CodeViewYAMLTypeHashing.h:42
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:585
llvm::yaml
Definition: MIRYamlMapping.h:30
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:656
BinaryStreamWriter.h
llvm::CodeViewYAML::GlobalHash::Hash
yaml::BinaryRef Hash
Definition: CodeViewYAMLTypeHashing.h:39