addede new pass, improved IR

This commit is contained in:
ALEXks
2023-12-02 10:20:13 +03:00
parent f5bc37c845
commit d48a73043a
9 changed files with 42 additions and 9 deletions

View File

@@ -2218,12 +2218,12 @@ SgStatement* SgStatement::nextInChildList()
return x; return x;
} }
std::string SgStatement::sunparse() std::string SgStatement::sunparse(int lang)
{ {
#ifdef __SPF #ifdef __SPF
checkConsistence(); checkConsistence();
#endif #endif
return std::string(unparse()); return std::string(unparse(lang));
} }

View File

@@ -243,9 +243,9 @@ public:
inline void replaceSymbBySymb(SgSymbol &symb, SgSymbol &newsymb); inline void replaceSymbBySymb(SgSymbol &symb, SgSymbol &newsymb);
inline void replaceSymbBySymbSameName(SgSymbol &symb, SgSymbol &newsymb); inline void replaceSymbBySymbSameName(SgSymbol &symb, SgSymbol &newsymb);
inline void replaceTypeInStmt(SgType &old, SgType &newtype); inline void replaceTypeInStmt(SgType &old, SgType &newtype);
char* unparse(); char* unparse(int lang = 2); // FORTRAN_LANG
inline void unparsestdout(); inline void unparsestdout();
std::string sunparse(); //unparsing functions. std::string sunparse(int lang = 2); // FORTRAN_LANG
inline char *comments(); //preceding comment lines. inline char *comments(); //preceding comment lines.
void addComment(const char *com); void addComment(const char *com);
void addComment(char *com); void addComment(char *com);
@@ -3679,12 +3679,12 @@ inline SgStatement *SgStatement::getScopeForDeclare()
} }
//Kataev 07.03.2013 //Kataev 07.03.2013
inline char* SgStatement::unparse() inline char* SgStatement::unparse(int lang)
{ {
#ifdef __SPF #ifdef __SPF
checkConsistence(); checkConsistence();
#endif #endif
return UnparseBif_Char(thebif, 2); //2 - fortran language return UnparseBif_Char(thebif, lang); //2 - fortran language
} }
inline void SgStatement::unparsestdout() inline void SgStatement::unparsestdout()

View File

@@ -187,6 +187,9 @@ set(TR_FUNC_PURE _src/Transformations/function_purifying.cpp
_src/Transformations/function_purifying.h) _src/Transformations/function_purifying.h)
set(TR_GV _src/Transformations/fix_common_blocks.cpp set(TR_GV _src/Transformations/fix_common_blocks.cpp
_src/Transformations/fix_common_blocks.h) _src/Transformations/fix_common_blocks.h)
set(TR_CONV _src/Transformations/convert_to_c.cpp
_src/Transformations/convert_to_c.h)
set(TRANSFORMS set(TRANSFORMS
${TR_CP} ${TR_CP}
${TR_VECTOR} ${TR_VECTOR}
@@ -200,7 +203,8 @@ set(TRANSFORMS
${TR_FUNC_PURE} ${TR_FUNC_PURE}
${TR_LOOP_UNROLL} ${TR_LOOP_UNROLL}
${TR_GV} ${TR_GV}
${TR_PRIV_DEL}) ${TR_PRIV_DEL}
${TR_CONV})
set(CFG _src/CFGraph/IR.cpp set(CFG _src/CFGraph/IR.cpp
_src/CFGraph/IR.h _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\\VectorAssignToLoop FILES ${TR_VECTOR})
source_group (Transformations\\RenameSymbols FILES ${RENAME_SYMBOLS}) source_group (Transformations\\RenameSymbols FILES ${RENAME_SYMBOLS})
source_group (Transformations\\GlobalVariables FILES ${TR_GV}) source_group (Transformations\\GlobalVariables FILES ${TR_GV})
source_group (Transformations\\ConvertToC FILES ${TR_CONV})
source_group (CreateIntervals FILES ${CREATE_INTER_T}) source_group (CreateIntervals FILES ${CREATE_INTER_T})

View File

@@ -824,7 +824,7 @@ static SgStatement* processStatement(SgStatement* st, vector<IR_Block*>& 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()))); blocks[jump_if]->getInstruction()->setArg2(new SAPFOR::Argument(CFG_ARG_TYPE::INSTR, to_string(blocks.back()->getNumber())));
processLabel(st, firstBlock, blocks, labels); processLabel(st, firstBlock, blocks, labels);

View File

@@ -78,6 +78,7 @@
#include "Transformations/function_purifying.h" #include "Transformations/function_purifying.h"
#include "Transformations/private_removing.h" #include "Transformations/private_removing.h"
#include "Transformations/fix_common_blocks.h" #include "Transformations/fix_common_blocks.h"
#include "Transformations/convert_to_c.h"
#include "RenameSymbols/rename_symbols.h" #include "RenameSymbols/rename_symbols.h"
#include "ProjectParameters/projectParameters.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) else if (curr_regime == GET_MIN_MAX_BLOCK_DIST)
getMaxMinBlockDistribution(file, min_max_block); getMaxMinBlockDistribution(file, min_max_block);
else if (curr_regime == CONVERT_TO_C)
covertToC(file);
else if (curr_regime == TEST_PASS) else if (curr_regime == TEST_PASS)
{ {
//test pass //test pass

View File

@@ -171,6 +171,7 @@ enum passes {
REMOVE_OMP_DIRS_TRANSFORM, REMOVE_OMP_DIRS_TRANSFORM,
REMOVE_COMMENTS, REMOVE_COMMENTS,
GET_MIN_MAX_BLOCK_DIST, GET_MIN_MAX_BLOCK_DIST,
CONVERT_TO_C,
TEST_PASS, TEST_PASS,
EMPTY_PASS EMPTY_PASS
@@ -347,6 +348,7 @@ static void setPassValues()
passNames[REMOVE_OMP_DIRS_TRANSFORM] = "REMOVE_OMP_DIRS_TRANSFORM"; passNames[REMOVE_OMP_DIRS_TRANSFORM] = "REMOVE_OMP_DIRS_TRANSFORM";
passNames[REMOVE_COMMENTS] = "REMOVE_COMMENTS"; passNames[REMOVE_COMMENTS] = "REMOVE_COMMENTS";
passNames[GET_MIN_MAX_BLOCK_DIST] = "GET_MIN_MAX_BLOCK_DIST"; passNames[GET_MIN_MAX_BLOCK_DIST] = "GET_MIN_MAX_BLOCK_DIST";
passNames[CONVERT_TO_C] = "CONVERT_TO_C";
passNames[TEST_PASS] = "TEST_PASS"; passNames[TEST_PASS] = "TEST_PASS";
} }

View File

@@ -0,0 +1,20 @@
#include "../Utils/leak_detector.h"
#include <cstdio>
#include <cstring>
#include <cstring>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <set>
#include <vector>
#include <algorithm>
#include <tuple>
#include "dvm.h"
#include "convert_to_c.h"
void covertToC(SgFile* file)
{
printf("%s\n", file->firstStatement()->unparse(C_LANG));
}

View File

@@ -0,0 +1,3 @@
#pragma once
void covertToC(SgFile* file);

View File

@@ -1,3 +1,3 @@
#pragma once #pragma once
#define VERSION_SPF "2253" #define VERSION_SPF "2254"