diff options
author | Chris Lattner <sabre@nondot.org> | 2001-09-10 07:58:01 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-09-10 07:58:01 +0000 |
commit | 70cc3397f84c2e1fd69c059a0ef89e398e847b00 (patch) | |
tree | ca2156daf75e4abf788d92925bdce4063da36e58 /lib/Bytecode/Writer | |
parent | 7720c8e1a7a252e983e3f3e7f841d7901dfea80c (diff) | |
download | external_llvm-70cc3397f84c2e1fd69c059a0ef89e398e847b00.zip external_llvm-70cc3397f84c2e1fd69c059a0ef89e398e847b00.tar.gz external_llvm-70cc3397f84c2e1fd69c059a0ef89e398e847b00.tar.bz2 |
Implement global variable support
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@530 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Writer')
-rw-r--r-- | lib/Bytecode/Writer/SlotCalculator.cpp | 15 | ||||
-rw-r--r-- | lib/Bytecode/Writer/Writer.cpp | 13 |
2 files changed, 24 insertions, 4 deletions
diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp index 9af5a38..cc7d4e5 100644 --- a/lib/Bytecode/Writer/SlotCalculator.cpp +++ b/lib/Bytecode/Writer/SlotCalculator.cpp @@ -12,6 +12,7 @@ #include "llvm/Analysis/SlotCalculator.h" #include "llvm/Analysis/ConstantsScanner.h" #include "llvm/Method.h" +#include "llvm/GlobalVariable.h" #include "llvm/Module.h" #include "llvm/BasicBlock.h" #include "llvm/ConstPoolVals.h" @@ -68,13 +69,21 @@ SlotCalculator::SlotCalculator(const Method *M, bool IgnoreNamed) { // void SlotCalculator::processModule() { SC_DEBUG("begin processModule!\n"); - // Currently, the only module level declarations are methods and method - // prototypes. We simply scavenge the types out of the methods, then add the - // methods themselves to the value table... + + // Add all of the global variables to the value table... + // + for_each(TheModule->gbegin(), TheModule->gend(), + bind_obj(this, &SlotCalculator::insertValue)); + + // Scavenge the types out of the methods, then add the methods themselves to + // the value table... // for_each(TheModule->begin(), TheModule->end(), // Insert methods... bind_obj(this, &SlotCalculator::insertValue)); + // Insert constants that are named at module level into the slot pool so that + // the module symbol table can refer to them... + // if (TheModule->hasSymbolTable() && !IgnoreNamedNodes) { SC_DEBUG("Inserting SymbolTable values:\n"); processSymbolTable(TheModule->getSymbolTable()); diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp index 4235145..e6562f5 100644 --- a/lib/Bytecode/Writer/Writer.cpp +++ b/lib/Bytecode/Writer/Writer.cpp @@ -24,6 +24,7 @@ #include "WriterInternals.h" #include "llvm/Module.h" +#include "llvm/GlobalVariable.h" #include "llvm/Method.h" #include "llvm/BasicBlock.h" #include "llvm/ConstPoolVals.h" @@ -117,7 +118,15 @@ void BytecodeWriter::outputConstants(bool isMethod) { void BytecodeWriter::outputModuleInfoBlock(const Module *M) { BytecodeBlock ModuleInfoBlock(BytecodeFormat::ModuleGlobalInfo, Out); - // Output the types of the methods in this class + // 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()); + assert(Slot != -1 && "Module global vars is broken!"); + output_vbr((unsigned)Slot, Out); + } + output_vbr((unsigned)Table.getValSlot(Type::VoidTy), Out); + + // Output the types of the methods in this module... for (Module::const_iterator I = M->begin(), End = M->end(); I != End; ++I) { int Slot = Table.getValSlot((*I)->getType()); assert(Slot != -1 && "Module const pool is broken!"); @@ -125,6 +134,8 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) { output_vbr((unsigned)Slot, Out); } output_vbr((unsigned)Table.getValSlot(Type::VoidTy), Out); + + align32(Out); } |