Index: lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp |
diff --git a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp |
index 5317e11a279a051890104dbafd56385e8cf32cab..9e262ac7375b1e77d8e1dc6e13ec041b44c144d2 100644 |
--- a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp |
+++ b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp |
@@ -23,8 +23,14 @@ |
#include "llvm/Support/DataStream.h" |
#include "llvm/Support/MathExtras.h" |
#include "llvm/Support/MemoryBuffer.h" |
+#include "llvm/Support/raw_ostream.h" |
Karl
2013/05/17 20:52:18
Removed include, no longer needed.
|
using namespace llvm; |
+/* To turn on debugging for this file, change value of NACL_DEBUGGING to 1. |
Karl
2013/05/17 20:52:18
Replaced with builtin DEBUG of llvm.
|
+ */ |
+#define NACL_DEBUGGING 0 |
+#include "llvm/Bitcode/NaCl/NaClDebugging.h" |
+ |
enum { |
SWITCH_INST_MAGIC = 0x4B5 // May 2012 => 1205 => Hex |
}; |
@@ -450,6 +456,7 @@ static void decodeLLVMAttributesForBitcode(AttrBuilder &B, |
} |
bool NaClBitcodeReader::ParseAttributeBlock() { |
+ NACL_DEBUG(outs() << "-> ParseAttributeBlock\n"); |
if (Stream.EnterSubBlock(naclbitc::PARAMATTR_BLOCK_ID)) |
return Error("Malformed block record"); |
@@ -469,6 +476,7 @@ bool NaClBitcodeReader::ParseAttributeBlock() { |
case NaClBitstreamEntry::Error: |
return Error("Error at end of PARAMATTR block"); |
case NaClBitstreamEntry::EndBlock: |
+ NACL_DEBUG(outs() << "<- ParseAttributeBlock\n"); |
return false; |
case NaClBitstreamEntry::Record: |
// The interesting case. |
@@ -508,6 +516,7 @@ bool NaClBitcodeReader::ParseAttributeBlock() { |
} |
bool NaClBitcodeReader::ParseAttributeGroupBlock() { |
+ NACL_DEBUG(outs() << "-> ParseAttributeGroupBlock\n"); |
if (Stream.EnterSubBlock(naclbitc::PARAMATTR_GROUP_BLOCK_ID)) |
return Error("Malformed block record"); |
@@ -525,6 +534,7 @@ bool NaClBitcodeReader::ParseAttributeGroupBlock() { |
case NaClBitstreamEntry::Error: |
return Error("Error at end of PARAMATTR_GROUP block"); |
case NaClBitstreamEntry::EndBlock: |
+ NACL_DEBUG(outs() << "<- ParseAttributeGroupBlock\n"); |
return false; |
case NaClBitstreamEntry::Record: |
// The interesting case. |
@@ -584,9 +594,11 @@ bool NaClBitcodeReader::ParseAttributeGroupBlock() { |
} |
bool NaClBitcodeReader::ParseTypeTable() { |
+ NACL_DEBUG(outs() << "-> ParseTypeTable\n"); |
if (Stream.EnterSubBlock(naclbitc::TYPE_BLOCK_ID_NEW)) |
return Error("Malformed block record"); |
+ NACL_DEBUG(outs() << "<- ParseTypeTable\n"); |
return ParseTypeTableBody(); |
} |
@@ -810,6 +822,7 @@ bool NaClBitcodeReader::ParseTypeTableBody() { |
} |
bool NaClBitcodeReader::ParseValueSymbolTable() { |
+ NACL_DEBUG(outs() << "-> ParseValueSymbolTable\n"); |
if (Stream.EnterSubBlock(naclbitc::VALUE_SYMTAB_BLOCK_ID)) |
return Error("Malformed block record"); |
@@ -825,6 +838,7 @@ bool NaClBitcodeReader::ParseValueSymbolTable() { |
case NaClBitstreamEntry::Error: |
return Error("malformed value symbol table block"); |
case NaClBitstreamEntry::EndBlock: |
+ NACL_DEBUG(outs() << "<- ParseValueSymbolTable\n"); |
return false; |
case NaClBitstreamEntry::Record: |
// The interesting case. |
@@ -866,6 +880,7 @@ bool NaClBitcodeReader::ParseValueSymbolTable() { |
bool NaClBitcodeReader::ParseMetadata() { |
unsigned NextMDValueNo = MDValueList.size(); |
+ NACL_DEBUG(outs() << "-> ParseMetadata\n"); |
if (Stream.EnterSubBlock(naclbitc::METADATA_BLOCK_ID)) |
return Error("Malformed block record"); |
@@ -881,6 +896,7 @@ bool NaClBitcodeReader::ParseMetadata() { |
Error("malformed metadata block"); |
return true; |
case NaClBitstreamEntry::EndBlock: |
+ NACL_DEBUG(outs() << "<- ParseMetadata\n"); |
return false; |
case NaClBitstreamEntry::Record: |
// The interesting case. |
@@ -1019,6 +1035,7 @@ static APInt ReadWideAPInt(ArrayRef<uint64_t> Vals, unsigned TypeBits) { |
} |
bool NaClBitcodeReader::ParseConstants() { |
+ NACL_DEBUG(outs() << "-> ParseConstants\n"); |
if (Stream.EnterSubBlock(naclbitc::CONSTANTS_BLOCK_ID)) |
return Error("Malformed block record"); |
@@ -1041,6 +1058,7 @@ bool NaClBitcodeReader::ParseConstants() { |
// Once all the constants have been read, go through and resolve forward |
// references. |
ValueList.ResolveConstantForwardRefs(); |
+ NACL_DEBUG(outs() << "<- ParseConstants\n"); |
return false; |
case NaClBitstreamEntry::Record: |
// The interesting case. |
@@ -1415,6 +1433,7 @@ bool NaClBitcodeReader::ParseConstants() { |
} |
bool NaClBitcodeReader::ParseUseLists() { |
+ NACL_DEBUG(outs() << "-> ParseUseLists\n"); |
if (Stream.EnterSubBlock(naclbitc::USELIST_BLOCK_ID)) |
return Error("Malformed block record"); |
@@ -1429,6 +1448,7 @@ bool NaClBitcodeReader::ParseUseLists() { |
case NaClBitstreamEntry::Error: |
return Error("malformed use list block"); |
case NaClBitstreamEntry::EndBlock: |
+ NACL_DEBUG(outs() << "<- ParseUseLists\n"); |
return false; |
case NaClBitstreamEntry::Record: |
// The interesting case. |
@@ -1455,6 +1475,7 @@ bool NaClBitcodeReader::ParseUseLists() { |
/// remember where it is and then skip it. This lets us lazily deserialize the |
/// functions. |
bool NaClBitcodeReader::RememberAndSkipFunctionBody() { |
+ NACL_DEBUG(outs() << "-> RememberAndSkipFunctionBody\n"); |
// Get the function we are talking about. |
if (FunctionsWithBodies.empty()) |
return Error("Insufficient function protos"); |
@@ -1469,6 +1490,7 @@ bool NaClBitcodeReader::RememberAndSkipFunctionBody() { |
// Skip over the function block for now. |
if (Stream.SkipBlock()) |
return Error("Malformed block record"); |
+ NACL_DEBUG(outs() << "<- RememberAndSkipFunctionBody\n"); |
return false; |
} |
@@ -1499,6 +1521,7 @@ bool NaClBitcodeReader::GlobalCleanup() { |
} |
bool NaClBitcodeReader::ParseModule(bool Resume) { |
+ NACL_DEBUG(outs() << "-> ParseModule\n"); |
if (Resume) |
Stream.JumpToBit(NextUnreadBit); |
else if (Stream.EnterSubBlock(naclbitc::MODULE_BLOCK_ID)) |
@@ -1517,11 +1540,13 @@ bool NaClBitcodeReader::ParseModule(bool Resume) { |
Error("malformed module block"); |
return true; |
case NaClBitstreamEntry::EndBlock: |
+ NACL_DEBUG(outs() << "<- ParseModule\n"); |
return GlobalCleanup(); |
case NaClBitstreamEntry::SubBlock: |
switch (Entry.ID) { |
default: // Skip unknown content. |
+ outs() << "Skip unknown context\n"; |
if (Stream.SkipBlock()) |
return Error("Malformed block record"); |
break; |
@@ -1530,42 +1555,58 @@ bool NaClBitcodeReader::ParseModule(bool Resume) { |
return Error("Malformed BlockInfoBlock"); |
break; |
case naclbitc::PARAMATTR_BLOCK_ID: |
- if (ParseAttributeBlock()) |
+ if (ParseAttributeBlock()) { |
+ NACL_DEBUG(outs() << "<- ParseModule\n"); |
return true; |
+ } |
break; |
case naclbitc::PARAMATTR_GROUP_BLOCK_ID: |
- if (ParseAttributeGroupBlock()) |
+ if (ParseAttributeGroupBlock()) { |
+ NACL_DEBUG(outs() << "<- ParseModule\n"); |
return true; |
+ } |
break; |
case naclbitc::TYPE_BLOCK_ID_NEW: |
- if (ParseTypeTable()) |
+ if (ParseTypeTable()) { |
+ NACL_DEBUG(outs() << "<- ParseModule\n"); |
return true; |
+ } |
break; |
case naclbitc::VALUE_SYMTAB_BLOCK_ID: |
- if (ParseValueSymbolTable()) |
+ if (ParseValueSymbolTable()) { |
+ NACL_DEBUG(outs() << "<- ParseModule\n"); |
return true; |
+ } |
SeenValueSymbolTable = true; |
break; |
case naclbitc::CONSTANTS_BLOCK_ID: |
- if (ParseConstants() || ResolveGlobalAndAliasInits()) |
+ if (ParseConstants() || ResolveGlobalAndAliasInits()) { |
+ NACL_DEBUG(outs() << "<- ParseModule\n"); |
return true; |
+ } |
break; |
case naclbitc::METADATA_BLOCK_ID: |
- if (ParseMetadata()) |
+ if (ParseMetadata()) { |
+ NACL_DEBUG(outs() << "<- ParseModule\n"); |
return true; |
+ } |
break; |
case naclbitc::FUNCTION_BLOCK_ID: |
// If this is the first function body we've seen, reverse the |
// FunctionsWithBodies list. |
if (!SeenFirstFunctionBody) { |
std::reverse(FunctionsWithBodies.begin(), FunctionsWithBodies.end()); |
- if (GlobalCleanup()) |
+ if (GlobalCleanup()) { |
+ NACL_DEBUG(outs() << "<- ParseModule\n"); |
return true; |
+ } |
SeenFirstFunctionBody = true; |
} |
- if (RememberAndSkipFunctionBody()) |
+ if (RememberAndSkipFunctionBody()) { |
+ NACL_DEBUG(outs() << "<- ParseModule\n"); |
return true; |
+ } |
// For streaming bitcode, suspend parsing when we reach the function |
// bodies. Subsequent materialization calls will resume it when |
// necessary. For streaming, the function bodies must be at the end of |
@@ -1574,12 +1615,15 @@ bool NaClBitcodeReader::ParseModule(bool Resume) { |
// just finish the parse now. |
if (LazyStreamer && SeenValueSymbolTable) { |
NextUnreadBit = Stream.GetCurrentBitNo(); |
+ NACL_DEBUG(outs() << "<- ParseModule\n"); |
return false; |
} |
break; |
case naclbitc::USELIST_BLOCK_ID: |
- if (ParseUseLists()) |
+ if (ParseUseLists()) { |
+ NACL_DEBUG(outs() << "<- ParseModule\n"); |
return true; |
+ } |
break; |
} |
continue; |
@@ -1861,6 +1905,7 @@ bool NaClBitcodeReader::ParseBitcodeInto(Module *M) { |
} |
bool NaClBitcodeReader::ParseModuleTriple(std::string &Triple) { |
+ NACL_DEBUG(outs() << "-> ParseModuleTriple\n"); |
if (Stream.EnterSubBlock(naclbitc::MODULE_BLOCK_ID)) |
return Error("Malformed block record"); |
@@ -1875,6 +1920,7 @@ bool NaClBitcodeReader::ParseModuleTriple(std::string &Triple) { |
case NaClBitstreamEntry::Error: |
return Error("malformed module block"); |
case NaClBitstreamEntry::EndBlock: |
+ NACL_DEBUG(outs() << "<- ParseModuleTriple\n"); |
return false; |
case NaClBitstreamEntry::Record: |
// The interesting case. |
@@ -1940,6 +1986,7 @@ bool NaClBitcodeReader::ParseTriple(std::string &Triple) { |
/// ParseMetadataAttachment - Parse metadata attachments. |
bool NaClBitcodeReader::ParseMetadataAttachment() { |
+ NACL_DEBUG(outs() << "-> ParseMetadataAttachment\n"); |
if (Stream.EnterSubBlock(naclbitc::METADATA_ATTACHMENT_ID)) |
return Error("Malformed block record"); |
@@ -1952,6 +1999,7 @@ bool NaClBitcodeReader::ParseMetadataAttachment() { |
case NaClBitstreamEntry::Error: |
return Error("malformed metadata block"); |
case NaClBitstreamEntry::EndBlock: |
+ NACL_DEBUG(outs() << "<- ParseMetadataAttachment\n"); |
return false; |
case NaClBitstreamEntry::Record: |
// The interesting case. |
@@ -1985,6 +2033,7 @@ bool NaClBitcodeReader::ParseMetadataAttachment() { |
/// ParseFunctionBody - Lazily parse the specified function body block. |
bool NaClBitcodeReader::ParseFunctionBody(Function *F) { |
+ NACL_DEBUG(outs() << "-> ParseFunctionBody\n"); |
if (Stream.EnterSubBlock(naclbitc::FUNCTION_BLOCK_ID)) |
return Error("Malformed block record"); |
@@ -2016,21 +2065,34 @@ bool NaClBitcodeReader::ParseFunctionBody(Function *F) { |
case NaClBitstreamEntry::SubBlock: |
switch (Entry.ID) { |
default: // Skip unknown content. |
+ outs() << "default skip block\n"; |
if (Stream.SkipBlock()) |
return Error("Malformed block record"); |
break; |
case naclbitc::CONSTANTS_BLOCK_ID: |
- if (ParseConstants()) return true; |
+ if (ParseConstants()) { |
+ NACL_DEBUG(outs() << "-> ParseFunctionBody\n"); |
+ return true; |
+ } |
NextValueNo = ValueList.size(); |
break; |
case naclbitc::VALUE_SYMTAB_BLOCK_ID: |
- if (ParseValueSymbolTable()) return true; |
+ if (ParseValueSymbolTable()) { |
+ NACL_DEBUG(outs() << "-> ParseFunctionBody\n"); |
+ return true; |
+ } |
break; |
case naclbitc::METADATA_ATTACHMENT_ID: |
- if (ParseMetadataAttachment()) return true; |
+ if (ParseMetadataAttachment()) { |
+ NACL_DEBUG(outs() << "-> ParseFunctionBody\n"); |
+ return true; |
+ } |
break; |
case naclbitc::METADATA_BLOCK_ID: |
- if (ParseMetadata()) return true; |
+ if (ParseMetadata()) { |
+ NACL_DEBUG(outs() << "-> ParseFunctionBody\n"); |
+ return true; |
+ } |
break; |
} |
continue; |
@@ -2862,6 +2924,7 @@ OutOfRecordLoop: |
ValueList.shrinkTo(ModuleValueListSize); |
MDValueList.shrinkTo(ModuleMDValueListSize); |
std::vector<BasicBlock*>().swap(FunctionBBs); |
+ NACL_DEBUG(outs() << "-> ParseFunctionBody\n"); |
return false; |
} |