小约翰克涵 2022-06-19 20:40 采纳率: 42.9%
浏览 25
已结题

编译原理的局部优化中函数bool isManageable(string ioperater)的含义是什么

#include "main.h"

struct DAGNode {
    int number;//节点的唯一标识,与lastNum有关
    string content;//操作
    std::set<DAGNode*> parents;//父节点塞入
    DAGNode* leftChild;
    DAGNode* rightChild;
};
int lastNum = 0;//记录节点数
std::vector<DAGNode*> allNodes;
map<string, int> varNodeTable; // Node table
map<string, int> varsWithInitial; // Vars serving as initial nodes
std::set<string> crossingVars;
string currentFunc2;
std::vector<infixNotation> newInfixTable;
fstream betterInfixFile;
string newOutputBuff;

//Only codes with operand of ADD, SUB, MUL, DIV, NEG, ASSIGN, GETARR are manageable
inline bool isManageable(string ioperater) {
    if (ioperater == "ADD" || ioperater == "SUB" || ioperater == "MUL" ||
        ioperater == "DIV" || ioperater == "NEG" || ioperater == "ASSIGN" ||
        ioperater == "GETARR") {
        return true;
    }
    return false;
}



// Split basic blocks & get crossing variables
//分割基本块
void splitBlocks() {
    map<string, int> varExistenceCount;
    std::set<string> varsInBlock;
    bool isInBlock = false;
    // Check all infix notations, get existence count
    for (int i = 0; i < infixTable.size(); ++i) {
        if (isManageable(infixTable[i].ioperator)) { // Infix code is manageable
            if (!isInBlock) { // This line of code is following an other kind of basic block
                isInBlock = true;
                checkVarExistenceCount(varExistenceCount, varsInBlock);
                // Empty vars in block
                varsInBlock.clear();
            }
        }
        else { // Infix code is not manageable
            if (isInBlock) { // This line of code is following an other kind of basic block
                isInBlock = false;
                checkVarExistenceCount(varExistenceCount, varsInBlock);
                // Empty vars in block
                varsInBlock.clear();
            }
        }
        //insert infixtable node i into varsInBlock
        if (infixTable[i].ioperator != "CONST" && infixTable[i].ioperator != "VAR" &&
            infixTable[i].ioperator != "FUNC" && infixTable[i].ioperator != "PARAM") {
            // Declarations don't take in count
            insertOperands(varsInBlock, infixTable[i]);
        }
    }

    // Manage the rest codes   最后一个块没有判断
    checkVarExistenceCount(varExistenceCount, varsInBlock);

    // Store element with existence count over 1 to crossingVars
    for (map<string, int>::iterator it = varExistenceCount.begin(); it != varExistenceCount.end();
        ++it) {
        if (it->second > 1) { // Var cross basic blocks
            crossingVars.insert(it->first);
        }
    }
}

对于编译原理中的局部优化中函数bool isManageable(string ioperater)是什么意思,什么叫manageable;以及为什么后面的分割块函数部分要调用isManageable这个函数

  • 写回答

1条回答 默认 最新

  • m0_58688645 2022-06-19 21:07
    关注

    斗舞

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 6月26日
  • 修改了问题 6月19日
  • 创建了问题 6月19日

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境