From f9a3ec86c138177c7d9b3a9d119e6d2247d14bd8 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 26 Apr 2009 22:21:57 +0000 Subject: 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 --- include/llvm/Bitcode/BitstreamReader.h | 36 ++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'include/llvm/Bitcode/BitstreamReader.h') diff --git a/include/llvm/Bitcode/BitstreamReader.h b/include/llvm/Bitcode/BitstreamReader.h index d2489d19ac..be3d8c55b7 100644 --- a/include/llvm/Bitcode/BitstreamReader.h +++ b/include/llvm/Bitcode/BitstreamReader.h @@ -30,6 +30,9 @@ public: struct BlockInfo { unsigned BlockID; std::vector Abbrevs; + std::string Name; + + std::vector > 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(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(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; + } } } } -- cgit v1.2.3