[llvm-commits] [llvm] r70159 - /llvm/trunk/include/llvm/Bitcode/BitstreamReader.h

Chris Lattner sabre at nondot.org
Sun Apr 26 14:07:02 PDT 2009


Author: lattner
Date: Sun Apr 26 16:07:02 2009
New Revision: 70159

URL: http://llvm.org/viewvc/llvm-project?rev=70159&view=rev
Log:
make BitstreamCursor's copyable and assignable.

Modified:
    llvm/trunk/include/llvm/Bitcode/BitstreamReader.h

Modified: llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamReader.h?rev=70159&r1=70158&r2=70159&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Bitcode/BitstreamReader.h (original)
+++ llvm/trunk/include/llvm/Bitcode/BitstreamReader.h Sun Apr 26 16:07:02 2009
@@ -71,6 +71,11 @@
   // 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 @@
   /// BlockScope - This tracks the codesize of parent blocks.
   SmallVector<Block, 8> 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 @@
     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<unsigned>(CurAbbrevs.size());
+         i != e; ++i)
+      CurAbbrevs[i]->addRef();
+    
+    // Copy block scope and bump ref counts.
+    for (unsigned S = 0, e = static_cast<unsigned>(BlockScope.size());
+         S != e; ++S) {
+      std::vector<BitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs;
+      for (unsigned i = 0, e = static_cast<unsigned>(Abbrevs.size());
+           i != e; ++i)
+        Abbrevs[i]->addRef();
+    }
+  }
+  
   void freeState() {
     // Free all the Abbrevs.
     for (unsigned i = 0, e = static_cast<unsigned>(CurAbbrevs.size());
@@ -512,6 +544,10 @@
 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<uint64_t, 64> Record;





More information about the llvm-commits mailing list