improved checkpoints
This commit is contained in:
@@ -16,6 +16,75 @@ enum class typeEvery { TIME, ITER };
|
|||||||
|
|
||||||
static const vector<string> iosNames = { "spf_close_all", "spf_open_all", "spf_inc_num_part" };
|
static const vector<string> iosNames = { "spf_close_all", "spf_open_all", "spf_inc_num_part" };
|
||||||
|
|
||||||
|
static SgStatement* replaceForWithWhile(SgStatement* forSt)
|
||||||
|
{
|
||||||
|
checkNull(forSt, convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
|
auto forStat = isSgForStmt(forSt);
|
||||||
|
checkNull(forStat, convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
|
auto start = forStat->start();
|
||||||
|
auto end = forStat->end();
|
||||||
|
auto step = forStat->step();
|
||||||
|
if (step == NULL)
|
||||||
|
step = new SgValueExp(1);
|
||||||
|
|
||||||
|
auto stepCalc = CalculateInteger(step->copyPtr());
|
||||||
|
|
||||||
|
auto doName = forStat->doName();
|
||||||
|
|
||||||
|
checkNull(start, convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
checkNull(end, convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
|
SgStatement* insert = forSt->lexPrev();
|
||||||
|
SgStatement* doWhile = NULL;
|
||||||
|
|
||||||
|
if (stepCalc->isInteger())
|
||||||
|
{
|
||||||
|
const int stepValue = stepCalc->valueInteger();
|
||||||
|
auto cond = (stepValue > 0) ? (*new SgVarRefExp(doName) < end->copy()) : (*new SgVarRefExp(doName) > end->copy());
|
||||||
|
auto cond2 = (stepValue > 0) ? (*new SgVarRefExp(doName) > end->copy()) : (*new SgVarRefExp(doName) < end->copy());
|
||||||
|
SgLogIfStmt* logIf = new SgLogIfStmt(cond2, *new SgStatement(EXIT_STMT));
|
||||||
|
|
||||||
|
doWhile = new SgWhileStmt(&cond, NULL);
|
||||||
|
insert->insertStmtAfter(*doWhile, *insert->controlParent());
|
||||||
|
auto insertTo = doWhile->lastNodeOfStmt();
|
||||||
|
|
||||||
|
SgStatement* last = forSt->lastNodeOfStmt();
|
||||||
|
while (forSt->lexNext() != last)
|
||||||
|
{
|
||||||
|
auto body = forSt->lexNext();
|
||||||
|
insertTo->insertStmtBefore(*body->extractStmt(), *doWhile);
|
||||||
|
}
|
||||||
|
|
||||||
|
doWhile->insertStmtBefore(*new SgAssignStmt(*new SgVarRefExp(doName), start->copy() - step->copy()), *insert->controlParent());
|
||||||
|
|
||||||
|
doWhile->insertStmtAfter(*logIf, *doWhile);
|
||||||
|
doWhile->insertStmtAfter(*new SgAssignStmt(*new SgVarRefExp(doName), (*new SgVarRefExp(doName) + *step)), *doWhile);
|
||||||
|
|
||||||
|
doWhile->addComment(forSt->comments());
|
||||||
|
forSt->extractStmt();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
|
return doWhile;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void checkForToReplace(SgStatement* gotoBlock, SgStatement* goPoint)
|
||||||
|
{
|
||||||
|
//return;
|
||||||
|
auto cp = gotoBlock->controlParent();
|
||||||
|
while (goPoint->controlParent() != cp)
|
||||||
|
{
|
||||||
|
auto top = goPoint->controlParent();
|
||||||
|
if (top->variant() == FOR_NODE)
|
||||||
|
goPoint = replaceForWithWhile(top);
|
||||||
|
else
|
||||||
|
goPoint = top;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void createModule(SgStatement*& module, const string& name, bool withFile = true)
|
static void createModule(SgStatement*& module, const string& name, bool withFile = true)
|
||||||
{
|
{
|
||||||
if (module == NULL)
|
if (module == NULL)
|
||||||
@@ -950,7 +1019,7 @@ static SgStatement* createSaveBlock(const vector<SgSymbol*>& loadS, FuncInfo*& f
|
|||||||
const vector<string>& moduleNames, const int unitNum, const vector<vector<string>>& chainLocalVarNoParams,
|
const vector<string>& moduleNames, const int unitNum, const vector<vector<string>>& chainLocalVarNoParams,
|
||||||
const vector<string>& chainLabel)
|
const vector<string>& chainLabel)
|
||||||
{
|
{
|
||||||
SgStatement* storeBlock = new SgIfStmt(IF_NODE);
|
SgStatement* storeBlock = new SgIfStmt((SgExpression*)NULL);
|
||||||
|
|
||||||
vector<SgExpression*> listSpec;
|
vector<SgExpression*> listSpec;
|
||||||
listSpec.push_back(&SgAssignOp(*new SgKeywordValExp("form"), *new SgValueExp("unformatted")));
|
listSpec.push_back(&SgAssignOp(*new SgKeywordValExp("form"), *new SgValueExp("unformatted")));
|
||||||
@@ -1116,6 +1185,8 @@ static void processAllCalls(SgStatement* firstExec, const string funcToName, con
|
|||||||
|
|
||||||
gotoBlock->insertStmtBefore(*gotoNextPU, *gotoBlock);
|
gotoBlock->insertStmtBefore(*gotoNextPU, *gotoBlock);
|
||||||
saveVarToModule(localVarNoParams, execStmt, funcFromName.c_str(), procLabelSymb, labNum);
|
saveVarToModule(localVarNoParams, execStmt, funcFromName.c_str(), procLabelSymb, labNum);
|
||||||
|
|
||||||
|
checkForToReplace(gotoBlock, execStmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
execStmt = execStmt->lexNext();
|
execStmt = execStmt->lexNext();
|
||||||
@@ -1225,7 +1296,7 @@ static void processFunctionCallChain(SgStatement* func, const vector<FuncInfo*>&
|
|||||||
|
|
||||||
|
|
||||||
SgStatement* gotoBlock = new SgStatement(IF_NODE);
|
SgStatement* gotoBlock = new SgStatement(IF_NODE);
|
||||||
gotoBlock->addComment("! goto next program unit\n");
|
gotoBlock->addComment("! GOTO NEXT PROGRAM UNIT\n");
|
||||||
gotoBlock->setExpression(0, *new SgVarRefExp(loadS[0]) == *new SgValueExp(1));
|
gotoBlock->setExpression(0, *new SgVarRefExp(loadS[0]) == *new SgValueExp(1));
|
||||||
loadBlock->insertStmtAfter(*gotoBlock, *loadBlock->controlParent());
|
loadBlock->insertStmtAfter(*gotoBlock, *loadBlock->controlParent());
|
||||||
|
|
||||||
@@ -1565,6 +1636,8 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
|
|||||||
SgAssignStmt* init = new SgAssignStmt(*new SgVarRefExp(loadS[0]), *new SgValueExp(0));
|
SgAssignStmt* init = new SgAssignStmt(*new SgVarRefExp(loadS[0]), *new SgValueExp(0));
|
||||||
gotoBlock->insertStmtAfter(*init, *gotoBlock);
|
gotoBlock->insertStmtAfter(*init, *gotoBlock);
|
||||||
loadBlock->insertStmtAfter(*gotoBlock, *loadBlock->controlParent());
|
loadBlock->insertStmtAfter(*gotoBlock, *loadBlock->controlParent());
|
||||||
|
|
||||||
|
checkForToReplace(gotoBlock, point);
|
||||||
}
|
}
|
||||||
|
|
||||||
processModules(file, allFuncInfo);
|
processModules(file, allFuncInfo);
|
||||||
|
|||||||
@@ -188,6 +188,17 @@ static void removeExternalStat(SgStatement* func, const set<string>& addedInterf
|
|||||||
rem->deleteStmt();
|
rem->deleteStmt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static vector<FuncInfo*> sortByName(const T &funcs)
|
||||||
|
{
|
||||||
|
vector<FuncInfo*> funcList;
|
||||||
|
for (auto& elem : funcs)
|
||||||
|
funcList.push_back(elem);
|
||||||
|
|
||||||
|
std::sort(funcList.begin(), funcList.end(), [](FuncInfo* a, FuncInfo* b) { return a->funcName > b->funcName; });
|
||||||
|
return funcList;
|
||||||
|
}
|
||||||
|
|
||||||
void createInterfacesForAssumedSize(const map<string, vector<FuncInfo*>>& allFuncInfo)
|
void createInterfacesForAssumedSize(const map<string, vector<FuncInfo*>>& allFuncInfo)
|
||||||
{
|
{
|
||||||
set<FuncInfo*> hasAssumedSizeArrays;
|
set<FuncInfo*> hasAssumedSizeArrays;
|
||||||
@@ -251,14 +262,14 @@ void createInterfacesForAssumedSize(const map<string, vector<FuncInfo*>>& allFun
|
|||||||
if (SgFile::switchToFile(funcByFile.first) == -1)
|
if (SgFile::switchToFile(funcByFile.first) == -1)
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
for (auto& func : funcByFile.second)
|
for (auto& func : sortByName(funcByFile.second))
|
||||||
{
|
{
|
||||||
SgProgHedrStmt* prog = isSgProgHedrStmt(func->funcPointer->GetOriginal());
|
SgProgHedrStmt* prog = isSgProgHedrStmt(func->funcPointer->GetOriginal());
|
||||||
if (prog == NULL)
|
if (prog == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
set<string> addedInterfaceFor;
|
set<string> addedInterfaceFor;
|
||||||
for (auto& elem : func->callsFromV)
|
for (auto& elem : sortByName(func->callsFromV))
|
||||||
{
|
{
|
||||||
auto it = hasAssumedSizeArrays.find(elem);
|
auto it = hasAssumedSizeArrays.find(elem);
|
||||||
if (it != hasAssumedSizeArrays.end())
|
if (it != hasAssumedSizeArrays.end())
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define VERSION_SPF "2341"
|
#define VERSION_SPF "2343"
|
||||||
|
|||||||
Reference in New Issue
Block a user