improved CFG functions style

This commit is contained in:
ALEXks
2025-05-30 17:06:21 +03:00
parent f7c66f537d
commit 06dd8848be
3 changed files with 15 additions and 15 deletions

View File

@@ -50,27 +50,28 @@ BBlock::BasicBlock(const BBlock& copyFrom)
prev = copyFrom.prev;
}
void BBlock::addInstruction(IR_Block* item)
void BBlock::addInstruction(IR_Block* item, bool pushFront)
{
instructions.push_back(item);
if (pushFront)
instructions.insert(instructions.begin(), item);
else
instructions.push_back(item);
item->setBasicBlock(this);
}
void BBlock::addInstructionInFront(IR_Block* item)
void BBlock::addInstructionBefore(IR_Block* item, Instruction* before)
{
instructions.insert(instructions.begin(), item);
item->setBasicBlock(this);
}
checkNull(before, convertFileName(__FILE__).c_str(), __LINE__);
checkNull(item, convertFileName(__FILE__).c_str(), __LINE__);
void BBlock::addInstructionBeforeInstruction(IR_Block* item, Instruction* instruction)
{
for (auto it = instructions.begin(); it != instructions.end(); ++it) {
if ((*it)->getInstruction() == instruction) {
if ((*it)->getInstruction() == before) {
instructions.insert(it, item);
item->setBasicBlock(this);
return;
}
}
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
int BBlock::removePrev(BBlock* removed)
@@ -529,7 +530,7 @@ static int buildReachingDefs(const vector<BBlock*>& CFG, const FuncInfo* currF,
return iter;
}
//Kosaraju<EFBFBD>Sharir algorithm
//Kosaraju-Sharir algorithm
static vector<int> getStronglyConnectedComps(vector<vector<int>>& g) {
// 1. For each vertex u of the graph, mark u as unvisited. Let l be empty.
auto size = g.size();