fixed module added minor improvements
This commit is contained in:
@@ -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 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)
|
static SgType* createArrayCharType(int len, int dim)
|
||||||
{
|
{
|
||||||
if (dim == 0)
|
if (dim == 0)
|
||||||
@@ -246,7 +262,6 @@ static void insertToOpenClose(const map<int, UserFiles>& needToSave, const vecto
|
|||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
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)
|
static bool createForIOs(const map<int, UserFiles>& filesInfo, SgStatement* func)
|
||||||
{
|
{
|
||||||
SgStatement* moduleF = NULL;
|
SgStatement* moduleF = NULL;
|
||||||
@@ -790,11 +805,9 @@ static SgStatement* createLoadBlock(const vector<SgSymbol*>& loadS, FuncInfo*& f
|
|||||||
const char* funcName = funcI->funcName.c_str();
|
const char* funcName = funcI->funcName.c_str();
|
||||||
vector<SgStatement*> insertToLoadS;
|
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->addComment("! LOAD CHECKPOINT\n");
|
||||||
|
|
||||||
loadBlock->setExpression(0, *new SgVarRefExp(loadS[4]) == *new SgValueExp(1)); //*new SgVarRefExp(loadS[0])
|
|
||||||
|
|
||||||
if (funcI->isMain)
|
if (funcI->isMain)
|
||||||
{
|
{
|
||||||
SgAssignStmt* init = new SgAssignStmt(*new SgVarRefExp(loadS[4]), *new SgValueExp(0));
|
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>& moduleNames, const int unitNum, const vector<vector<string>>& chainLocalVarNoParams,
|
||||||
const vector<string>& chainLabel)
|
const vector<string>& chainLabel)
|
||||||
{
|
{
|
||||||
SgStatement* storeBlock = new SgStatement(IF_NODE);
|
SgStatement* storeBlock = new SgIfStmt(IF_NODE);
|
||||||
|
|
||||||
|
|
||||||
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")));
|
||||||
@@ -1074,7 +1086,7 @@ static SgStatement* createSaveBlock(const vector<SgSymbol*>& loadS, FuncInfo*& f
|
|||||||
return storeBlock;
|
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)
|
SgSymbol* procLabelSymb, const int labNum)
|
||||||
{
|
{
|
||||||
for (auto localVar : localVarNoParams)
|
for (auto localVar : localVarNoParams)
|
||||||
@@ -1083,12 +1095,12 @@ static void saveVarToModule(const set<string>& localVarNoParams, SgStatement* ca
|
|||||||
SgExpression* rightEx = new SgVarRefExp(rightSymb);
|
SgExpression* rightEx = new SgVarRefExp(rightSymb);
|
||||||
SgSymbol* leftSymb = renamedNewSymb(rightSymb, funcName);
|
SgSymbol* leftSymb = renamedNewSymb(rightSymb, funcName);
|
||||||
SgExpression* leftEx = new SgVarRefExp(leftSymb);
|
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* procLabelExpr = new SgVarRefExp(procLabelSymb);
|
||||||
SgExpression* labNumExpr = new SgValueExp(labNum);
|
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,
|
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) {
|
if (execStmt->variant() == PROC_STAT && execStmt->symbol()->identifier() == funcToName) {
|
||||||
const int labNum = getNextFreeLabel();
|
const int labNum = getNextFreeLabel();
|
||||||
auto nextPELabel = new SgLabel(labNum);
|
auto nextPULabel = new SgLabel(labNum);
|
||||||
execStmt->setLabel(*nextPELabel);
|
execStmt->setLabel(*nextPULabel);
|
||||||
|
|
||||||
SgStatement* gotoNextPE = new SgStatement(IF_NODE);
|
SgStatement* gotoNextPU = new SgIfStmt(*new SgVarRefExp(procLabelSymb) == *new SgValueExp(labNum));
|
||||||
gotoNextPE->setExpression(0, *new SgVarRefExp(procLabelSymb) == *new SgValueExp(labNum));
|
gotoNextPU->insertStmtAfter(*new SgGotoStmt(*nextPULabel), *gotoNextPU);
|
||||||
gotoNextPE->insertStmtAfter(*new SgGotoStmt(*nextPELabel), *gotoNextPE);
|
|
||||||
|
|
||||||
gotoBlock->insertStmtBefore(*gotoNextPE, *gotoBlock);
|
|
||||||
|
|
||||||
|
gotoBlock->insertStmtBefore(*gotoNextPU, *gotoBlock);
|
||||||
saveVarToModule(localVarNoParams, execStmt, funcFromName.c_str(), procLabelSymb, labNum);
|
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();
|
const vector<string> moduleNames = findAllModules();
|
||||||
|
|
||||||
SgStatement* moduleF = NULL;
|
SgStatement* moduleF = NULL;
|
||||||
const string cpModule = "spf_module_checkpoint";
|
createModule(moduleF, "spf_module_checkpoint");
|
||||||
SgSymbol* mainModuleCpS = new SgSymbol(MODULE_NAME, cpModule.c_str());
|
SgSymbol* mainModuleCpS = moduleF->symbol();
|
||||||
moduleF = new SgStatement(MODULE_STMT, NULL, mainModuleCpS);
|
|
||||||
SgStatement* global = current_file->firstStatement();
|
|
||||||
global->insertStmtAfter(*moduleF, *global);
|
|
||||||
|
|
||||||
for (auto& checkps : inFileCp)
|
for (auto& checkps : inFileCp)
|
||||||
{
|
{
|
||||||
const int cpLine = checkps.first;
|
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* profCallS = new SgAssignStmt(*new SgVarRefExp(profS[0]), *new SgFunctionCallExp(*timeF));
|
||||||
SgStatement* profCallE = new SgAssignStmt(*new SgVarRefExp(profS[1]), *new SgFunctionCallExp(*timeF));
|
SgStatement* profCallE = new SgAssignStmt(*new SgVarRefExp(profS[1]), *new SgFunctionCallExp(*timeF));
|
||||||
/*
|
|
||||||
|
|
||||||
*/
|
|
||||||
vector<SgSymbol*> loadS;
|
vector<SgSymbol*> loadS;
|
||||||
vector<SgExpression*> initLoadS;
|
vector<SgExpression*> initLoadS;
|
||||||
|
|
||||||
@@ -1660,14 +1665,8 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
|
|||||||
commonVariables, createdModuleForIO, moduleNames, unitNum, funcName, chainLocalVarNoParamsa);
|
commonVariables, createdModuleForIO, moduleNames, unitNum, funcName, chainLocalVarNoParamsa);
|
||||||
lastDecl->insertStmtAfter(*loadBlock, *lastDecl->controlParent());
|
lastDecl->insertStmtAfter(*loadBlock, *lastDecl->controlParent());
|
||||||
|
|
||||||
|
if (funcI->isMain)
|
||||||
|
|
||||||
if (funcI->isMain) {
|
|
||||||
insertInitNamesOfFiles(numOfFiles, additional, files, journal, lastDecl, false);
|
insertInitNamesOfFiles(numOfFiles, additional, files, journal, lastDecl, false);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//TODO:
|
//TODO:
|
||||||
/*set<string> elemNotDeclHere;
|
/*set<string> elemNotDeclHere;
|
||||||
@@ -1679,7 +1678,7 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
|
|||||||
for (auto& elem : elemNotDeclHere)
|
for (auto& elem : elemNotDeclHere)
|
||||||
printf("%s\n", elem.c_str());*/
|
printf("%s\n", elem.c_str());*/
|
||||||
|
|
||||||
// make all new declarations
|
// make all new declarations
|
||||||
//makeDeclaration(moduleF, everyS, &initS);
|
//makeDeclaration(moduleF, everyS, &initS);
|
||||||
makeDeclaration(moduleF, loadS, &initLoadS);
|
makeDeclaration(moduleF, loadS, &initLoadS);
|
||||||
makeDeclaration(moduleF, profS);
|
makeDeclaration(moduleF, profS);
|
||||||
@@ -1687,7 +1686,6 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
|
|||||||
makeDeclaration(func, { timeF });
|
makeDeclaration(func, { timeF });
|
||||||
|
|
||||||
func->insertStmtAfter(*new SgStatement(USE_STMT, NULL, mainModuleCpS), *func);
|
func->insertStmtAfter(*new SgStatement(USE_STMT, NULL, mainModuleCpS), *func);
|
||||||
|
|
||||||
func->insertStmtAfter(*new SgStatement(USE_STMT, NULL, proc_mainModuleCpS), *func);
|
func->insertStmtAfter(*new SgStatement(USE_STMT, NULL, proc_mainModuleCpS), *func);
|
||||||
|
|
||||||
//check use
|
//check use
|
||||||
@@ -1799,9 +1797,8 @@ void createCheckpoints(SgFile* file, const map<string, CommonBlock*>& commonBloc
|
|||||||
auto nextStLab = new SgLabel(labNum);
|
auto nextStLab = new SgLabel(labNum);
|
||||||
point->setLabel(*nextStLab);
|
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->addComment("! goto CP\n");
|
||||||
gotoBlock->setExpression(0, *new SgVarRefExp(loadS[4]) == *new SgValueExp(labNum));
|
|
||||||
|
|
||||||
gotoBlock->insertStmtAfter(*new SgGotoStmt(*nextStLab), *gotoBlock);
|
gotoBlock->insertStmtAfter(*new SgGotoStmt(*nextStLab), *gotoBlock);
|
||||||
SgAssignStmt* init = new SgAssignStmt(*new SgVarRefExp(loadS[4]), *new SgValueExp(0));
|
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);
|
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,
|
static SgExpression* moveSaveAssignToMod(SgExpression* ex, SgStatement*& saveModule,
|
||||||
map<string, SgStatement*>& declLists, const string& procName, bool withInit)
|
map<string, SgStatement*>& declLists, const string& procName, bool withInit)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user