summaryrefslogtreecommitdiff
path: root/tools/llvm-bcanalyzer
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-26 22:21:57 +0000
committerChris Lattner <sabre@nondot.org>2009-04-26 22:21:57 +0000
commitf9a3ec86c138177c7d9b3a9d119e6d2247d14bd8 (patch)
tree15986c2b097351545c57cf4bd2e8c3b4e3d97cd7 /tools/llvm-bcanalyzer
parent7919b966a8fd8f98346216e79df6f4722693be22 (diff)
downloadllvm-f9a3ec86c138177c7d9b3a9d119e6d2247d14bd8.tar.gz
llvm-f9a3ec86c138177c7d9b3a9d119e6d2247d14bd8.tar.bz2
llvm-f9a3ec86c138177c7d9b3a9d119e6d2247d14bd8.tar.xz
Add two new record types to the blockinfo block:
BLOCKNAME and SETRECORDNAME. This allows a bitcode file to be self describing with pretty names for records and blocks in addition to numbers. This enhances llvm-bcanalyzer to use this to print prettily. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70165 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-bcanalyzer')
-rw-r--r--tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp40
1 files changed, 32 insertions, 8 deletions
diff --git a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
index 182404c4d1..e220ffa095 100644
--- a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
+++ b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
@@ -72,7 +72,8 @@ static enum {
/// GetBlockName - Return a symbolic block name if known, otherwise return
/// null.
-static const char *GetBlockName(unsigned BlockID) {
+static const char *GetBlockName(unsigned BlockID,
+ const BitstreamReader &StreamFile) {
// Standard blocks for all bitcode files.
if (BlockID < bitc::FIRST_APPLICATION_BLOCKID) {
if (BlockID == bitc::BLOCKINFO_BLOCK_ID)
@@ -80,6 +81,14 @@ static const char *GetBlockName(unsigned BlockID) {
return 0;
}
+ // Check to see if we have a blockinfo record for this block, with a name.
+ if (const BitstreamReader::BlockInfo *Info =
+ StreamFile.getBlockInfo(BlockID)) {
+ if (!Info->Name.empty())
+ return Info->Name.c_str();
+ }
+
+
if (CurStreamType != LLVMIRBitstream) return 0;
switch (BlockID) {
@@ -96,18 +105,30 @@ static const char *GetBlockName(unsigned BlockID) {
/// GetCodeName - Return a symbolic code name if known, otherwise return
/// null.
-static const char *GetCodeName(unsigned CodeID, unsigned BlockID) {
+static const char *GetCodeName(unsigned CodeID, unsigned BlockID,
+ const BitstreamReader &StreamFile) {
// Standard blocks for all bitcode files.
if (BlockID < bitc::FIRST_APPLICATION_BLOCKID) {
if (BlockID == bitc::BLOCKINFO_BLOCK_ID) {
switch (CodeID) {
default: return 0;
- case bitc::MODULE_CODE_VERSION: return "VERSION";
+ case bitc::BLOCKINFO_CODE_SETBID: return "SETBID";
+ case bitc::BLOCKINFO_CODE_BLOCKNAME: return "BLOCKNAME";
+ case bitc::BLOCKINFO_CODE_SETRECORDNAME: return "SETRECORDNAME";
}
}
return 0;
}
+ // Check to see if we have a blockinfo record for this record, with a name.
+ if (const BitstreamReader::BlockInfo *Info =
+ StreamFile.getBlockInfo(BlockID)) {
+ for (unsigned i = 0, e = Info->RecordNames.size(); i != e; ++i)
+ if (Info->RecordNames[i].first == CodeID)
+ return Info->RecordNames[i].second.c_str();
+ }
+
+
if (CurStreamType != LLVMIRBitstream) return 0;
switch (BlockID) {
@@ -289,7 +310,7 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned IndentLevel) {
const char *BlockName = 0;
if (Dump) {
std::cerr << Indent << "<";
- if ((BlockName = GetBlockName(BlockID)))
+ if ((BlockName = GetBlockName(BlockID, *Stream.getBitStreamReader())))
std::cerr << BlockName;
else
std::cerr << "UnknownBlock" << BlockID;
@@ -358,11 +379,13 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned IndentLevel) {
if (Dump) {
std::cerr << Indent << " <";
- if (const char *CodeName = GetCodeName(Code, BlockID))
+ if (const char *CodeName =
+ GetCodeName(Code, BlockID, *Stream.getBitStreamReader()))
std::cerr << CodeName;
else
std::cerr << "UnknownCode" << Code;
- if (NonSymbolic && GetCodeName(Code, BlockID))
+ if (NonSymbolic &&
+ GetCodeName(Code, BlockID, *Stream.getBitStreamReader()))
std::cerr << " codeid=" << Code;
if (AbbrevID != bitc::UNABBREV_RECORD)
std::cerr << " abbrevid=" << AbbrevID;
@@ -474,7 +497,7 @@ static int AnalyzeBitcode() {
for (std::map<unsigned, PerBlockIDStats>::iterator I = BlockIDStats.begin(),
E = BlockIDStats.end(); I != E; ++I) {
std::cerr << " Block ID #" << I->first;
- if (const char *BlockName = GetBlockName(I->first))
+ if (const char *BlockName = GetBlockName(I->first, StreamFile))
std::cerr << " (" << BlockName << ")";
std::cerr << ":\n";
@@ -517,7 +540,8 @@ static int AnalyzeBitcode() {
std::cerr << "\tCode Histogram:\n";
for (unsigned i = 0, e = FreqPairs.size(); i != e; ++i) {
std::cerr << "\t\t" << FreqPairs[i].first << "\t";
- if (const char *CodeName = GetCodeName(FreqPairs[i].second, I->first))
+ if (const char *CodeName =
+ GetCodeName(FreqPairs[i].second, I->first, StreamFile))
std::cerr << CodeName << "\n";
else
std::cerr << "UnknownCode" << FreqPairs[i].second << "\n";