Add support for global constants, and for initializers for constants
llvm-svn: 598
diff --git a/llvm/lib/Bytecode/Writer/Writer.cpp b/llvm/lib/Bytecode/Writer/Writer.cpp
index e6562f5..da48018 100644
--- a/llvm/lib/Bytecode/Writer/Writer.cpp
+++ b/llvm/lib/Bytecode/Writer/Writer.cpp
@@ -120,9 +120,21 @@
// Output the types for the global variables in the module...
for (Module::const_giterator I = M->gbegin(), End = M->gend(); I != End;++I) {
- int Slot = Table.getValSlot((*I)->getType());
+ const GlobalVariable *GV = *I;
+ int Slot = Table.getValSlot(GV->getType());
assert(Slot != -1 && "Module global vars is broken!");
- output_vbr((unsigned)Slot, Out);
+
+ // Fields: bit0 = isConstant, bit1 = hasInitializer, bit2+ = slot#
+ unsigned oSlot = ((unsigned)Slot << 2) | (GV->hasInitializer() << 1) |
+ GV->isConstant();
+ output_vbr(oSlot, Out);
+
+ // If we have an initialized, output it now.
+ if (GV->hasInitializer()) {
+ Slot = Table.getValSlot(GV->getInitializer());
+ assert(Slot != -1 && "No slot for global var initializer!");
+ output_vbr((unsigned)Slot, Out);
+ }
}
output_vbr((unsigned)Table.getValSlot(Type::VoidTy), Out);