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


C++ LabelList::emplace_back方法代码示例

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


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

示例1: if

static bool
labelify(Shader &shader, LabelList &labels)
{
   std::stack<shadir::CfInstruction *> loopStarts; // LOOP_START*
   std::stack<shadir::CfInstruction *> pushes;     // PUSH
   std::stack<shadir::CfInstruction *> pops;       // POP*
   std::stack<shadir::AluInstruction *> predSets;  // PRED_SET*

   // Iterate over the code and find matching code patterns to labelify
   for (auto itr = shader.code.begin(); itr != shader.code.end(); ++itr) {
      auto &ins = *itr;

      if (ins->insType == shadir::Instruction::ControlFlow) {
         auto cfIns = reinterpret_cast<shadir::CfInstruction*>(ins.get());

         if (cfIns->id == latte::cf::inst::LOOP_START
             || cfIns->id == latte::cf::inst::LOOP_START_DX10
             || cfIns->id == latte::cf::inst::LOOP_START_NO_AL) {
            // Found a loop start, find a matching loop_end in the correct stack
            loopStarts.push(cfIns);
         } else if (cfIns->id == latte::cf::inst::LOOP_END) {
            assert(loopStarts.size());

            // Create a LoopStart label
            auto labelStart = new Label { Label::LoopStart, loopStarts.top() };
            loopStarts.pop();
            labels.emplace_back(labelStart);

            // Create a LoopEnd label
            auto labelEnd = new Label { Label::LoopEnd, ins.get() };
            labels.emplace_back(labelEnd);

            // Link the start and end labels
            labelEnd->linkedLabel = labelStart;
            labelStart->linkedLabel = labelEnd;
         } else if (cfIns->id == latte::cf::inst::LOOP_CONTINUE || cfIns->id == latte::cf::inst::LOOP_BREAK) {
            assert(loopStarts.size());
            assert(predSets.size());

            // Create a ConditionalStart label for the last PRED_SET
            auto labelStart = new Label { Label::ConditionalStart, predSets.top() };
            predSets.pop();
            labels.emplace_back(labelStart);

            // Create a ConditionalEnd label for after the BREAK/CONTINUE instruction
            auto labelEnd = new Label { Label::ConditionalEnd, (itr + 1)->get() };
            labels.emplace_back(labelEnd);

            // Link the start and end labels
            labelEnd->linkedLabel = labelStart;
            labelStart->linkedLabel = labelEnd;
         } else if (cfIns->id == latte::cf::inst::JUMP) {
            assert(predSets.size());
            assert(pushes.size());

            // Find the end of the jump
            auto jumpEnd = std::find_if(itr, shader.code.end(),
                                        [cfIns](auto &ins) {
                                           return ins->cfPC == cfIns->addr;
                                        });

            assert(jumpEnd != shader.code.end());

            // Check if this jump has an ELSE branch
            auto jumpElse = shader.code.end();

            if ((*jumpEnd)->insType == shadir::Instruction::ControlFlow) {
               auto jumpEndCfIns = reinterpret_cast<shadir::CfInstruction*>(jumpEnd->get());

               if (jumpEndCfIns->id == latte::cf::inst::ELSE) {
                  jumpElse = jumpEnd;

                  // Find the real end of the jump
                  jumpEnd = std::find_if(jumpElse, shader.code.end(),
                                         [jumpEndCfIns](auto &ins) {
                                            return ins->cfPC == jumpEndCfIns->addr;
                                         });

                  assert(jumpEnd != shader.code.end());
               }
            }

            // Create a conditional start label
            auto labelStart = new Label { Label::ConditionalStart, predSets.top() };
            predSets.pop();
            labels.emplace_back(labelStart);

            // Create a conditional else label, if needed
            if (jumpElse != shader.code.end()) {
               auto labelElse = new Label { Label::ConditionalElse, jumpElse->get() };
               labelElse->linkedLabel = labelStart;
               labels.emplace_back(labelElse);
            }

            // Create a conditional end label
            auto labelEnd = new Label { Label::ConditionalEnd, jumpEnd->get() };
            labels.emplace_back(labelEnd);

            // Eliminate our JUMP instruction
            labels.emplace_back(new Label { Label::Eliminated, ins.get() });
//.........这里部分代码省略.........
开发者ID:Flaw,项目名称:decaf-emu,代码行数:101,代码来源:latte_blockify.cpp


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