Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/ObjectYAML/CodeViewYAMLTypeHashing.cpp
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
} // end namespace llvm | } // end namespace llvm | ||||
DebugHSection llvm::CodeViewYAML::fromDebugH(ArrayRef<uint8_t> DebugH) { | DebugHSection llvm::CodeViewYAML::fromDebugH(ArrayRef<uint8_t> DebugH) { | ||||
assert(DebugH.size() >= 8); | assert(DebugH.size() >= 8); | ||||
assert((DebugH.size() - 8) % 8 == 0); | assert((DebugH.size() - 8) % 8 == 0); | ||||
BinaryStreamReader Reader(DebugH, llvm::support::little); | BinaryStreamReader Reader(DebugH, llvm::support::little); | ||||
DebugHSection DHS; | DebugHSection DHS; | ||||
cantFail(Reader.readInteger(DHS.Magic)); | llvm_cantFail(Reader.readInteger(DHS.Magic)); | ||||
cantFail(Reader.readInteger(DHS.Version)); | llvm_cantFail(Reader.readInteger(DHS.Version)); | ||||
cantFail(Reader.readInteger(DHS.HashAlgorithm)); | llvm_cantFail(Reader.readInteger(DHS.HashAlgorithm)); | ||||
while (Reader.bytesRemaining() != 0) { | while (Reader.bytesRemaining() != 0) { | ||||
ArrayRef<uint8_t> S; | ArrayRef<uint8_t> S; | ||||
cantFail(Reader.readBytes(S, 8)); | llvm_cantFail(Reader.readBytes(S, 8)); | ||||
DHS.Hashes.emplace_back(S); | DHS.Hashes.emplace_back(S); | ||||
} | } | ||||
assert(Reader.bytesRemaining() == 0); | assert(Reader.bytesRemaining() == 0); | ||||
return DHS; | return DHS; | ||||
} | } | ||||
ArrayRef<uint8_t> llvm::CodeViewYAML::toDebugH(const DebugHSection &DebugH, | ArrayRef<uint8_t> llvm::CodeViewYAML::toDebugH(const DebugHSection &DebugH, | ||||
BumpPtrAllocator &Alloc) { | BumpPtrAllocator &Alloc) { | ||||
uint32_t Size = 8 + 8 * DebugH.Hashes.size(); | uint32_t Size = 8 + 8 * DebugH.Hashes.size(); | ||||
uint8_t *Data = Alloc.Allocate<uint8_t>(Size); | uint8_t *Data = Alloc.Allocate<uint8_t>(Size); | ||||
MutableArrayRef<uint8_t> Buffer(Data, Size); | MutableArrayRef<uint8_t> Buffer(Data, Size); | ||||
BinaryStreamWriter Writer(Buffer, llvm::support::little); | BinaryStreamWriter Writer(Buffer, llvm::support::little); | ||||
cantFail(Writer.writeInteger(DebugH.Magic)); | llvm_cantFail(Writer.writeInteger(DebugH.Magic)); | ||||
cantFail(Writer.writeInteger(DebugH.Version)); | llvm_cantFail(Writer.writeInteger(DebugH.Version)); | ||||
cantFail(Writer.writeInteger(DebugH.HashAlgorithm)); | llvm_cantFail(Writer.writeInteger(DebugH.HashAlgorithm)); | ||||
SmallString<8> Hash; | SmallString<8> Hash; | ||||
for (const auto &H : DebugH.Hashes) { | for (const auto &H : DebugH.Hashes) { | ||||
Hash.clear(); | Hash.clear(); | ||||
raw_svector_ostream OS(Hash); | raw_svector_ostream OS(Hash); | ||||
H.Hash.writeAsBinary(OS); | H.Hash.writeAsBinary(OS); | ||||
assert((Hash.size() == 8) && "Invalid hash size!"); | assert((Hash.size() == 8) && "Invalid hash size!"); | ||||
cantFail(Writer.writeFixedString(Hash)); | llvm_cantFail(Writer.writeFixedString(Hash)); | ||||
} | } | ||||
assert(Writer.bytesRemaining() == 0); | assert(Writer.bytesRemaining() == 0); | ||||
return Buffer; | return Buffer; | ||||
} | } |