From: Chris Lattner Date: Sun, 26 Apr 2009 21:07:02 +0000 (+0000) Subject: make BitstreamCursor's copyable and assignable. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=7919b966a8fd8f98346216e79df6f4722693be22;p=oota-llvm.git make BitstreamCursor's copyable and assignable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70159 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Bitcode/BitstreamReader.h b/include/llvm/Bitcode/BitstreamReader.h index ae18f2c57b3..d2489d19ac4 100644 --- a/include/llvm/Bitcode/BitstreamReader.h +++ b/include/llvm/Bitcode/BitstreamReader.h @@ -71,6 +71,11 @@ public: // Block Manipulation //===--------------------------------------------------------------------===// + /// hasBlockInfoRecords - Return true if we've already read and processed the + /// block info block for this Bitstream. We only process it for the first + /// cursor that walks over it. + bool hasBlockInfoRecords() const { return !BlockInfoRecords.empty(); } + /// getBlockInfo - If there is block info for the specified ID, return it, /// otherwise return null. BlockInfo *getBlockInfo(unsigned BlockID) { @@ -126,11 +131,13 @@ class BitstreamCursor { /// BlockScope - This tracks the codesize of parent blocks. SmallVector BlockScope; - BitstreamCursor(const BitstreamCursor&); // NOT YET IMPLEMENTED. - void operator=(const BitstreamCursor&); // NOT YET IMPLEMENTED. public: BitstreamCursor() : BitStream(0), NextChar(0) { } + BitstreamCursor(const BitstreamCursor &RHS) : BitStream(0), NextChar(0) { + operator=(RHS); + } + explicit BitstreamCursor(BitstreamReader &R) : BitStream(&R) { NextChar = R.getFirstChar(); assert(NextChar && "Bitstream not initialized yet"); @@ -154,6 +161,31 @@ public: freeState(); } + void operator=(const BitstreamCursor &RHS) { + freeState(); + + BitStream = RHS.BitStream; + NextChar = RHS.NextChar; + CurWord = RHS.CurWord; + BitsInCurWord = RHS.BitsInCurWord; + CurCodeSize = RHS.CurCodeSize; + + // Copy abbreviations, and bump ref counts. + CurAbbrevs = RHS.CurAbbrevs; + for (unsigned i = 0, e = static_cast(CurAbbrevs.size()); + i != e; ++i) + CurAbbrevs[i]->addRef(); + + // Copy block scope and bump ref counts. + for (unsigned S = 0, e = static_cast(BlockScope.size()); + S != e; ++S) { + std::vector &Abbrevs = BlockScope[S].PrevAbbrevs; + for (unsigned i = 0, e = static_cast(Abbrevs.size()); + i != e; ++i) + Abbrevs[i]->addRef(); + } + } + void freeState() { // Free all the Abbrevs. for (unsigned i = 0, e = static_cast(CurAbbrevs.size()); @@ -512,6 +544,10 @@ public: public: bool ReadBlockInfoBlock() { + // If this is the second stream to get to the block info block, skip it. + if (BitStream->hasBlockInfoRecords()) + return SkipBlock(); + if (EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID)) return true; SmallVector Record;