cleanup and replaced parseFortranDouble to strtod

This commit is contained in:
2025-05-29 09:07:20 +03:00
parent 18edf55d15
commit ba632b29ce
5 changed files with 17 additions and 89 deletions

View File

@@ -106,7 +106,7 @@ static void updateRegionInfo(SgStatement *st, map<string, pair<Statement*, State
extendRegionInfo(st, startEnd, lines_);
set<string> calls_from_statement;
set<string> callsFromStatement;
if (st->variant() == PROC_STAT)
{
@@ -114,16 +114,16 @@ static void updateRegionInfo(SgStatement *st, map<string, pair<Statement*, State
//check contains
if (mapFuncs.find(containsPrefix + fullName) != mapFuncs.end())
fullName = containsPrefix + fullName;
calls_from_statement.insert(fullName);
callsFromStatement.insert(fullName);
}
for (int z = 0; z < 3; ++z)
findFuncCalls(st->expr(z), calls_from_statement, containsPrefix, mapFuncs);
findFuncCalls(st->expr(z), callsFromStatement, containsPrefix, mapFuncs);
string filename = st->fileName();
int line = st->lineNumber();
for (const auto &func_name : calls_from_statement)
for (const auto &func_name : callsFromStatement)
funcCallFromReg[func_name][filename].insert(line);
}
@@ -294,71 +294,6 @@ static void checkForEmpty(SgStatement *start, SgStatement *end, vector<Messages>
}
}
static bool parseFortranDouble(const char* str, double &val)
{
int base_sign = 1, exp_sign = 1;
int integer_part = 0, power = 0;
double decimal_part = 0;
while (*str && *str != '.' && *str != 'd' && *str != 'D')
{
if (*str >= '0' && *str <= '9')
integer_part = integer_part * 10 + (*str - '0');
else if (*str == '-')
base_sign = -1;
else if (*str == '+')
base_sign = 1;
str++;
}
if (*str == '.')
{
str++;
int base = 10;
while (*str >= '0' && *str <= '9')
{
decimal_part += double(*str - '0') / base;
str++;
base *= 10;
}
}
if (*str == 'd' || *str == 'D')
{
str++;
while (*str == '+' || *str == '-' || *str >= '0' && *str <= '9')
{
if (*str >= '0' && *str <= '9')
power = power * 10 + (*str - '0');
else if (*str == '-')
exp_sign = -1;
else if (*str == '+')
exp_sign = 1;
str++;
}
}
double result = integer_part + decimal_part;
for(int i = 0; i < power; i++)
{
if (exp_sign > 0)
result *= 10;
else
result /= 10;
}
if (base_sign < 0)
result = -result;
val = result;
return true;
}
void fillRegionLines(SgFile *file, vector<ParallelRegion*> &regions, vector<Messages>& messagesForFile, vector<LoopGraph*> *loops, vector<FuncInfo*> *funcs)
{
map<string, FuncInfo*> mapFuncs;
@@ -453,7 +388,6 @@ void fillRegionLines(SgFile *file, vector<ParallelRegion*> &regions, vector<Mess
while (apply_fragment)
{
auto *curr = apply_fragment->lhs();
if (curr)
{
__spf_print(1, "%s %d\n", curr->unparse(), curr->variant());
@@ -462,18 +396,15 @@ void fillRegionLines(SgFile *file, vector<ParallelRegion*> &regions, vector<Mess
{
if (curr->lhs() &&
isSgValueExp(curr->lhs()) &&
isSgValueExp(curr->lhs())->doubleValue() &&
parseFortranDouble(isSgValueExp(curr->lhs())->doubleValue(), fragmentWeight))
isSgValueExp(curr->lhs())->doubleValue())
{
fragmentWeight = strtod(isSgValueExp(curr->lhs())->doubleValue(), NULL);
__spf_print(1, "->> %lf\n", fragmentWeight);
}
else
{
__spf_print(1, "WEIGHT clause without double argument\n");
}
}
}
apply_fragment = apply_fragment->rhs();
}
}