Path: blob/main/contrib/llvm-project/llvm/lib/DebugInfo/PDB/Native/HashTable.cpp
35293 views
//===- HashTable.cpp - PDB Hash Table -------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/DebugInfo/PDB/Native/HashTable.h"9#include "llvm/DebugInfo/PDB/Native/RawError.h"10#include "llvm/Support/BinaryStreamReader.h"11#include "llvm/Support/BinaryStreamWriter.h"12#include "llvm/Support/Error.h"13#include "llvm/Support/MathExtras.h"14#include <cstdint>15#include <utility>1617using namespace llvm;18using namespace llvm::pdb;1920Error llvm::pdb::readSparseBitVector(BinaryStreamReader &Stream,21SparseBitVector<> &V) {22uint32_t NumWords;23if (auto EC = Stream.readInteger(NumWords))24return joinErrors(25std::move(EC),26make_error<RawError>(raw_error_code::corrupt_file,27"Expected hash table number of words"));2829for (uint32_t I = 0; I != NumWords; ++I) {30uint32_t Word;31if (auto EC = Stream.readInteger(Word))32return joinErrors(std::move(EC),33make_error<RawError>(raw_error_code::corrupt_file,34"Expected hash table word"));35for (unsigned Idx = 0; Idx < 32; ++Idx)36if (Word & (1U << Idx))37V.set((I * 32) + Idx);38}39return Error::success();40}4142Error llvm::pdb::writeSparseBitVector(BinaryStreamWriter &Writer,43SparseBitVector<> &Vec) {44constexpr int BitsPerWord = 8 * sizeof(uint32_t);4546int ReqBits = Vec.find_last() + 1;47uint32_t ReqWords = alignTo(ReqBits, BitsPerWord) / BitsPerWord;48if (auto EC = Writer.writeInteger(ReqWords))49return joinErrors(50std::move(EC),51make_error<RawError>(raw_error_code::corrupt_file,52"Could not write linear map number of words"));5354uint32_t Idx = 0;55for (uint32_t I = 0; I != ReqWords; ++I) {56uint32_t Word = 0;57for (uint32_t WordIdx = 0; WordIdx < 32; ++WordIdx, ++Idx) {58if (Vec.test(Idx))59Word |= (1 << WordIdx);60}61if (auto EC = Writer.writeInteger(Word))62return joinErrors(std::move(EC), make_error<RawError>(63raw_error_code::corrupt_file,64"Could not write linear map word"));65}66return Error::success();67}686970