Eugene Zelenko | 4fcfc19 | 2017-06-30 23:06:03 +0000 | [diff] [blame] | 1 | //===- HashTable.cpp - PDB Hash Table -------------------------------------===// |
Zachary Turner | 11036a9 | 2017-01-19 23:31:24 +0000 | [diff] [blame] | 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 | |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 10 | #include "llvm/DebugInfo/PDB/Native/HashTable.h" |
Zachary Turner | 11036a9 | 2017-01-19 23:31:24 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/Optional.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/PDB/Native/RawError.h" |
Eugene Zelenko | 4fcfc19 | 2017-06-30 23:06:03 +0000 | [diff] [blame] | 13 | #include "llvm/Support/BinaryStreamReader.h" |
| 14 | #include "llvm/Support/BinaryStreamWriter.h" |
| 15 | #include "llvm/Support/Error.h" |
| 16 | #include "llvm/Support/MathExtras.h" |
| 17 | #include <algorithm> |
| 18 | #include <cassert> |
| 19 | #include <cstdint> |
| 20 | #include <utility> |
Zachary Turner | a332fa3 | 2017-01-19 23:44:14 +0000 | [diff] [blame] | 21 | |
Zachary Turner | 11036a9 | 2017-01-19 23:31:24 +0000 | [diff] [blame] | 22 | using namespace llvm; |
| 23 | using namespace llvm::pdb; |
| 24 | |
Zachary Turner | ebf03f6 | 2018-03-15 17:38:26 +0000 | [diff] [blame] | 25 | Error llvm::pdb::readSparseBitVector(BinaryStreamReader &Stream, |
Zachary Turner | 11036a9 | 2017-01-19 23:31:24 +0000 | [diff] [blame] | 26 | SparseBitVector<> &V) { |
| 27 | uint32_t NumWords; |
Zachary Turner | 695ed56 | 2017-02-28 00:04:07 +0000 | [diff] [blame] | 28 | if (auto EC = Stream.readInteger(NumWords)) |
Zachary Turner | 11036a9 | 2017-01-19 23:31:24 +0000 | [diff] [blame] | 29 | return joinErrors( |
| 30 | std::move(EC), |
| 31 | make_error<RawError>(raw_error_code::corrupt_file, |
| 32 | "Expected hash table number of words")); |
| 33 | |
| 34 | for (uint32_t I = 0; I != NumWords; ++I) { |
| 35 | uint32_t Word; |
Zachary Turner | 695ed56 | 2017-02-28 00:04:07 +0000 | [diff] [blame] | 36 | if (auto EC = Stream.readInteger(Word)) |
Zachary Turner | 11036a9 | 2017-01-19 23:31:24 +0000 | [diff] [blame] | 37 | return joinErrors(std::move(EC), |
| 38 | make_error<RawError>(raw_error_code::corrupt_file, |
| 39 | "Expected hash table word")); |
| 40 | for (unsigned Idx = 0; Idx < 32; ++Idx) |
| 41 | if (Word & (1U << Idx)) |
| 42 | V.set((I * 32) + Idx); |
| 43 | } |
| 44 | return Error::success(); |
| 45 | } |
| 46 | |
Zachary Turner | ebf03f6 | 2018-03-15 17:38:26 +0000 | [diff] [blame] | 47 | Error llvm::pdb::writeSparseBitVector(BinaryStreamWriter &Writer, |
Zachary Turner | 11036a9 | 2017-01-19 23:31:24 +0000 | [diff] [blame] | 48 | SparseBitVector<> &Vec) { |
| 49 | int ReqBits = Vec.find_last() + 1; |
| 50 | uint32_t NumWords = alignTo(ReqBits, sizeof(uint32_t)) / sizeof(uint32_t); |
Zachary Turner | 695ed56 | 2017-02-28 00:04:07 +0000 | [diff] [blame] | 51 | if (auto EC = Writer.writeInteger(NumWords)) |
Zachary Turner | 11036a9 | 2017-01-19 23:31:24 +0000 | [diff] [blame] | 52 | return joinErrors( |
| 53 | std::move(EC), |
| 54 | make_error<RawError>(raw_error_code::corrupt_file, |
| 55 | "Could not write linear map number of words")); |
| 56 | |
| 57 | uint32_t Idx = 0; |
| 58 | for (uint32_t I = 0; I != NumWords; ++I) { |
| 59 | uint32_t Word = 0; |
| 60 | for (uint32_t WordIdx = 0; WordIdx < 32; ++WordIdx, ++Idx) { |
| 61 | if (Vec.test(Idx)) |
| 62 | Word |= (1 << WordIdx); |
| 63 | } |
Zachary Turner | 695ed56 | 2017-02-28 00:04:07 +0000 | [diff] [blame] | 64 | if (auto EC = Writer.writeInteger(Word)) |
Zachary Turner | 11036a9 | 2017-01-19 23:31:24 +0000 | [diff] [blame] | 65 | return joinErrors(std::move(EC), make_error<RawError>( |
| 66 | raw_error_code::corrupt_file, |
| 67 | "Could not write linear map word")); |
| 68 | } |
| 69 | return Error::success(); |
| 70 | } |