Fix internal program error
This commit is contained in:
@@ -178,9 +178,9 @@ set(TR_LOOP_SPLIT _src/Transformations/loops_splitter.cpp
|
|||||||
set(TR_LOOP_UNROLL _src/Transformations/loops_unrolling.cpp
|
set(TR_LOOP_UNROLL _src/Transformations/loops_unrolling.cpp
|
||||||
_src/Transformations/loops_unrolling.h)
|
_src/Transformations/loops_unrolling.h)
|
||||||
set(TR_PRIV_BR _src/Transformations/private_arrays_resizing.cpp
|
set(TR_PRIV_BR _src/Transformations/private_arrays_resizing.cpp
|
||||||
_src/Transformations/private_arrays_resizing.h)
|
_src/Transformations/private_arrays_resizing.h)
|
||||||
set(TR_PRIV_DEL _src/Transformations/private_removing.cpp
|
set(TR_PRIV_DEL _src/Transformations/private_removing.cpp
|
||||||
_src/Transformations/private_removing.h)
|
_src/Transformations/private_removing.h)
|
||||||
set(TR_SWAP_ARR_DIMS _src/Transformations/swap_array_dims.cpp
|
set(TR_SWAP_ARR_DIMS _src/Transformations/swap_array_dims.cpp
|
||||||
_src/Transformations/swap_array_dims.h)
|
_src/Transformations/swap_array_dims.h)
|
||||||
set(TR_FUNC_DUP _src/Transformations/uniq_call_chain_dup.cpp
|
set(TR_FUNC_DUP _src/Transformations/uniq_call_chain_dup.cpp
|
||||||
@@ -190,8 +190,7 @@ set(TR_FUNC_PURE _src/Transformations/function_purifying.cpp
|
|||||||
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
|
set(TR_CONV _src/Transformations/convert_to_c.cpp
|
||||||
_src/Transformations/convert_to_c.h)
|
_src/Transformations/convert_to_c.h)
|
||||||
|
|
||||||
set(TR_IMPLICIT_NONE _src/Transformations/set_implicit_none.cpp
|
set(TR_IMPLICIT_NONE _src/Transformations/set_implicit_none.cpp
|
||||||
_src/Transformations/set_implicit_none.h)
|
_src/Transformations/set_implicit_none.h)
|
||||||
|
|
||||||
|
|||||||
@@ -5,39 +5,86 @@ using std::vector;
|
|||||||
using std::map;
|
using std::map;
|
||||||
using std::set;
|
using std::set;
|
||||||
|
|
||||||
map<char, SgType*> types;
|
static const char commonIntLetters[6] = {'i', 'j', 'k', 'm', 'n', 'l'};
|
||||||
set<SgSymbol*> allVars;
|
|
||||||
vector<SgSymbol*> varsWithoutDecl;
|
|
||||||
const char commonIntLetters[6] = {'i', 'j', 'k', 'm', 'n', 'l'};
|
|
||||||
|
|
||||||
void InitTypes();
|
static void InitTypes(map<char, SgType*> types)
|
||||||
void FillCommonTypes();
|
|
||||||
void CleanTypes();
|
|
||||||
void FunctionImplicitCheck(SgStatement* function);
|
|
||||||
void FindAllVars(SgExpression* expr);
|
|
||||||
char AddLettersToMap(SgExpression* params, SgType* type);
|
|
||||||
|
|
||||||
void ImplicitCheck(SgFile* file)
|
|
||||||
{
|
{
|
||||||
for (int functionNumber = 0; functionNumber < file->numberOfFunctions(); functionNumber++)
|
for (char letter = 'a'; letter <= 'z'; letter++)
|
||||||
{
|
types[letter] = NULL;
|
||||||
InitTypes();
|
|
||||||
FillCommonTypes();
|
|
||||||
|
|
||||||
SgStatement* function = file->functions(functionNumber);
|
|
||||||
FunctionImplicitCheck(function);
|
|
||||||
|
|
||||||
CleanTypes();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void FunctionImplicitCheck(SgStatement* function)
|
static void FillCommonTypes(map<char, SgType*> types)
|
||||||
{
|
{
|
||||||
|
for (char letter : commonIntLetters)
|
||||||
|
if (types[letter] == NULL)
|
||||||
|
types[letter] = new SgType(T_INT);
|
||||||
|
|
||||||
|
for (auto letter : types)
|
||||||
|
if (letter.second == NULL)
|
||||||
|
types[letter.first] = new SgType(T_FLOAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FindAllVars(SgExpression* expr, set<SgSymbol*>* allVars)
|
||||||
|
{
|
||||||
|
if (expr == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (expr->variant() == VAR_REF || expr->variant() == ARRAY_REF)
|
||||||
|
allVars->insert(expr->symbol());
|
||||||
|
|
||||||
|
FindAllVars(expr->lhs(), allVars);
|
||||||
|
FindAllVars(expr->rhs(), allVars);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char AddLettersToMap(SgExpression* expr, SgType* type, map<char, SgType*>& types)
|
||||||
|
{
|
||||||
|
if (expr == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (expr->variant() == CHAR_VAL)
|
||||||
|
{
|
||||||
|
SgValueExp* val = isSgValueExp(expr);
|
||||||
|
return val->charValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
char leftVal = AddLettersToMap(expr->lhs(), type, types);
|
||||||
|
char rightVal = AddLettersToMap(expr->rhs(), type, types);
|
||||||
|
|
||||||
|
if (expr->variant() == DDOT)
|
||||||
|
if (leftVal != NULL && rightVal != NULL)
|
||||||
|
for (char letter = leftVal; letter <= rightVal; letter++)
|
||||||
|
types[letter] = type;
|
||||||
|
|
||||||
|
if (expr->variant() == EXPR_LIST)
|
||||||
|
{
|
||||||
|
if (leftVal != NULL)
|
||||||
|
types[leftVal] = type;
|
||||||
|
if (rightVal != NULL)
|
||||||
|
types[rightVal] = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static map<char, SgType*> FunctionImplicitCheck(SgStatement* function, map<SgStatement*, map<char, SgType*>>& typesByFunctions)
|
||||||
|
{
|
||||||
|
set<SgSymbol*> allVars;
|
||||||
|
map<char, SgType*> types;
|
||||||
|
vector<SgSymbol*> varsWithoutDecl;
|
||||||
|
|
||||||
|
InitTypes(types);
|
||||||
|
FillCommonTypes(types);
|
||||||
|
|
||||||
|
if (typesByFunctions.find(function->controlParent()) != typesByFunctions.end())
|
||||||
|
for (auto parentType : typesByFunctions[function->controlParent()])
|
||||||
|
types[parentType.first] = parentType.second;
|
||||||
|
|
||||||
auto implicitNoneDeclaration = new SgStatement(IMPL_DECL);
|
auto implicitNoneDeclaration = new SgStatement(IMPL_DECL);
|
||||||
auto hasImplicitNone = false;
|
auto hasImplicitNone = false;
|
||||||
|
|
||||||
for (SgStatement* statement = function; statement != NULL; statement = statement->lexNext())
|
for (SgStatement* statement = function; statement != NULL; statement = statement->lexNext())
|
||||||
{
|
{
|
||||||
|
|
||||||
if (statement->variant() == IMPL_DECL)
|
if (statement->variant() == IMPL_DECL)
|
||||||
{
|
{
|
||||||
SgImplicitStmt* implicitStatement = isSgImplicitStmt(statement);
|
SgImplicitStmt* implicitStatement = isSgImplicitStmt(statement);
|
||||||
@@ -52,8 +99,8 @@ static void FunctionImplicitCheck(SgStatement* function)
|
|||||||
SgType* type = implicitStatement->implicitType(j);
|
SgType* type = implicitStatement->implicitType(j);
|
||||||
SgExpression* lettersExpression = implicitStatement->implicitRangeList(j);
|
SgExpression* lettersExpression = implicitStatement->implicitRangeList(j);
|
||||||
|
|
||||||
AddLettersToMap(lettersExpression, type);
|
AddLettersToMap(lettersExpression, type, types);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
hasImplicitNone = true;
|
hasImplicitNone = true;
|
||||||
@@ -63,9 +110,15 @@ static void FunctionImplicitCheck(SgStatement* function)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (SgStatement* statement = function; statement != function->lastExecutable(); statement = statement->lexNext())
|
for (SgStatement* statement = function;
|
||||||
|
statement != NULL && statement->variant() != CONTAINS_STMT; statement = statement->lexNext())
|
||||||
|
{
|
||||||
for (int expressionNumber = 0; expressionNumber < 3; expressionNumber++)
|
for (int expressionNumber = 0; expressionNumber < 3; expressionNumber++)
|
||||||
FindAllVars(statement->expr(expressionNumber));
|
FindAllVars(statement->expr(expressionNumber), &allVars);
|
||||||
|
|
||||||
|
if (statement == function->lastExecutable())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto var : allVars)
|
for (auto var : allVars)
|
||||||
{
|
{
|
||||||
@@ -86,7 +139,8 @@ static void FunctionImplicitCheck(SgStatement* function)
|
|||||||
|
|
||||||
if (!hasImplicitNone)
|
if (!hasImplicitNone)
|
||||||
{
|
{
|
||||||
for (SgStatement* statement = function->lexNext(); statement != NULL;)
|
for (SgStatement* statement = function->lexNext();
|
||||||
|
statement != NULL && statement->variant() != CONTAINS_STMT && isSgExecutableStatement(statement) == NULL;)
|
||||||
{
|
{
|
||||||
if (statement->variant() == IMPL_DECL)
|
if (statement->variant() == IMPL_DECL)
|
||||||
{
|
{
|
||||||
@@ -100,70 +154,26 @@ static void FunctionImplicitCheck(SgStatement* function)
|
|||||||
|
|
||||||
function->insertStmtAfter(*implicitNoneDeclaration, *function);
|
function->insertStmtAfter(*implicitNoneDeclaration, *function);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void InitTypes()
|
|
||||||
{
|
|
||||||
for (char letter = 'a'; letter <= 'z'; letter++)
|
|
||||||
types[letter] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void FillCommonTypes()
|
|
||||||
{
|
|
||||||
for (char letter : commonIntLetters)
|
|
||||||
if (types[letter] == NULL)
|
|
||||||
types[letter] = new SgType(T_INT);
|
|
||||||
|
|
||||||
for (auto letter : types)
|
|
||||||
if (letter.second == NULL)
|
|
||||||
types[letter.first] = new SgType(T_FLOAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void CleanTypes()
|
|
||||||
{
|
|
||||||
types.clear();
|
|
||||||
allVars.clear();
|
allVars.clear();
|
||||||
varsWithoutDecl.clear();
|
varsWithoutDecl.clear();
|
||||||
|
|
||||||
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void FindAllVars(SgExpression* expr)
|
void ImplicitCheck(SgFile* file)
|
||||||
{
|
{
|
||||||
if (expr == NULL)
|
map<SgStatement*, map<char, SgType*>> typesByFunctions;
|
||||||
return;
|
|
||||||
|
|
||||||
if (expr->variant() == VAR_REF || expr->variant() == ARRAY_REF)
|
for (int functionNumber = 0; functionNumber < file->numberOfFunctions(); functionNumber++)
|
||||||
allVars.insert(expr->symbol());
|
|
||||||
|
|
||||||
FindAllVars(expr->lhs());
|
|
||||||
FindAllVars(expr->rhs());
|
|
||||||
}
|
|
||||||
|
|
||||||
static char AddLettersToMap(SgExpression* expr, SgType* type)
|
|
||||||
{
|
|
||||||
if (expr == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (expr->variant() == CHAR_VAL)
|
|
||||||
{
|
{
|
||||||
SgValueExp* val = isSgValueExp(expr);
|
SgStatement* function = file->functions(functionNumber);
|
||||||
return val->charValue();
|
|
||||||
|
map<char, SgType*>& types = FunctionImplicitCheck(function, typesByFunctions);
|
||||||
|
typesByFunctions[function] = types;
|
||||||
}
|
}
|
||||||
|
|
||||||
char leftVal = AddLettersToMap(expr->lhs(), type);
|
typesByFunctions.clear();
|
||||||
char rightVal = AddLettersToMap(expr->rhs(), type);
|
|
||||||
|
|
||||||
if (expr->variant() == DDOT)
|
|
||||||
if (leftVal != NULL && rightVal != NULL)
|
|
||||||
for (char letter = leftVal; letter <= rightVal; letter++)
|
|
||||||
types[letter] = type;
|
|
||||||
|
|
||||||
if (expr->variant() == EXPR_LIST)
|
printf("%s", file->firstStatement()->unparse());
|
||||||
{
|
|
||||||
if (leftVal != NULL)
|
|
||||||
types[leftVal] = type;
|
|
||||||
if (rightVal != NULL)
|
|
||||||
types[rightVal] = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user