Make ModRefBehavior a lattice. Use this to clean up AliasAnalysis
[oota-llvm.git] / include / llvm / Bitcode / BitstreamReader.h
index be3d8c55b7af1db392e9b79b421c0637ea9b6143..779ef5fa2d839b7cb832ffe68c3c5d5a1eb7de33 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "llvm/Bitcode/BitCodes.h"
 #include <climits>
+#include <string>
 #include <vector>
 
 namespace llvm {
@@ -41,11 +42,19 @@ private:
   
   std::vector<BlockInfo> BlockInfoRecords;
 
+  /// IgnoreBlockInfoNames - This is set to true if we don't care about the
+  /// block/record name information in the BlockInfo block. Only llvm-bcanalyzer
+  /// uses this.
+  bool IgnoreBlockInfoNames;
+  
+  BitstreamReader(const BitstreamReader&);  // NOT IMPLEMENTED
+  void operator=(const BitstreamReader&);  // NOT IMPLEMENTED
 public:
-  BitstreamReader() : FirstChar(0), LastChar(0) {
+  BitstreamReader() : FirstChar(0), LastChar(0), IgnoreBlockInfoNames(true) {
   }
 
   BitstreamReader(const unsigned char *Start, const unsigned char *End) {
+    IgnoreBlockInfoNames = true;
     init(Start, End);
   }
 
@@ -70,6 +79,11 @@ public:
   const unsigned char *getFirstChar() const { return FirstChar; }
   const unsigned char *getLastChar() const { return LastChar; }
 
+  /// CollectBlockInfoNames - This is called by clients that want block/record
+  /// name information.
+  void CollectBlockInfoNames() { IgnoreBlockInfoNames = false; }
+  bool isIgnoringBlockInfoNames() { return IgnoreBlockInfoNames; }
+  
   //===--------------------------------------------------------------------===//
   // Block Manipulation
   //===--------------------------------------------------------------------===//
@@ -247,6 +261,7 @@ public:
   
   
   uint32_t Read(unsigned NumBits) {
+    assert(NumBits <= 32 && "Cannot return more than 32 bits!");
     // If the field is fully contained by CurWord, return it quickly.
     if (BitsInCurWord >= NumBits) {
       uint32_t R = CurWord & ((1U << NumBits)-1);
@@ -309,15 +324,17 @@ public:
     }
   }
 
+  // ReadVBR64 - Read a VBR that may have a value up to 64-bits in size.  The
+  // chunk size of the VBR must still be <= 32 bits though.
   uint64_t ReadVBR64(unsigned NumBits) {
-    uint64_t Piece = Read(NumBits);
+    uint32_t Piece = Read(NumBits);
     if ((Piece & (1U << (NumBits-1))) == 0)
-      return Piece;
+      return uint64_t(Piece);
 
     uint64_t Result = 0;
     unsigned NextBit = 0;
     while (1) {
-      Result |= (Piece & ((1U << (NumBits-1))-1)) << NextBit;
+      Result |= uint64_t(Piece & ((1U << (NumBits-1))-1)) << NextBit;
 
       if ((Piece & (1U << (NumBits-1))) == 0)
         return Result;
@@ -598,6 +615,7 @@ public:
         break;
       case bitc::BLOCKINFO_CODE_BLOCKNAME: {
         if (!CurBlockInfo) return true;
+        if (BitStream->isIgnoringBlockInfoNames()) break;  // Ignore name.
         std::string Name;
         for (unsigned i = 0, e = Record.size(); i != e; ++i)
           Name += (char)Record[i];
@@ -606,6 +624,7 @@ public:
       }
       case bitc::BLOCKINFO_CODE_SETRECORDNAME: {
         if (!CurBlockInfo) return true;
+        if (BitStream->isIgnoringBlockInfoNames()) break;  // Ignore name.
         std::string Name;
         for (unsigned i = 1, e = Record.size(); i != e; ++i)
           Name += (char)Record[i];