Allow modules to have 'any' pointer size and endianness. Luckily, we had
authorChris Lattner <sabre@nondot.org>
Sun, 24 Aug 2003 13:47:36 +0000 (13:47 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 24 Aug 2003 13:47:36 +0000 (13:47 +0000)
some space for extra flags, so we don't need to bump the revision number.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8118 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bytecode/Reader/Reader.cpp
lib/Bytecode/Reader/ReaderInternals.h
lib/Bytecode/Writer/Writer.cpp

index 097a8d4dc7756eeb6180d8bcb4fcb69780788a22..3076f2032cd1664092e8396097091c9c41f42078 100644 (file)
@@ -498,9 +498,15 @@ bool BytecodeParser::ParseVersionInfo(const unsigned char *&Buf,
   if (read_vbr(Buf, EndBuf, Version)) return true;
 
   // Unpack version number: low four bits are for flags, top bits = version
-  isBigEndian     = Version & 1;
-  hasLongPointers = Version & 2;
-  RevisionNum     = Version >> 4;
+  Module::Endianness  Endianness;
+  Module::PointerSize PointerSize;
+  Endianness  = (Version & 1) ? Module::BigEndian : Module::LittleEndian;
+  PointerSize = (Version & 2) ? Module::Pointer64 : Module::Pointer32;
+
+  bool hasNoEndianness = Version & 4;
+  bool hasNoPointerSize = Version & 8;
+  
+  RevisionNum = Version >> 4;
 
   // Default values for the current bytecode version
   HasImplicitZeroInitializer = true;
@@ -515,11 +521,14 @@ bool BytecodeParser::ParseVersionInfo(const unsigned char *&Buf,
     //
     if (Version != 14) return true;  // Unknown revision 0 flags?
     HasImplicitZeroInitializer = false;
-    isBigEndian = hasLongPointers = true;
+    Endianness  = Module::BigEndian;
+    PointerSize = Module::Pointer64;
     hasInternalMarkerOnly = true;
+    hasNoEndianness = hasNoPointerSize = false;
     break;
   case 1:
-    // Version #1 has two bit fields: isBigEndian and hasLongPointers
+    // Version #1 has four bit fields: isBigEndian, hasLongPointers,
+    // hasNoEndianness, and hasNoPointerSize.
     hasInternalMarkerOnly = true;
     break;
   case 2:
@@ -531,14 +540,14 @@ bool BytecodeParser::ParseVersionInfo(const unsigned char *&Buf,
     return true;
   }
 
-  TheModule->setEndianness(isBigEndian ? Module::BigEndian :
-                                         Module::LittleEndian);
-  TheModule->setPointerSize(hasLongPointers ? Module::Pointer64 : 
-                                              Module::Pointer32);
+  if (hasNoEndianness) Endianness  = Module::AnyEndianness;
+  if (hasNoPointerSize) PointerSize = Module::AnyPointerSize;
 
+  TheModule->setEndianness(Endianness);
+  TheModule->setPointerSize(PointerSize);
   BCR_TRACE(1, "Bytecode Rev = " << (unsigned)RevisionNum << "\n");
-  BCR_TRACE(1, "BigEndian/LongPointers = " << isBigEndian << ","
-               << hasLongPointers << "\n");
+  BCR_TRACE(1, "Endianness/PointerSize = " << Endianness << ","
+               << PointerSize << "\n");
   BCR_TRACE(1, "HasImplicitZeroInit = " << HasImplicitZeroInitializer << "\n");
   return false;
 }
index e09e5e585b9089777a48726d861936b238635ba0..a57ad7cf0491e126b1cc3b75c7cb8cc7487f2f33 100644 (file)
@@ -86,7 +86,6 @@ private:          // All of this data is transient across calls to ParseBytecode
   unsigned char RevisionNum;        // The rev # itself
   unsigned char FirstDerivedTyID;   // First variable index to use for type
   bool HasImplicitZeroInitializer;  // Is entry 0 of every slot implicity zeros?
-  bool isBigEndian, hasLongPointers;// Information about the target compiled for
   bool hasInternalMarkerOnly;       // Only types of linkage are intern/external
 
   typedef std::vector<ValueList*> ValueTable;
index f8d94890f066cf869521252b4226ee29105ea912..096dc69895cc41c4299a0b84b6fc6b5b6bc551a2 100644 (file)
@@ -43,11 +43,14 @@ BytecodeWriter::BytecodeWriter(std::deque<unsigned char> &o, const Module *M)
   // Emit the top level CLASS block.
   BytecodeBlock ModuleBlock(BytecodeFormat::Module, Out);
 
-  bool isBigEndian = M->isBigEndian();
-  bool hasLongPointers = M->has64BitPointers();
+  bool isBigEndian      = M->getEndianness() == Module::BigEndian;
+  bool hasLongPointers  = M->getPointerSize() == Module::Pointer64;
+  bool hasNoEndianness  = M->getEndianness() == Module::AnyEndianness;
+  bool hasNoPointerSize = M->getPointerSize() == Module::AnyPointerSize;
 
   // Output the version identifier... we are currently on bytecode version #2
-  unsigned Version = (2 << 4) | isBigEndian | (hasLongPointers << 1);
+  unsigned Version = (2 << 4) | isBigEndian | (hasLongPointers << 1) |
+                     (hasNoEndianness << 2) | (hasNoPointerSize << 3);
   output_vbr(Version, Out);
   align32(Out);