From 6dbfd7bfbcc7a69c978452560033fa5953db2cbf Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 24 Apr 2007 00:18:21 +0000 Subject: [PATCH] track global inits git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36385 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bitcode/Reader/BitcodeReader.cpp | 10 +++++++--- lib/Bitcode/Reader/BitcodeReader.h | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index ca74e3f6b7f..97f33a9b811 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -243,7 +243,7 @@ bool BitcodeReader::ParseTypeSymbolTable(BitstreamReader &Stream) { switch (Stream.ReadRecord(Code, Record)) { default: // Default behavior: unknown type. break; - case bitc::TST_ENTRY_CODE: // TST_ENTRY: [typeid, namelen, namechar x N] + case bitc::TST_CODE_ENTRY: // TST_ENTRY: [typeid, namelen, namechar x N] if (ConvertToString(Record, 1, TypeName)) return Error("Invalid TST_ENTRY record"); unsigned TypeID = Record[0]; @@ -288,7 +288,7 @@ bool BitcodeReader::ParseValueSymbolTable(BitstreamReader &Stream) { switch (Stream.ReadRecord(Code, Record)) { default: // Default behavior: unknown type. break; - case bitc::VST_ENTRY_CODE: // VST_ENTRY: [valueid, namelen, namechar x N] + case bitc::TST_CODE_ENTRY: // VST_ENTRY: [valueid, namelen, namechar x N] if (ConvertToString(Record, 1, ValueName)) return Error("Invalid TST_ENTRY record"); unsigned ValueID = Record[0]; @@ -358,6 +358,8 @@ bool BitcodeReader::ParseModule(BitstreamReader &Stream, case bitc::MODULE_CODE_VERSION: // VERSION: [version#] if (Record.size() < 1) return Error("Malformed MODULE_CODE_VERSION"); + if (!GlobalInits.empty()) + return Error("Malformed global initializer set"); // Only version #0 is supported so far. if (Record[0] != 0) return Error("Unknown bitstream version!"); @@ -431,7 +433,9 @@ bool BitcodeReader::ParseModule(BitstreamReader &Stream, ValueList.push_back(NewGV); - // TODO: remember initializer/global pair for later substitution. + // Remember which value to use for the global initializer. + if (unsigned InitID = Record[2]) + GlobalInits.push_back(std::make_pair(NewGV, InitID-1)); break; } // FUNCTION: [type, callingconv, isproto, linkage, alignment, section, diff --git a/lib/Bitcode/Reader/BitcodeReader.h b/lib/Bitcode/Reader/BitcodeReader.h index 45452ba0cb3..ed11692391c 100644 --- a/lib/Bitcode/Reader/BitcodeReader.h +++ b/lib/Bitcode/Reader/BitcodeReader.h @@ -22,12 +22,14 @@ namespace llvm { class BitstreamReader; class Value; + class GlobalValue; class BitcodeReader : public ModuleProvider { const char *ErrorString; std::vector TypeList; std::vector ValueList; + std::vector > GlobalInits; public: virtual ~BitcodeReader() {}