fixed module added minor improvements

This commit is contained in:
ALEXks
2024-05-02 11:00:12 +03:00
parent c8a88be667
commit de52d39665

View File

@@ -16,6 +16,22 @@ enum class typeEvery { TIME, ITER };
static const vector<string> iosNames = { "spf_close_all", "spf_open_all", "spf_inc_num_part" };
static void createModule(SgStatement*& module, const string& name, bool withFile = true)
{
if (module == NULL)
{
string full_name = name;
if (withFile)
full_name += "_" + to_string(current_file_id);
module = new SgStatement(MODULE_STMT, NULL, new SgSymbol(MODULE_NAME, full_name.c_str()));
addControlEndToStmt(module->thebif);
SgStatement* global = current_file->firstStatement();
global->insertStmtAfter(*module, *global);
}
}
static SgType* createArrayCharType(int len, int dim)
{
if (dim == 0)
@@ -246,7 +262,6 @@ static void insertToOpenClose(const map<int, UserFiles>& needToSave, const vecto
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
static void createModule(SgStatement*& module, const string& name, bool withFile = true);
static bool createForIOs(const map<int, UserFiles>& filesInfo, SgStatement* func)
{
SgStatement* moduleF = NULL;
@@ -790,11 +805,9 @@ static SgStatement* createLoadBlock(const vector<SgSymbol*>& loadS, FuncInfo*& f
const char* funcName = funcI->funcName.c_str();
vector<SgStatement*> insertToLoadS;
SgStatement* loadBlock = new SgStatement(IF_NODE);
SgStatement* loadBlock = new SgIfStmt(*new SgVarRefExp(loadS[4]) == *new SgValueExp(1)); //*new SgVarRefExp(loadS[0])
loadBlock->addComment("! LOAD CHECKPOINT\n");
loadBlock->setExpression(0, *new SgVarRefExp(loadS[4]) == *new SgValueExp(1)); //*new SgVarRefExp(loadS[0])
if (funcI->isMain)
{
SgAssignStmt* init = new SgAssignStmt(*new SgVarRefExp(loadS[4]), *new SgValueExp(0));
@@ -941,8 +954,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>& chainLabel)
{
SgStatement* storeBlock = new SgStatement(IF_NODE);
SgStatement* storeBlock = new SgIfStmt(IF_NODE);
vector<SgExpression*> listSpec;
listSpec.push_back(&SgAssignOp(*new SgKeywordValExp("form"), *new SgValueExp("unformatted")));
@@ -1074,7 +1086,7 @@ static SgStatement* createSaveBlock(const vector<SgSymbol*>& loadS, FuncInfo*& f
return storeBlock;
}
static void saveVarToModule(const set<string>& localVarNoParams, SgStatement* callPE, const char* funcName,
static void saveVarToModule(const set<string>& localVarNoParams, SgStatement* callPU, const char* funcName,
SgSymbol* procLabelSymb, const int labNum)
{
for (auto localVar : localVarNoParams)
@@ -1083,12 +1095,12 @@ static void saveVarToModule(const set<string>& localVarNoParams, SgStatement* ca
SgExpression* rightEx = new SgVarRefExp(rightSymb);
SgSymbol* leftSymb = renamedNewSymb(rightSymb, funcName);
SgExpression* leftEx = new SgVarRefExp(leftSymb);
callPE->insertStmtBefore(*new SgAssignStmt(*leftEx, *rightEx), *callPE->controlParent());
callPU->insertStmtBefore(*new SgAssignStmt(*leftEx, *rightEx), *callPU->controlParent());
}
SgExpression* procLabelExpr = new SgVarRefExp(procLabelSymb);
SgExpression* labNumExpr = new SgValueExp(labNum);
callPE->insertStmtBefore(*new SgAssignStmt(*procLabelExpr, *labNumExpr), *callPE->controlParent());
callPU->insertStmtBefore(*new SgAssignStmt(*procLabelExpr, *labNumExpr), *callPU->controlParent());
}
static void processAllCalls(SgStatement* firstExec, const string funcToName, const string funcFromName,
@@ -1099,15 +1111,13 @@ static void processAllCalls(SgStatement* firstExec, const string funcToName, con
{
if (execStmt->variant() == PROC_STAT && execStmt->symbol()->identifier() == funcToName) {
const int labNum = getNextFreeLabel();
auto nextPELabel = new SgLabel(labNum);
execStmt->setLabel(*nextPELabel);
auto nextPULabel = new SgLabel(labNum);
execStmt->setLabel(*nextPULabel);
SgStatement* gotoNextPE = new SgStatement(IF_NODE);
gotoNextPE->setExpression(0, *new SgVarRefExp(procLabelSymb) == *new SgValueExp(labNum));
gotoNextPE->insertStmtAfter(*new SgGotoStmt(*nextPELabel), *gotoNextPE);
gotoBlock->insertStmtBefore(*gotoNextPE, *gotoBlock);
SgStatement* gotoNextPU = new SgIfStmt(*new SgVarRefExp(procLabelSymb) == *new SgValueExp(labNum));
gotoNextPU->insertStmtAfter(*new SgGotoStmt(*nextPULabel), *gotoNextPU);
gotoBlock->insertStmtBefore(*gotoNextPU, *gotoBlock);
saveVarToModule(localVarNoParams, execStmt, funcFromName.c_str(), procLabelSymb, labNum);
}
@@ -1513,12 +1523,9 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
const vector<string> moduleNames = findAllModules();
SgStatement* moduleF = NULL;
const string cpModule = "spf_module_checkpoint";
SgSymbol* mainModuleCpS = new SgSymbol(MODULE_NAME, cpModule.c_str());
moduleF = new SgStatement(MODULE_STMT, NULL, mainModuleCpS);
SgStatement* global = current_file->firstStatement();
global->insertStmtAfter(*moduleF, *global);
createModule(moduleF, "spf_module_checkpoint");
SgSymbol* mainModuleCpS = moduleF->symbol();
for (auto& checkps : inFileCp)
{
const int cpLine = checkps.first;
@@ -1610,9 +1617,7 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
SgStatement* profCallS = new SgAssignStmt(*new SgVarRefExp(profS[0]), *new SgFunctionCallExp(*timeF));
SgStatement* profCallE = new SgAssignStmt(*new SgVarRefExp(profS[1]), *new SgFunctionCallExp(*timeF));
/*
*/
vector<SgSymbol*> loadS;
vector<SgExpression*> initLoadS;
@@ -1660,14 +1665,8 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
commonVariables, createdModuleForIO, moduleNames, unitNum, funcName, chainLocalVarNoParamsa);
lastDecl->insertStmtAfter(*loadBlock, *lastDecl->controlParent());
if (funcI->isMain) {
if (funcI->isMain)
insertInitNamesOfFiles(numOfFiles, additional, files, journal, lastDecl, false);
}
//TODO:
/*set<string> elemNotDeclHere;
@@ -1679,7 +1678,7 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
for (auto& elem : elemNotDeclHere)
printf("%s\n", elem.c_str());*/
// make all new declarations
// make all new declarations
//makeDeclaration(moduleF, everyS, &initS);
makeDeclaration(moduleF, loadS, &initLoadS);
makeDeclaration(moduleF, profS);
@@ -1687,7 +1686,6 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
makeDeclaration(func, { timeF });
func->insertStmtAfter(*new SgStatement(USE_STMT, NULL, mainModuleCpS), *func);
func->insertStmtAfter(*new SgStatement(USE_STMT, NULL, proc_mainModuleCpS), *func);
//check use
@@ -1799,9 +1797,8 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
auto nextStLab = new SgLabel(labNum);
point->setLabel(*nextStLab);
SgStatement* gotoBlock = new SgStatement(IF_NODE);
SgStatement* gotoBlock = new SgIfStmt(*new SgVarRefExp(loadS[4]) == *new SgValueExp(labNum));
gotoBlock->addComment("! goto CP\n");
gotoBlock->setExpression(0, *new SgVarRefExp(loadS[4]) == *new SgValueExp(labNum));
gotoBlock->insertStmtAfter(*new SgGotoStmt(*nextStLab), *gotoBlock);
SgAssignStmt* init = new SgAssignStmt(*new SgVarRefExp(loadS[4]), *new SgValueExp(0));
@@ -1821,18 +1818,6 @@ static string cuttingType(const string& all_decl_with_init)
return all_decl_with_init.substr(0, iter);
}
static void createModule(SgStatement*& module, const string& name, bool withFile)
{
if (module == NULL)
{
module = new SgStatement(MODULE_STMT, NULL, new SgSymbol(MODULE_NAME, (name + (withFile ? to_string(current_file_id) : "")).c_str()), NULL, NULL, NULL);
addControlEndToStmt(module->thebif);
SgStatement* global = current_file->firstStatement();
global->insertStmtAfter(*module, *global);
}
}
static SgExpression* moveSaveAssignToMod(SgExpression* ex, SgStatement*& saveModule,
map<string, SgStatement*>& declLists, const string& procName, bool withInit)
{