Version 1.2 now supports encoding strings as a special case, to avoid having
authorChris Lattner <sabre@nondot.org>
Wed, 14 Jan 2004 23:35:21 +0000 (23:35 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 14 Jan 2004 23:35:21 +0000 (23:35 +0000)
to emit all of those sbyte constants.

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

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

index 660566b26643367cf90733400cd7e3f5ed96d017..5fb62dae20c41563a1fe764e195f204c40c7725c 100644 (file)
@@ -298,6 +298,42 @@ void BytecodeParser::ParseGlobalTypes(const unsigned char *&Buf,
   ParseConstantPool(Buf, EndBuf, T, ModuleTypeValues);
 }
 
+void BytecodeParser::parseStringConstants(const unsigned char *&Buf,
+                                          const unsigned char *EndBuf,
+                                          unsigned NumEntries, ValueTable &Tab){
+  unsigned Typ;
+  for (; NumEntries; --NumEntries) {
+    if (read_vbr(Buf, EndBuf, Typ)) throw Error_readvbr;
+    const Type *Ty = getType(Typ);
+    if (!isa<ArrayType>(Ty))
+      throw std::string("String constant data invalid!");
+    
+    const ArrayType *ATy = cast<ArrayType>(Ty);
+    if (ATy->getElementType() != Type::SByteTy &&
+        ATy->getElementType() != Type::UByteTy)
+      throw std::string("String constant data invalid!");
+    
+    // Read character data.  The type tells us how long the string is.
+    char Data[ATy->getNumElements()];
+    if (input_data(Buf, EndBuf, Data, Data+ATy->getNumElements()))
+      throw Error_inputdata;
+
+    std::vector<Constant*> Elements(ATy->getNumElements());
+    if (ATy->getElementType() == Type::SByteTy)
+      for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i)
+        Elements[i] = ConstantSInt::get(Type::SByteTy, Data[i]);
+    else
+      for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i)
+        Elements[i] = ConstantSInt::get(Type::UByteTy, Data[i]);
+
+    // Create the constant, inserting it as needed.
+    Constant *C = ConstantArray::get(ATy, Elements);
+    unsigned Slot = insertValue(C, Typ, Tab);
+    ResolveReferencesToConstant(C, Slot);
+  }
+}
+
+
 void BytecodeParser::ParseConstantPool(const unsigned char *&Buf,
                                        const unsigned char *EndBuf,
                                        ValueTable &Tab, 
@@ -310,6 +346,9 @@ void BytecodeParser::ParseConstantPool(const unsigned char *&Buf,
     if (Typ == Type::TypeTyID) {
       BCR_TRACE(3, "Type: 'type'  NumEntries: " << NumEntries << "\n");
       parseTypeConstants(Buf, EndBuf, TypeTab, NumEntries);
+    } else if (Typ == Type::VoidTyID) {
+      assert(&Tab == &ModuleValues && "Cannot read strings in functions!");
+      parseStringConstants(Buf, EndBuf, NumEntries, Tab);
     } else {
       BCR_TRACE(3, "Type: '" << *getType(Typ) << "'  NumEntries: "
                 << NumEntries << "\n");
index a0b40be6e396bc1fd7cebb689f22e417544acc76..7a6fa87511493fd359b989042dc6efca0ed9c5a0 100644 (file)
@@ -552,8 +552,8 @@ void BytecodeParser::ParseVersionInfo(const unsigned char *&Buf,
 
   switch (RevisionNum) {
   case 2:               // LLVM pre-1.0 release: will be deleted on the next rev
-    // Version #2 added information about all 4 linkage types instead of just
-    // having internal and external.
+    // Version #2 only supported 4 linkage types.  It didn't support weak
+    // linkage.
     hasExtendedLinkageSpecs = false;
     hasOldStyleVarargs = true;
     hasVarArgCallPadding = true;
@@ -561,8 +561,11 @@ void BytecodeParser::ParseVersionInfo(const unsigned char *&Buf,
   case 0:               //  LLVM 1.0, 1.1 release version
     // Compared to rev #2, we added support for weak linkage, a more dense
     // encoding, and better varargs support.
+
+    // Base LLVM 1.0 bytecode format.
     break;
   case 1:               // LLVM 1.2 release version
+    // LLVM 1.2 added explicit support for emitting strings efficiently.
     break;
 
   default:
index b1d9c605f7868bb2d5a5667bc0795de0419b3ff5..54a38e457b4d170319075df5ae2fd814bf43e01f 100644 (file)
@@ -177,6 +177,9 @@ private:
                           TypeValuesListTy &Tab, unsigned NumEntries);
   const Type *parseTypeConstant(const unsigned char *&Buf,
                                 const unsigned char *EndBuf);
+  void parseStringConstants(const unsigned char *&Buf,
+                            const unsigned char *EndBuf,
+                            unsigned NumEntries, ValueTable &Tab);
 
   Value      *getValue(unsigned TypeID, unsigned num, bool Create = true);
   const Type *getType(unsigned ID);