summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bytecode/Reader/Reader.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-09-18 04:01:05 +0000
committerChris Lattner <sabre@nondot.org>2001-09-18 04:01:05 +0000
commit3779864fcf9c2b1df53b4841c6d87e92b5bbce4a (patch)
tree6755ed22c12e875f46dbd2db30c964cf0a323239 /llvm/lib/Bytecode/Reader/Reader.cpp
parent7fb14f54f84ab9a49a3eaf50286f65cf24fbe37b (diff)
downloadbcm5719-llvm-3779864fcf9c2b1df53b4841c6d87e92b5bbce4a.tar.gz
bcm5719-llvm-3779864fcf9c2b1df53b4841c6d87e92b5bbce4a.zip
Add support for global constants, and for initializers for constants
llvm-svn: 598
Diffstat (limited to 'llvm/lib/Bytecode/Reader/Reader.cpp')
-rw-r--r--llvm/lib/Bytecode/Reader/Reader.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/llvm/lib/Bytecode/Reader/Reader.cpp b/llvm/lib/Bytecode/Reader/Reader.cpp
index 71fec255cc5..a2038edf342 100644
--- a/llvm/lib/Bytecode/Reader/Reader.cpp
+++ b/llvm/lib/Bytecode/Reader/Reader.cpp
@@ -323,14 +323,29 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End,
unsigned VarType;
if (read_vbr(Buf, End, VarType)) return failure(true);
while (VarType != Type::VoidTyID) { // List is terminated by Void
- const Type *Ty = getType(VarType);
+ // VarType Fields: bit0 = isConstant, bit1 = hasInitializer, bit2+ = slot#
+ const Type *Ty = getType(VarType >> 2);
if (!Ty || !Ty->isPointerType()) {
cerr << "Global not pointer type! Ty = " << Ty << endl;
return failure(true);
}
+ ConstPoolVal *Initializer = 0;
+ if (VarType & 2) { // Does it have an initalizer?
+ // Do not improvise... values must have been stored in the constant pool,
+ // which should have been read before now.
+ //
+ unsigned InitSlot;
+ if (read_vbr(Buf, End, InitSlot)) return failure(true);
+
+ Value *V = getValue(Ty->castPointerType()->getValueType(),
+ InitSlot, false);
+ if (V == 0) return failure(true);
+ Initializer = V->castConstantAsserting();
+ }
+
// Create the global variable...
- GlobalVariable *GV = new GlobalVariable(Ty);
+ GlobalVariable *GV = new GlobalVariable(Ty, VarType & 1, Initializer);
insertValue(GV, ModuleValues);
C->getGlobalList().push_back(GV);
OpenPOWER on IntegriCloud