From d48a73043a5e58ef3ed05859da4442f95eff3232 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Sat, 2 Dec 2023 10:20:13 +0300 Subject: [PATCH] addede new pass, improved IR --- dvm/fdvm/trunk/Sage/Sage++/libSage++.cpp | 4 ++-- dvm/fdvm/trunk/Sage/lib/include/libSage++.h | 8 ++++---- sapfor/experts/Sapfor_2017/CMakeLists.txt | 7 ++++++- .../experts/Sapfor_2017/_src/CFGraph/IR.cpp | 2 +- sapfor/experts/Sapfor_2017/_src/Sapfor.cpp | 3 +++ sapfor/experts/Sapfor_2017/_src/Sapfor.h | 2 ++ .../_src/Transformations/convert_to_c.cpp | 20 +++++++++++++++++++ .../_src/Transformations/convert_to_c.h | 3 +++ .../experts/Sapfor_2017/_src/Utils/version.h | 2 +- 9 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 sapfor/experts/Sapfor_2017/_src/Transformations/convert_to_c.cpp create mode 100644 sapfor/experts/Sapfor_2017/_src/Transformations/convert_to_c.h diff --git a/dvm/fdvm/trunk/Sage/Sage++/libSage++.cpp b/dvm/fdvm/trunk/Sage/Sage++/libSage++.cpp index 50e59f3..0592ef1 100644 --- a/dvm/fdvm/trunk/Sage/Sage++/libSage++.cpp +++ b/dvm/fdvm/trunk/Sage/Sage++/libSage++.cpp @@ -2218,12 +2218,12 @@ SgStatement* SgStatement::nextInChildList() return x; } -std::string SgStatement::sunparse() +std::string SgStatement::sunparse(int lang) { #ifdef __SPF checkConsistence(); #endif - return std::string(unparse()); + return std::string(unparse(lang)); } diff --git a/dvm/fdvm/trunk/Sage/lib/include/libSage++.h b/dvm/fdvm/trunk/Sage/lib/include/libSage++.h index 9142d22..f94c8e4 100644 --- a/dvm/fdvm/trunk/Sage/lib/include/libSage++.h +++ b/dvm/fdvm/trunk/Sage/lib/include/libSage++.h @@ -243,9 +243,9 @@ public: inline void replaceSymbBySymb(SgSymbol &symb, SgSymbol &newsymb); inline void replaceSymbBySymbSameName(SgSymbol &symb, SgSymbol &newsymb); inline void replaceTypeInStmt(SgType &old, SgType &newtype); - char* unparse(); + char* unparse(int lang = 2); // FORTRAN_LANG inline void unparsestdout(); - std::string sunparse(); //unparsing functions. + std::string sunparse(int lang = 2); // FORTRAN_LANG inline char *comments(); //preceding comment lines. void addComment(const char *com); void addComment(char *com); @@ -3679,12 +3679,12 @@ inline SgStatement *SgStatement::getScopeForDeclare() } //Kataev 07.03.2013 -inline char* SgStatement::unparse() +inline char* SgStatement::unparse(int lang) { #ifdef __SPF checkConsistence(); #endif - return UnparseBif_Char(thebif, 2); //2 - fortran language + return UnparseBif_Char(thebif, lang); //2 - fortran language } inline void SgStatement::unparsestdout() diff --git a/sapfor/experts/Sapfor_2017/CMakeLists.txt b/sapfor/experts/Sapfor_2017/CMakeLists.txt index d6c259b..fd246f3 100644 --- a/sapfor/experts/Sapfor_2017/CMakeLists.txt +++ b/sapfor/experts/Sapfor_2017/CMakeLists.txt @@ -187,6 +187,9 @@ set(TR_FUNC_PURE _src/Transformations/function_purifying.cpp _src/Transformations/function_purifying.h) set(TR_GV _src/Transformations/fix_common_blocks.cpp _src/Transformations/fix_common_blocks.h) +set(TR_CONV _src/Transformations/convert_to_c.cpp + _src/Transformations/convert_to_c.h) + set(TRANSFORMS ${TR_CP} ${TR_VECTOR} @@ -200,7 +203,8 @@ set(TRANSFORMS ${TR_FUNC_PURE} ${TR_LOOP_UNROLL} ${TR_GV} - ${TR_PRIV_DEL}) + ${TR_PRIV_DEL} + ${TR_CONV}) set(CFG _src/CFGraph/IR.cpp _src/CFGraph/IR.h @@ -419,6 +423,7 @@ source_group (Transformations\\PrivateArrayRemoving FILES ${TR_PRIV_DEL}) source_group (Transformations\\VectorAssignToLoop FILES ${TR_VECTOR}) source_group (Transformations\\RenameSymbols FILES ${RENAME_SYMBOLS}) source_group (Transformations\\GlobalVariables FILES ${TR_GV}) +source_group (Transformations\\ConvertToC FILES ${TR_CONV}) source_group (CreateIntervals FILES ${CREATE_INTER_T}) diff --git a/sapfor/experts/Sapfor_2017/_src/CFGraph/IR.cpp b/sapfor/experts/Sapfor_2017/_src/CFGraph/IR.cpp index d08aef7..fd59b00 100644 --- a/sapfor/experts/Sapfor_2017/_src/CFGraph/IR.cpp +++ b/sapfor/experts/Sapfor_2017/_src/CFGraph/IR.cpp @@ -824,7 +824,7 @@ static SgStatement* processStatement(SgStatement* st, vector& blocks, } } - blocks.push_back(new IR_Block(new Instruction(CFG_OP::EMPTY, st))); + blocks.push_back(new IR_Block(new Instruction(CFG_OP::EMPTY, (ifSt->falseBody()) ? ifSt->falseBody() : st->lastNodeOfStmt()))); blocks[jump_if]->getInstruction()->setArg2(new SAPFOR::Argument(CFG_ARG_TYPE::INSTR, to_string(blocks.back()->getNumber()))); processLabel(st, firstBlock, blocks, labels); diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp index 469b183..e80bf3f 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp @@ -78,6 +78,7 @@ #include "Transformations/function_purifying.h" #include "Transformations/private_removing.h" #include "Transformations/fix_common_blocks.h" +#include "Transformations/convert_to_c.h" #include "RenameSymbols/rename_symbols.h" #include "ProjectParameters/projectParameters.h" @@ -1158,6 +1159,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne } else if (curr_regime == GET_MIN_MAX_BLOCK_DIST) getMaxMinBlockDistribution(file, min_max_block); + else if (curr_regime == CONVERT_TO_C) + covertToC(file); else if (curr_regime == TEST_PASS) { //test pass diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.h b/sapfor/experts/Sapfor_2017/_src/Sapfor.h index ceea0b2..0d87ccf 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.h +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.h @@ -171,6 +171,7 @@ enum passes { REMOVE_OMP_DIRS_TRANSFORM, REMOVE_COMMENTS, GET_MIN_MAX_BLOCK_DIST, + CONVERT_TO_C, TEST_PASS, EMPTY_PASS @@ -347,6 +348,7 @@ static void setPassValues() passNames[REMOVE_OMP_DIRS_TRANSFORM] = "REMOVE_OMP_DIRS_TRANSFORM"; passNames[REMOVE_COMMENTS] = "REMOVE_COMMENTS"; passNames[GET_MIN_MAX_BLOCK_DIST] = "GET_MIN_MAX_BLOCK_DIST"; + passNames[CONVERT_TO_C] = "CONVERT_TO_C"; passNames[TEST_PASS] = "TEST_PASS"; } diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/convert_to_c.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/convert_to_c.cpp new file mode 100644 index 0000000..a95e7b6 --- /dev/null +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/convert_to_c.cpp @@ -0,0 +1,20 @@ +#include "../Utils/leak_detector.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dvm.h" +#include "convert_to_c.h" + +void covertToC(SgFile* file) +{ + printf("%s\n", file->firstStatement()->unparse(C_LANG)); +} diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/convert_to_c.h b/sapfor/experts/Sapfor_2017/_src/Transformations/convert_to_c.h new file mode 100644 index 0000000..ec8c2ef --- /dev/null +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/convert_to_c.h @@ -0,0 +1,3 @@ +#pragma once + +void covertToC(SgFile* file); \ No newline at end of file diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index c2e66dd..f342a6a 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/version.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/version.h @@ -1,3 +1,3 @@ #pragma once -#define VERSION_SPF "2253" +#define VERSION_SPF "2254"