From d062e52dd660b3afb6e4a88b3ef00420e3ae0df9 Mon Sep 17 00:00:00 2001 From: DenisDudarenko Date: Sun, 26 May 2024 13:53:47 +0300 Subject: [PATCH] WIP add afterLoopLine --- .../experts/Sapfor_2017/_src/CFGraph/IR.cpp | 48 ++++++++++++++----- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/CFGraph/IR.cpp b/sapfor/experts/Sapfor_2017/_src/CFGraph/IR.cpp index 4a7ae6b..82ffa21 100644 --- a/sapfor/experts/Sapfor_2017/_src/CFGraph/IR.cpp +++ b/sapfor/experts/Sapfor_2017/_src/CFGraph/IR.cpp @@ -1660,6 +1660,11 @@ void testIR(map> fullIR) { for (auto j : i.second) printBlock(j); + vector all; + for (auto j : i.second) + for (auto k : j->getInstructions()) + all.push_back(k); + vector visited(i.second.size(), 0); vector> startAndEnd; dfs(i.second[0], visited, startAndEnd, NULL); @@ -1668,23 +1673,39 @@ void testIR(map> fullIR) { vector loops; for (auto j : startAndEnd) { - auto instruction = j.second->getInstructions()[0]->getInstruction(); - if (instruction->getOperator()->variant() == FOR_NODE) { - SgForStmt* stmt = isSgForStmt(instruction->getOperator()); + auto firstInstruction = j.second->getInstructions()[0]->getInstruction(); + auto lastInstruction = j.first->getInstructions().back()->getInstruction(); + Instruction* instructionAfterLoop; + for (auto a : fullIR) + for(auto b : a.second) + for (auto c : b->getInstructions()) + if (c->getInstruction()->getNumber() == lastInstruction->getNumber() + 1) + { + instructionAfterLoop = c->getInstruction(); + break; + } + + //auto instructionAfterLoop = getInstructionByNumber(all, lastInstruction->getNumber() + 1); + cout << "first - " << firstInstruction->getNumber() << " last - " << lastInstruction->getNumber() << " after - " << instructionAfterLoop->getNumber() << endl; + + if (firstInstruction->getOperator()->variant() == FOR_NODE) { + SgForStmt* stmt = isSgForStmt(firstInstruction->getOperator()); auto tmpLoop = new LoopGraph(); tmpLoop->isFor = true; - tmpLoop->lineNum = instruction->getOperator()->lineNumber(); + tmpLoop->lineNum = firstInstruction->getOperator()->lineNumber(); + tmpLoop->lineNumAfterLoop = instructionAfterLoop->getOperator()->lineNumber(); cout << "for" << endl << stmt->sunparse() << endl; - cout << "loop start line " << tmpLoop->lineNum << endl << endl; - + cout << "loop start line " << tmpLoop->lineNum << endl; + cout << "after loop line " << tmpLoop->lineNumAfterLoop << endl << endl; loops.push_back(tmpLoop); - } else if (instruction->getOperator()->variant() == WHILE_NODE) { - SgWhileStmt* stmt = isSgWhileStmt(instruction->getOperator()); + } else if (firstInstruction->getOperator()->variant() == WHILE_NODE) { + SgWhileStmt* stmt = isSgWhileStmt(firstInstruction->getOperator()); auto tmpLoop = new LoopGraph(); - tmpLoop->lineNum = instruction->getOperator()->lineNumber(); + tmpLoop->lineNum = firstInstruction->getOperator()->lineNumber(); + tmpLoop->lineNumAfterLoop = instructionAfterLoop->getOperator()->lineNumber(); if (stmt->conditional() == NULL) { @@ -1697,14 +1718,15 @@ void testIR(map> fullIR) { cout << "while " << endl << stmt->sunparse(); } - cout << "loop start line " << tmpLoop->lineNum << endl << endl; + cout << "loop start line " << tmpLoop->lineNum << endl; + cout << "after loop line " << tmpLoop->lineNumAfterLoop << endl << endl; loops.push_back(tmpLoop); - } else if (instruction->getOperator()->variant() == LOOP_NODE) { - cout << "not known loop" << endl << instruction->getOperator()->sunparse() << endl; + } else if (firstInstruction->getOperator()->variant() == LOOP_NODE) { + cout << "not known loop" << endl << firstInstruction->getOperator()->sunparse() << endl; } else { - cout << "goto loop - " << instruction->getOperator()->sunparse() << endl; + cout << "goto loop - " << firstInstruction->getOperator()->sunparse() << endl; } }