Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +0000 | [diff] [blame] | 1 | //===- ModuleDebugFileChecksumFragment.cpp ----------------------*- C++ -*-===// |
| 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 | #include "llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h" |
| 11 | |
| 12 | #include "llvm/DebugInfo/CodeView/CodeViewError.h" |
| 13 | #include "llvm/Support/BinaryStreamReader.h" |
| 14 | |
| 15 | using namespace llvm; |
| 16 | using namespace llvm::codeview; |
| 17 | |
| 18 | struct FileChecksumEntryHeader { |
| 19 | using ulittle32_t = support::ulittle32_t; |
| 20 | |
| 21 | ulittle32_t FileNameOffset; // Byte offset of filename in global string table. |
| 22 | uint8_t ChecksumSize; // Number of bytes of checksum. |
| 23 | uint8_t ChecksumKind; // FileChecksumKind |
| 24 | // Checksum bytes follow. |
| 25 | }; |
| 26 | |
| 27 | Error llvm::VarStreamArrayExtractor<FileChecksumEntry>::extract( |
| 28 | BinaryStreamRef Stream, uint32_t &Len, FileChecksumEntry &Item, void *Ctx) { |
| 29 | BinaryStreamReader Reader(Stream); |
| 30 | |
| 31 | const FileChecksumEntryHeader *Header; |
| 32 | if (auto EC = Reader.readObject(Header)) |
| 33 | return EC; |
| 34 | |
| 35 | Item.FileNameOffset = Header->FileNameOffset; |
| 36 | Item.Kind = static_cast<FileChecksumKind>(Header->ChecksumKind); |
| 37 | if (auto EC = Reader.readBytes(Item.Checksum, Header->ChecksumSize)) |
| 38 | return EC; |
| 39 | |
| 40 | Len = alignTo(Header->ChecksumSize + sizeof(FileChecksumEntryHeader), 4); |
| 41 | return Error::success(); |
| 42 | } |
| 43 | |
| 44 | Error ModuleDebugFileChecksumFragment::initialize(BinaryStreamReader Reader) { |
| 45 | if (auto EC = Reader.readArray(Checksums, Reader.bytesRemaining())) |
| 46 | return EC; |
| 47 | |
| 48 | return Error::success(); |
| 49 | } |