fixed function analysis

This commit is contained in:
ALEXks
2025-02-10 12:16:52 +03:00
committed by Dudarenko
parent 68c779790d
commit d5d5514e17
3 changed files with 68 additions and 42 deletions

View File

@@ -560,7 +560,7 @@ static void findParamInParam(SgExpression *exp, FuncInfo &currInfo)
// Searching through expression, which parameter presented with // Searching through expression, which parameter presented with
if (exp) if (exp)
{ {
if (exp->variant() == VAR_REF) if (exp->variant() == VAR_REF || isArrayRef(exp))
{ {
// check for matching with one of param of func which called this // check for matching with one of param of func which called this
//cout << "Checking " << exp->symbol()->identifier() << " for match.." << endl; //cout << "Checking " << exp->symbol()->identifier() << " for match.." << endl;
@@ -631,7 +631,7 @@ static void findParamUsedInFuncCalls(SgExpression *exp, FuncInfo &currInfo,
if (!hasRecCall(&currInfo, nameOfCallFunc)) if (!hasRecCall(&currInfo, nameOfCallFunc))
{ {
// Add func call which we've just found // Add func call which we've just found
currInfo.funcsCalledFromThis.push_back(NestedFuncCall(exp->symbol()->identifier())); currInfo.funcsCalledFromThis.push_back(NestedFuncCall(nameOfCallFunc[1]));
// For every found func call iterate through pars // For every found func call iterate through pars
//cout << "Through params of the call of " << exp->symbol()->identifier() << endl; //cout << "Through params of the call of " << exp->symbol()->identifier() << endl;
@@ -716,11 +716,11 @@ void findContainsFunctions(SgStatement *st, vector<SgStatement*> &found, const b
} }
} }
static void fillIn(FuncInfo *currF, SgExpression *ex, const map<string, int> &parNames) static void fillIn(FuncInfo *currF, SgExpression *ex, const map<string, int> &parNames, bool isInFuncPar)
{ {
if (ex) if (ex)
{ {
if (ex->variant() == VAR_REF || isArrayRef(ex)) if (!isInFuncPar && (ex->variant() == VAR_REF || isArrayRef(ex)))
{ {
const char *name = ex->symbol()->identifier(); const char *name = ex->symbol()->identifier();
if (name && name != string("")) if (name && name != string(""))
@@ -731,8 +731,15 @@ static void fillIn(FuncInfo *currF, SgExpression *ex, const map<string, int> &pa
} }
} }
fillIn(currF, ex->lhs(), parNames); if (ex->variant() == FUNC_CALL) {
fillIn(currF, ex->rhs(), parNames); SgFunctionCallExp* call = (SgFunctionCallExp*)ex;
for (int z = 0; z < call->numberOfArgs(); ++z)
fillIn(currF, call->arg(z), parNames, true);
}
else {
fillIn(currF, ex->lhs(), parNames, false);
fillIn(currF, ex->rhs(), parNames, false);
}
} }
} }
@@ -799,9 +806,9 @@ static void fillInOut(FuncInfo *currF, SgStatement *start, SgStatement *last, co
{ {
SgExpression *left = st->expr(0); SgExpression *left = st->expr(0);
fillIn(currF, left->lhs(), parNames); fillIn(currF, left->lhs(), parNames, false);
fillIn(currF, left->rhs(), parNames); fillIn(currF, left->rhs(), parNames, false);
fillIn(currF, st->expr(1), parNames); fillIn(currF, st->expr(1), parNames, false);
string symb = ""; string symb = "";
if (left->symbol()) if (left->symbol())
@@ -886,18 +893,29 @@ static void fillInOut(FuncInfo *currF, SgStatement *start, SgStatement *last, co
if (types[z] == OUT_BIT || types[z] == INOUT_BIT) if (types[z] == OUT_BIT || types[z] == INOUT_BIT)
fillType(currF, arg->symbol()->identifier(), parNames, OUT_BIT); fillType(currF, arg->symbol()->identifier(), parNames, OUT_BIT);
if (types[z] == IN_BIT || types[z] == INOUT_BIT) if (types[z] == IN_BIT || types[z] == INOUT_BIT)
fillIn(currF, arg, parNames); fillIn(currF, arg, parNames, false);
} }
else else
fillIn(currF, arg, parNames); fillIn(currF, arg, parNames, false);
} }
processed = true; processed = true;
} }
} }
if (!processed) if (!processed)
{
if (st->variant() == PROC_STAT)
{
SgCallStmt* call = (SgCallStmt*)st;
for (int z = 0; z < call->numberOfArgs(); ++z)
fillIn(currF, call->arg(z), parNames, true);
}
else
{
for (int i = 0; i < 3; ++i) for (int i = 0; i < 3; ++i)
fillIn(currF, st->expr(i), parNames); fillIn(currF, st->expr(i), parNames, false);
}
}
} }
} }
} }
@@ -998,7 +1016,6 @@ static FuncInfo* createNewFuction(const string& funcName, SgStatement *st, SgSta
currInfo->doNotInline = true; currInfo->doNotInline = true;
} }
currInfo->funcParams.completeParams();
return currInfo; return currInfo;
} }

