#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这个函数