当前位置: 首页>>代码示例>>C++>>正文


C++ BitstreamReader::ReadCode方法代码示例

本文整理汇总了C++中BitstreamReader::ReadCode方法的典型用法代码示例。如果您正苦于以下问题:C++ BitstreamReader::ReadCode方法的具体用法?C++ BitstreamReader::ReadCode怎么用?C++ BitstreamReader::ReadCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BitstreamReader的用法示例。


在下文中一共展示了BitstreamReader::ReadCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ParseBlock

/// ParseBlock - Read a block, updating statistics, etc.
static bool ParseBlock(BitstreamReader &Stream, unsigned IndentLevel) {
  std::string Indent(IndentLevel*2, ' ');
  uint64_t BlockBitStart = Stream.GetCurrentBitNo();
  unsigned BlockID = Stream.ReadSubBlockID();

  // Get the statistics for this BlockID.
  PerBlockIDStats &BlockStats = BlockIDStats[BlockID];
  
  BlockStats.NumInstances++;
  
  // BLOCKINFO is a special part of the stream.
  if (BlockID == bitc::BLOCKINFO_BLOCK_ID) {
    if (Dump) std::cerr << Indent << "<BLOCKINFO_BLOCK/>\n";
    if (Stream.ReadBlockInfoBlock())
      return Error("Malformed BlockInfoBlock");
    uint64_t BlockBitEnd = Stream.GetCurrentBitNo();
    BlockStats.NumBits += BlockBitEnd-BlockBitStart;
    return false;
  }
  
  unsigned NumWords = 0;
  if (Stream.EnterSubBlock(BlockID, &NumWords))
    return Error("Malformed block record");

  const char *BlockName = 0;
  if (Dump) {
    std::cerr << Indent << "<";
    if ((BlockName = GetBlockName(BlockID)))
      std::cerr << BlockName;
    else
      std::cerr << "UnknownBlock" << BlockID;
    
    if (NonSymbolic && BlockName)
      std::cerr << " BlockID=" << BlockID;
    
    std::cerr << " NumWords=" << NumWords
              << " BlockCodeSize=" << Stream.GetAbbrevIDWidth() << ">\n";
  }
  
  SmallVector<uint64_t, 64> Record;

  // Read all the records for this block.
  while (1) {
    if (Stream.AtEndOfStream())
      return Error("Premature end of bitstream");

    // Read the code for this record.
    unsigned AbbrevID = Stream.ReadCode();
    switch (AbbrevID) {
    case bitc::END_BLOCK: {
      if (Stream.ReadBlockEnd())
        return Error("Error at end of block");
      uint64_t BlockBitEnd = Stream.GetCurrentBitNo();
      BlockStats.NumBits += BlockBitEnd-BlockBitStart;
      if (Dump) {
        std::cerr << Indent << "</";
        if (BlockName)
          std::cerr << BlockName << ">\n";
        else
          std::cerr << "UnknownBlock" << BlockID << ">\n";
      }
      return false;
    } 
    case bitc::ENTER_SUBBLOCK: {
      uint64_t SubBlockBitStart = Stream.GetCurrentBitNo();
      if (ParseBlock(Stream, IndentLevel+1))
        return true;
      ++BlockStats.NumSubBlocks;
      uint64_t SubBlockBitEnd = Stream.GetCurrentBitNo();
      
      // Don't include subblock sizes in the size of this block.
      BlockBitStart += SubBlockBitEnd-SubBlockBitStart;
      break;
    }
    case bitc::DEFINE_ABBREV:
      Stream.ReadAbbrevRecord();
      ++BlockStats.NumAbbrevs;
      break;
    default:
      ++BlockStats.NumRecords;
      if (AbbrevID != bitc::UNABBREV_RECORD)
        ++BlockStats.NumAbbreviatedRecords;
      
      Record.clear();
      unsigned Code = Stream.ReadRecord(AbbrevID, Record);

      // Increment the # occurrences of this code.
      if (BlockStats.CodeFreq.size() <= Code)
        BlockStats.CodeFreq.resize(Code+1);
      BlockStats.CodeFreq[Code]++;
      
      if (Dump) {
        std::cerr << Indent << "  <";
        if (const char *CodeName = GetCodeName(Code, BlockID))
          std::cerr << CodeName;
        else
          std::cerr << "UnknownCode" << Code;
        if (NonSymbolic && GetCodeName(Code, BlockID))
          std::cerr << " codeid=" << Code;
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:iphone-binutils-svn,代码行数:101,代码来源:llvm-bcanalyzer.cpp


注:本文中的BitstreamReader::ReadCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。