Changeset View
Changeset View
Standalone View
Standalone View
include/llvm/Bitcode/BitstreamWriter.h
Show All 15 Lines | |||||
#define LLVM_BITCODE_BITSTREAMWRITER_H | #define LLVM_BITCODE_BITSTREAMWRITER_H | ||||
#include "llvm/ADT/ArrayRef.h" | #include "llvm/ADT/ArrayRef.h" | ||||
#include "llvm/ADT/Optional.h" | #include "llvm/ADT/Optional.h" | ||||
#include "llvm/ADT/SmallVector.h" | #include "llvm/ADT/SmallVector.h" | ||||
#include "llvm/ADT/StringRef.h" | #include "llvm/ADT/StringRef.h" | ||||
#include "llvm/Bitcode/BitCodes.h" | #include "llvm/Bitcode/BitCodes.h" | ||||
#include "llvm/Support/Endian.h" | #include "llvm/Support/Endian.h" | ||||
#include "llvm/Support/SHA1.h" | |||||
#include <vector> | #include <vector> | ||||
namespace llvm { | namespace llvm { | ||||
class BitstreamWriter { | class BitstreamWriter { | ||||
SmallVectorImpl<char> &Out; | SmallVectorImpl<char> &Out; | ||||
/// CurBit - Always between 0 and 31 inclusive, specifies the next bit to use. | /// CurBit - Always between 0 and 31 inclusive, specifies the next bit to use. | ||||
unsigned CurBit; | unsigned CurBit; | ||||
/// CurValue - The current value. Only bits < CurBit are valid. | /// CurValue - The current value. Only bits < CurBit are valid. | ||||
uint32_t CurValue; | uint32_t CurValue; | ||||
/// CurCodeSize - This is the declared size of code values used for the | /// CurCodeSize - This is the declared size of code values used for the | ||||
/// current block, in bits. | /// current block, in bits. | ||||
unsigned CurCodeSize; | unsigned CurCodeSize; | ||||
/// BlockInfoCurBID - When emitting a BLOCKINFO_BLOCK, this is the currently | /// BlockInfoCurBID - When emitting a BLOCKINFO_BLOCK, this is the currently | ||||
/// selected BLOCK ID. | /// selected BLOCK ID. | ||||
unsigned BlockInfoCurBID; | unsigned BlockInfoCurBID; | ||||
/// The writer has the ability to compute the hash of the stream on the fly. | |||||
SHA1 Hash; | |||||
/// Flag to mark the hashing enabled/disabled. | |||||
bool HashEnabled; | |||||
/// CurAbbrevs - Abbrevs installed at in this block. | /// CurAbbrevs - Abbrevs installed at in this block. | ||||
std::vector<IntrusiveRefCntPtr<BitCodeAbbrev>> CurAbbrevs; | std::vector<IntrusiveRefCntPtr<BitCodeAbbrev>> CurAbbrevs; | ||||
struct Block { | struct Block { | ||||
unsigned PrevCodeSize; | unsigned PrevCodeSize; | ||||
size_t StartSizeWord; | size_t StartSizeWord; | ||||
std::vector<IntrusiveRefCntPtr<BitCodeAbbrev>> PrevAbbrevs; | std::vector<IntrusiveRefCntPtr<BitCodeAbbrev>> PrevAbbrevs; | ||||
Block(unsigned PCS, size_t SSW) : PrevCodeSize(PCS), StartSizeWord(SSW) {} | Block(unsigned PCS, size_t SSW) : PrevCodeSize(PCS), StartSizeWord(SSW) {} | ||||
Show All 11 Lines | class BitstreamWriter { | ||||
std::vector<BlockInfo> BlockInfoRecords; | std::vector<BlockInfo> BlockInfoRecords; | ||||
void WriteByte(unsigned char Value) { | void WriteByte(unsigned char Value) { | ||||
Out.push_back(Value); | Out.push_back(Value); | ||||
} | } | ||||
void WriteWord(unsigned Value) { | void WriteWord(unsigned Value) { | ||||
Value = support::endian::byte_swap<uint32_t, support::little>(Value); | Value = support::endian::byte_swap<uint32_t, support::little>(Value); | ||||
if (HashEnabled) | |||||
Hash.write(reinterpret_cast<const char *>(&Value), sizeof(Value)); | |||||
Out.append(reinterpret_cast<const char *>(&Value), | Out.append(reinterpret_cast<const char *>(&Value), | ||||
reinterpret_cast<const char *>(&Value + 1)); | reinterpret_cast<const char *>(&Value + 1)); | ||||
} | } | ||||
size_t GetBufferOffset() const { return Out.size(); } | size_t GetBufferOffset() const { return Out.size(); } | ||||
size_t GetWordIndex() const { | size_t GetWordIndex() const { | ||||
size_t Offset = GetBufferOffset(); | size_t Offset = GetBufferOffset(); | ||||
Show All 11 Lines | public: | ||||
} | } | ||||
/// \brief Retrieve the current position in the stream, in bits. | /// \brief Retrieve the current position in the stream, in bits. | ||||
uint64_t GetCurrentBitNo() const { return GetBufferOffset() * 8 + CurBit; } | uint64_t GetCurrentBitNo() const { return GetBufferOffset() * 8 + CurBit; } | ||||
/// \brief Retrieve the number of bits currently used to encode an abbrev ID. | /// \brief Retrieve the number of bits currently used to encode an abbrev ID. | ||||
unsigned GetAbbrevIDWidth() const { return CurCodeSize; } | unsigned GetAbbrevIDWidth() const { return CurCodeSize; } | ||||
/// Enable (and reset) the hashing | |||||
void enableHash(bool Enabled) { | |||||
HashEnabled = Enabled; | |||||
Hash.init(); | |||||
} | |||||
StringRef getCurrentHash() { return Hash.result(); } | |||||
//===--------------------------------------------------------------------===// | //===--------------------------------------------------------------------===// | ||||
// Basic Primitives for emitting bits to the stream. | // Basic Primitives for emitting bits to the stream. | ||||
//===--------------------------------------------------------------------===// | //===--------------------------------------------------------------------===// | ||||
/// Backpatch a 32-bit word in the output at the given bit offset | /// Backpatch a 32-bit word in the output at the given bit offset | ||||
/// with the specified value. | /// with the specified value. | ||||
void BackpatchWord(uint64_t BitNo, unsigned NewWord) { | void BackpatchWord(uint64_t BitNo, unsigned NewWord) { | ||||
using namespace llvm::support; | using namespace llvm::support; | ||||
▲ Show 20 Lines • Show All 442 Lines • Show Last 20 Lines |