From d5d5514e17f13d5e5dbc6b71cef327b2a2974a0a Mon Sep 17 00:00:00 2001 From: ALEXks Date: Mon, 10 Feb 2025 12:16:52 +0300 Subject: [PATCH] fixed function analysis --- .../_src/GraphCall/graph_calls.cpp | 49 ++++++++++----- .../_src/GraphCall/graph_calls_base.cpp | 59 +++++++++++-------- .../experts/Sapfor_2017/_src/Utils/version.h | 2 +- 3 files changed, 68 insertions(+), 42 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.cpp b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.cpp index 945ae77..35c3dfb 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.cpp +++ b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.cpp @@ -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 &found, const b } } -static void fillIn(FuncInfo *currF, SgExpression *ex, const map &parNames) +static void fillIn(FuncInfo *currF, SgExpression *ex, const map &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 &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 (!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) + fillIn(currF, st->expr(i), parNames, false); + } + } } } } @@ -997,8 +1015,7 @@ static FuncInfo* createNewFuction(const string& funcName, SgStatement *st, SgSta __spf_print(1, "set NOINLINE attribute for function '%s'\n", funcName.c_str()); currInfo->doNotInline = true; } - - currInfo->funcParams.completeParams(); + return currInfo; } diff --git a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls_base.cpp b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls_base.cpp index 47f8fef..8d55bdc 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls_base.cpp +++ b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls_base.cpp @@ -94,9 +94,9 @@ void updateFuncInfo(const map> &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> &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()) + auto& parOfCalled = funcCall.NoOfParamUsedForCall[parNo]; + if (parOfCalled.size() == 0) + continue; + + if (calledFunc->funcParams.isArgOut(parNo)) { - if (calledFunc->funcParams.isArgOut(parNo)) - for (auto& parOfCalling : parOfCalled) + for (auto& num : parOfCalled) + { + if (!currInfo->funcParams.isArgOut(num)) { - if (!currInfo->funcParams.isArgOut(parOfCalling)) - { - currInfo->funcParams.inout_types[parOfCalling] |= OUT_BIT; - changesDone = true; - } - } - - if (calledFunc->funcParams.isArgIn(parNo)) - for (auto& parOfCalling : parOfCalled) - { - 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++; } } } @@ -169,12 +171,19 @@ void updateFuncInfo(const map> &allFuncInfo) // const { currInfo->linesOfIO.insert(lineOfCall); changesDone = true; - } + } } } } } } 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> &funcByFile, map &V, vector &E) diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index 8182a93..d9a229a 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/version.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/version.h @@ -1,3 +1,3 @@ #pragma once -#define VERSION_SPF "2386" +#define VERSION_SPF "2387"