diff options
author | Chris Lattner <sabre@nondot.org> | 2009-04-26 22:21:57 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-04-26 22:21:57 +0000 |
commit | f9a3ec86c138177c7d9b3a9d119e6d2247d14bd8 (patch) | |
tree | 15986c2b097351545c57cf4bd2e8c3b4e3d97cd7 /include/llvm/Bitcode | |
parent | 7919b966a8fd8f98346216e79df6f4722693be22 (diff) | |
download | external_llvm-f9a3ec86c138177c7d9b3a9d119e6d2247d14bd8.zip external_llvm-f9a3ec86c138177c7d9b3a9d119e6d2247d14bd8.tar.gz external_llvm-f9a3ec86c138177c7d9b3a9d119e6d2247d14bd8.tar.bz2 |
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 'include/llvm/Bitcode')
-rw-r--r-- | include/llvm/Bitcode/BitCodes.h | 6 | ||||
-rw-r--r-- | include/llvm/Bitcode/BitstreamReader.h | 36 |
2 files changed, 36 insertions, 6 deletions
diff --git a/include/llvm/Bitcode/BitCodes.h b/include/llvm/Bitcode/BitCodes.h index faf3fc7..449dc35 100644 --- a/include/llvm/Bitcode/BitCodes.h +++ b/include/llvm/Bitcode/BitCodes.h @@ -66,10 +66,12 @@ namespace bitc { /// BlockInfoCodes - The blockinfo block contains metadata about user-defined /// blocks. enum BlockInfoCodes { - BLOCKINFO_CODE_SETBID = 1 // SETBID: [blockid#] // DEFINE_ABBREV has magic semantics here, applying to the current SETBID'd // block, instead of the BlockInfo block. - // BLOCKNAME: give string name to block, if desired. + + BLOCKINFO_CODE_SETBID = 1, // SETBID: [blockid#] + BLOCKINFO_CODE_BLOCKNAME = 2, // BLOCKNAME: [name] + BLOCKINFO_CODE_SETRECORDNAME = 3 // BLOCKINFO_CODE_SETRECORDNAME: [id, name] }; } // End bitc namespace diff --git a/include/llvm/Bitcode/BitstreamReader.h b/include/llvm/Bitcode/BitstreamReader.h index d2489d1..be3d8c5 100644 --- a/include/llvm/Bitcode/BitstreamReader.h +++ b/include/llvm/Bitcode/BitstreamReader.h @@ -30,6 +30,9 @@ public: struct BlockInfo { unsigned BlockID; std::vector<BitCodeAbbrev*> Abbrevs; + std::string Name; + + std::vector<std::pair<unsigned, std::string> > RecordNames; }; private: /// FirstChar/LastChar - This remembers the first and last bytes of the @@ -78,7 +81,7 @@ public: /// getBlockInfo - If there is block info for the specified ID, return it, /// otherwise return null. - BlockInfo *getBlockInfo(unsigned BlockID) { + const BlockInfo *getBlockInfo(unsigned BlockID) const { // Common case, the most recent entry matches BlockID. if (!BlockInfoRecords.empty() && BlockInfoRecords.back().BlockID == BlockID) return &BlockInfoRecords.back(); @@ -91,8 +94,8 @@ public: } BlockInfo &getOrCreateBlockInfo(unsigned BlockID) { - if (BlockInfo *BI = getBlockInfo(BlockID)) - return *BI; + if (const BlockInfo *BI = getBlockInfo(BlockID)) + return *const_cast<BlockInfo*>(BI); // Otherwise, add a new record. BlockInfoRecords.push_back(BlockInfo()); @@ -216,6 +219,13 @@ public: return (NextChar-BitStream->getFirstChar())*CHAR_BIT - BitsInCurWord; } + BitstreamReader *getBitStreamReader() { + return BitStream; + } + const BitstreamReader *getBitStreamReader() const { + return BitStream; + } + /// JumpToBit - Reset the stream to the specified bit number. void JumpToBit(uint64_t BitNo) { @@ -363,7 +373,8 @@ public: BlockScope.back().PrevAbbrevs.swap(CurAbbrevs); // Add the abbrevs specific to this block to the CurAbbrevs list. - if (BitstreamReader::BlockInfo *Info = BitStream->getBlockInfo(BlockID)) { + if (const BitstreamReader::BlockInfo *Info = + BitStream->getBlockInfo(BlockID)) { for (unsigned i = 0, e = static_cast<unsigned>(Info->Abbrevs.size()); i != e; ++i) { CurAbbrevs.push_back(Info->Abbrevs[i]); @@ -585,6 +596,23 @@ public: if (Record.size() < 1) return true; CurBlockInfo = &BitStream->getOrCreateBlockInfo((unsigned)Record[0]); break; + case bitc::BLOCKINFO_CODE_BLOCKNAME: { + if (!CurBlockInfo) return true; + std::string Name; + for (unsigned i = 0, e = Record.size(); i != e; ++i) + Name += (char)Record[i]; + CurBlockInfo->Name = Name; + break; + } + case bitc::BLOCKINFO_CODE_SETRECORDNAME: { + if (!CurBlockInfo) return true; + std::string Name; + for (unsigned i = 1, e = Record.size(); i != e; ++i) + Name += (char)Record[i]; + CurBlockInfo->RecordNames.push_back(std::make_pair((unsigned)Record[0], + Name)); + break; + } } } } |