fixed function analysis

This commit is contained in:
ALEXks
2025-02-10 12:16:52 +03:00
parent d8aa5606ef
commit 1504504d96
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
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
//cout << "Checking " << exp->symbol()->identifier() << " for match.." << endl;
@@ -631,7 +631,7 @@ static void findParamUsedInFuncCalls(SgExpression *exp, FuncInfo &currInfo,
if (!hasRecCall(&currInfo, nameOfCallFunc))
{
// 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
//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->variant() == VAR_REF || isArrayRef(ex))
if (!isInFuncPar && (ex->variant() == VAR_REF || isArrayRef(ex)))
{
const char *name = ex->symbol()->identifier();
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);
fillIn(currF, ex->rhs(), parNames);
if (ex->variant() == FUNC_CALL) {
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);
fillIn(currF, left->lhs(), parNames);
fillIn(currF, left->rhs(), parNames);
fillIn(currF, st->expr(1), parNames);
fillIn(currF, left->lhs(), parNames, false);
fillIn(currF, left->rhs(), parNames, false);
fillIn(currF, st->expr(1), parNames, false);
string symb = "";
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)
fillType(currF, arg->symbol()->identifier(), parNames, OUT_BIT);
if (types[z] == IN_BIT || types[z] == INOUT_BIT)
fillIn(currF, arg, parNames);
fillIn(currF, arg, parNames, false);
}
else
fillIn(currF, arg, parNames);
fillIn(currF, arg, parNames, false);
}
processed = true;
}
}
if (!processed)
for (int i = 0; i < 3; ++i)
fillIn(currF, st->expr(i), parNames);
{
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)
fillIn(currF, st->expr(i), parNames, false);
}
}
}
}
}
@@ -998,7 +1016,6 @@ static FuncInfo* createNewFuction(const string& funcName, SgStatement *st, SgSta
currInfo->doNotInline = true;
}
currInfo->funcParams.completeParams();
return currInfo;
}

View File

@@ -94,9 +94,9 @@ void updateFuncInfo(const map<string, vector<FuncInfo*>> &allFuncInfo) // const
// check for using parameter as index
// Iterate through all pars of the call
int parNo = 0;
for (auto &parOfCalled : funcCall.NoOfParamUsedForCall)
for (int parNo = 0; parNo < funcCall.NoOfParamUsedForCall.size(); ++parNo)
{
auto& parOfCalled = funcCall.NoOfParamUsedForCall[parNo];
// If this par of called func is used as index change
if (calledFunc->isParamUsedAsIndex[parNo])
{
@@ -111,36 +111,38 @@ void updateFuncInfo(const map<string, vector<FuncInfo*>> &allFuncInfo) // const
}
}
}
parNo++;
}
// propagate inout types
parNo = 0;
for (auto& parOfCalled : funcCall.NoOfParamUsedForCall)
for (int parNo = 0; parNo < funcCall.NoOfParamUsedForCall.size(); ++parNo)
{
if (parOfCalled.size())
{
if (calledFunc->funcParams.isArgOut(parNo))
for (auto& parOfCalling : parOfCalled)
{
if (!currInfo->funcParams.isArgOut(parOfCalling))
{
currInfo->funcParams.inout_types[parOfCalling] |= OUT_BIT;
changesDone = true;
}
}
auto& parOfCalled = funcCall.NoOfParamUsedForCall[parNo];
if (parOfCalled.size() == 0)
continue;
if (calledFunc->funcParams.isArgIn(parNo))
for (auto& parOfCalling : parOfCalled)
if (calledFunc->funcParams.isArgOut(parNo))
{
for (auto& num : parOfCalled)
{
if (!currInfo->funcParams.isArgOut(num))
{
if (!currInfo->funcParams.isArgIn(parOfCalling))
{
currInfo->funcParams.inout_types[parOfCalling] |= IN_BIT;
changesDone = true;
}
currInfo->funcParams.inout_types[num] |= OUT_BIT;
changesDone = true;
}
}
}
if (calledFunc->funcParams.isArgIn(parNo))
{
for (auto& num : parOfCalled)
{
if (!currInfo->funcParams.isArgIn(num))
{
currInfo->funcParams.inout_types[num] |= IN_BIT;
changesDone = true;
}
}
}
parNo++;
}
}
}
@@ -175,6 +177,13 @@ void updateFuncInfo(const map<string, vector<FuncInfo*>> &allFuncInfo) // const
}
}
} 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)

View File

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