View File

@@ -94,9 +94,9 @@ void updateFuncInfo(const map<string, vector<FuncInfo*>> &allFuncInfo) // const
// check for using parameter as index // check for using parameter as index
// Iterate through all pars of the call // Iterate through all pars of the call
int parNo = 0; for (int parNo = 0; parNo < funcCall.NoOfParamUsedForCall.size(); ++parNo)
for (auto &parOfCalled : funcCall.NoOfParamUsedForCall)
{ {
auto& parOfCalled = funcCall.NoOfParamUsedForCall[parNo];
// If this par of called func is used as index change // If this par of called func is used as index change
if (calledFunc->isParamUsedAsIndex[parNo]) if (calledFunc->isParamUsedAsIndex[parNo])
{ {
@@ -111,36 +111,38 @@ void updateFuncInfo(const map<string, vector<FuncInfo*>> &allFuncInfo) // const
} }
} }
} }
parNo++;
} }
// propagate inout types // propagate inout types
parNo = 0; for (int parNo = 0; parNo < funcCall.NoOfParamUsedForCall.size(); ++parNo)
for (auto& parOfCalled : funcCall.NoOfParamUsedForCall)
{
if (parOfCalled.size())
{ {
auto& parOfCalled = funcCall.NoOfParamUsedForCall[parNo];
if (parOfCalled.size() == 0)
continue;
if (calledFunc->funcParams.isArgOut(parNo)) if (calledFunc->funcParams.isArgOut(parNo))
for (auto& parOfCalling : parOfCalled)
{ {
if (!currInfo->funcParams.isArgOut(parOfCalling)) for (auto& num : parOfCalled)
{ {
currInfo->funcParams.inout_types[parOfCalling] |= OUT_BIT; if (!currInfo->funcParams.isArgOut(num))
{
currInfo->funcParams.inout_types[num] |= OUT_BIT;
changesDone = true; changesDone = true;
} }
} }
}
if (calledFunc->funcParams.isArgIn(parNo)) if (calledFunc->funcParams.isArgIn(parNo))
for (auto& parOfCalling : parOfCalled)
{ {
if (!currInfo->funcParams.isArgIn(parOfCalling)) for (auto& num : parOfCalled)
{ {
currInfo->funcParams.inout_types[parOfCalling] |= IN_BIT; if (!currInfo->funcParams.isArgIn(num))
{
currInfo->funcParams.inout_types[num] |= IN_BIT;
changesDone = true; changesDone = true;
} }
} }
} }
parNo++;
} }
} }
} }
@@ -175,6 +177,13 @@ void updateFuncInfo(const map<string, vector<FuncInfo*>> &allFuncInfo) // const
} }
} }
} while (changesDone); } while (changesDone);
//fill all pars IN, if they have NONE status
for (auto& it : mapFuncInfo)
{
FuncInfo* currInfo = it.second;
currInfo->funcParams.completeParams();
}
} }
int CreateCallGraphViz(const char *fileName, const map<string, vector<FuncInfo*>> &funcByFile, map<string, CallV> &V, vector<string> &E) int CreateCallGraphViz(const char *fileName, const map<string, vector<FuncInfo*>> &funcByFile, map<string, CallV> &V, vector<string> &E)

View File

@@ -1,3 +1,3 @@
#pragma once #pragma once
#define VERSION_SPF "2386" #define VERSION_SPF "2387"