[llvm-commits] CVS: llvm/lib/Bytecode/Reader/ConstantReader.cpp Reader.cpp ReaderInternals.h
Chris Lattner
lattner at cs.uiuc.edu
Wed Jan 14 17:36:00 PST 2004
Changes in directory llvm/lib/Bytecode/Reader:
ConstantReader.cpp updated: 1.67 -> 1.68
Reader.cpp updated: 1.93 -> 1.94
ReaderInternals.h updated: 1.71 -> 1.72
---
Log message:
Version 1.2 now supports encoding strings as a special case, to avoid having
to emit all of those sbyte constants.
---
Diffs of the changes: (+47 -2)
Index: llvm/lib/Bytecode/Reader/ConstantReader.cpp
diff -u llvm/lib/Bytecode/Reader/ConstantReader.cpp:1.67 llvm/lib/Bytecode/Reader/ConstantReader.cpp:1.68
--- llvm/lib/Bytecode/Reader/ConstantReader.cpp:1.67 Mon Jan 12 13:06:21 2004
+++ llvm/lib/Bytecode/Reader/ConstantReader.cpp Wed Jan 14 17:35:21 2004
@@ -298,6 +298,42 @@
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 @@
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: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.93 llvm/lib/Bytecode/Reader/Reader.cpp:1.94
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.93 Wed Jan 14 10:44:44 2004
+++ llvm/lib/Bytecode/Reader/Reader.cpp Wed Jan 14 17:35:21 2004
@@ -552,8 +552,8 @@
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 @@
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: llvm/lib/Bytecode/Reader/ReaderInternals.h
diff -u llvm/lib/Bytecode/Reader/ReaderInternals.h:1.71 llvm/lib/Bytecode/Reader/ReaderInternals.h:1.72
--- llvm/lib/Bytecode/Reader/ReaderInternals.h:1.71 Wed Jan 14 10:44:44 2004
+++ llvm/lib/Bytecode/Reader/ReaderInternals.h Wed Jan 14 17:35:21 2004
@@ -177,6 +177,9 @@
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);
More information about the llvm-commits
mailing list