diff options
author | Chris Lattner <sabre@nondot.org> | 2009-04-07 02:56:46 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-04-07 02:56:46 +0000 |
commit | c18941660a00f30cdab1328bee2647cd6a322914 (patch) | |
tree | 30b9a036ce62a240168aa7731811e43f13c0238f /tools/llvm-bcanalyzer | |
parent | 43fd9be9846d8c9f250b8984f100d45f61f50abe (diff) | |
download | external_llvm-c18941660a00f30cdab1328bee2647cd6a322914.zip external_llvm-c18941660a00f30cdab1328bee2647cd6a322914.tar.gz external_llvm-c18941660a00f30cdab1328bee2647cd6a322914.tar.bz2 |
Add an API for the bitstream reader to read blobs and return
them by reference, instead of packing each byte into a
smallvector.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68486 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-bcanalyzer')
-rw-r--r-- | tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp index 2953e08..4832a4c 100644 --- a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp +++ b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp @@ -342,32 +342,14 @@ static bool ParseBlock(BitstreamReader &Stream, unsigned IndentLevel) { break; default: Record.clear(); - bool HasBlob = false; ++BlockStats.NumRecords; - if (AbbrevID != bitc::UNABBREV_RECORD) { + if (AbbrevID != bitc::UNABBREV_RECORD) ++BlockStats.NumAbbreviatedRecords; - const BitCodeAbbrev *Abbv = Stream.getAbbrev(AbbrevID); - if (Abbv->getNumOperandInfos() != 0) { - const BitCodeAbbrevOp &LastOp = - Abbv->getOperandInfo(Abbv->getNumOperandInfos()-1); - // If the last operand is a blob, then this record has blob data. - if (LastOp.isEncoding() && - LastOp.getEncoding() == BitCodeAbbrevOp::Blob) - HasBlob = true; - } - } - unsigned Code; const char *BlobStart = 0; unsigned BlobLen = 0; - if (!HasBlob) - Code = Stream.ReadRecord(AbbrevID, Record); - else { - Code = Stream.ReadRecord(AbbrevID, Record); - BlobStart = BlobStart; - BlobLen = BlobLen; - } + unsigned Code = Stream.ReadRecord(AbbrevID, Record, BlobStart, BlobLen); // Increment the # occurrences of this code. if (BlockStats.CodeFreq.size() <= Code) @@ -388,7 +370,24 @@ static bool ParseBlock(BitstreamReader &Stream, unsigned IndentLevel) { for (unsigned i = 0, e = Record.size(); i != e; ++i) std::cerr << " op" << i << "=" << (int64_t)Record[i]; - std::cerr << "/>\n"; + std::cerr << "/>"; + + if (BlobStart) { + std::cerr << " blob data = "; + bool BlobIsPrintable = true; + for (unsigned i = 0; i != BlobLen; ++i) + if (!isprint(BlobStart[i])) { + BlobIsPrintable = false; + break; + } + + if (BlobIsPrintable) + std::cerr << "'" << std::string(BlobStart, BlobStart+BlobLen) <<"'"; + else + std::cerr << "unprintable, " << BlobLen << " bytes."; + } + + std::cerr << "\n"; } break; |