aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-04-23 18:58:34 +0000
committerChris Lattner <sabre@nondot.org>2007-04-23 18:58:34 +0000
commitd127c1b5f3785a4a957ccf70b79a96adfc223259 (patch)
tree0a99ba263ce4011dc6be6c171136ea06868f49ee /lib
parentaea20124338b335ea6ff2730924c223f0db95e04 (diff)
downloadexternal_llvm-d127c1b5f3785a4a957ccf70b79a96adfc223259.zip
external_llvm-d127c1b5f3785a4a957ccf70b79a96adfc223259.tar.gz
external_llvm-d127c1b5f3785a4a957ccf70b79a96adfc223259.tar.bz2
implement reading of abbrevs, and writing of abbreviated global varrs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36367 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp9
-rw-r--r--lib/Bitcode/Writer/BitcodeWriter.cpp10
2 files changed, 13 insertions, 6 deletions
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index f464e33..ba4ba8db 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -94,7 +94,8 @@ bool BitcodeReader::ParseTypeTable(BitstreamReader &Stream) {
}
if (Code == bitc::DEFINE_ABBREV) {
- assert(0 && "Abbrevs not implemented yet!");
+ Stream.ReadAbbrevRecord();
+ continue;
}
// Read a record.
@@ -231,7 +232,8 @@ bool BitcodeReader::ParseTypeSymbolTable(BitstreamReader &Stream) {
}
if (Code == bitc::DEFINE_ABBREV) {
- assert(0 && "Abbrevs not implemented yet!");
+ Stream.ReadAbbrevRecord();
+ continue;
}
// Read a record.
@@ -294,7 +296,8 @@ bool BitcodeReader::ParseModule(BitstreamReader &Stream,
}
if (Code == bitc::DEFINE_ABBREV) {
- assert(0 && "Abbrevs not implemented yet!");
+ Stream.ReadAbbrevRecord();
+ continue;
}
// Read a record.
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp
index d78ea29..633036e 100644
--- a/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -204,9 +204,11 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
// compute the maximum alignment value.
std::map<std::string, unsigned> SectionMap;
unsigned MaxAlignment = 0;
+ unsigned MaxGlobalType = 0;
for (Module::const_global_iterator GV = M->global_begin(),E = M->global_end();
GV != E; ++GV) {
MaxAlignment = std::max(MaxAlignment, GV->getAlignment());
+ MaxGlobalType = std::max(MaxGlobalType, VE.getTypeID(GV->getType()));
if (!GV->hasSection()) continue;
// Give section names unique ID's.
@@ -229,10 +231,12 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
// Emit abbrev for globals, now that we know # sections and max alignment.
unsigned SimpleGVarAbbrev = 0;
- if (!M->global_empty() && 0) {
+ if (!M->global_empty()) {
// Add an abbrev for common globals with no visibility or thread localness.
BitCodeAbbrev *Abbv = new BitCodeAbbrev();
Abbv->Add(BitCodeAbbrevOp(bitc::MODULE_CODE_GLOBALVAR));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth,
+ Log2_32_Ceil(MaxGlobalType+1)));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, 1)); // Constant.
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Initializer.
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, 3)); // Linkage.
@@ -241,7 +245,7 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
else {
unsigned MaxEncAlignment = Log2_32(MaxAlignment)+1;
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth,
- Log2_32_Ceil(MaxEncAlignment)));
+ Log2_32_Ceil(MaxEncAlignment+1)));
}
if (SectionMap.empty()) // Section.
Abbv->Add(BitCodeAbbrevOp(0));
@@ -300,7 +304,7 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
/// WriteModule - Emit the specified module to the bitstream.
static void WriteModule(const Module *M, BitstreamWriter &Stream) {
- Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 2);
+ Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3);
// Emit the version number if it is non-zero.
if (CurVersion) {