diff --git a/src/GraphCall/graph_calls.cpp b/src/GraphCall/graph_calls.cpp index f583a20..4ce117d 100644 --- a/src/GraphCall/graph_calls.cpp +++ b/src/GraphCall/graph_calls.cpp @@ -18,6 +18,7 @@ #include "../GraphLoop/graph_loops_func.h" #include "../DirectiveProcessing/directive_parser.h" #include "../Utils/SgUtils.h" +#include "../Utils/json.hpp" #include "../ParallelizationRegions/ParRegions_func.h" #include "../DynamicAnalysis/gCov_parser_func.h" #include "../ExpressionTransform/expr_transform.h" @@ -37,6 +38,8 @@ using std::cout; using std::endl; using std::stack; +using json = nlohmann::json; + #define DEBUG 0 //TODO: improve parameter checking @@ -2592,4 +2595,71 @@ void setInlineAttributeToCalls(const map& allFunctions, } } +static json convertToJson(const FuncInfo* currFunc) { + json func; + + if (currFunc) + { + func["funcName"] = currFunc->funcName; + func["line"] = currFunc->linesNum.first; + func["lineEnd"] = currFunc->linesNum.second; + func["isMain"] = (int)currFunc->isMain; + func["needToInline"] = (int)currFunc->needToInline; + func["doNotInline"] = (int)currFunc->doNotInline; + func["doNotAnalyze"] = (int)currFunc->doNotAnalyze; + + json func_pars = json::array(); + + for (int z = 0; z < currFunc->funcParams.countOfPars; ++z) + { + json par; + par["inoutType"] = currFunc->funcParams.inout_types[z]; + par["identificator"] = currFunc->funcParams.identificators[z]; + par["parameterT"] = string(paramNames[currFunc->funcParams.parametersT[z]]); + + func_pars.push_back(par); + } + + func["params"] = func_pars; + + json calls_from = json::array(); + for (const auto& call_from : currFunc->callsFromDetailed) + { + json call; + call["line"] = call_from.detailCallsFrom.second; + call["funcName"] = call_from.detailCallsFrom.first; + + calls_from.push_back(call); + } + func["callsFrom"] = calls_from; + } + return func; +} + +json convertToJson(const map>& funcsByFileMap) { + json loopsByFile = json::array(); + + for (auto& byFile : funcsByFileMap) + { + json func; + const string& file = byFile.first; + + json func_array = json::array(); + for (auto& func : byFile.second) + { + auto conv = convertToJson(func); + if (!conv.empty()) + func_array.push_back(conv); + } + + func["file"] = file; + func["functions"] = func_array; + + loopsByFile.push_back(func); + } + + json allFuncs; + allFuncs["allFunctions"] = loopsByFile; + return allFuncs; +} #undef DEBUG diff --git a/src/GraphCall/graph_calls_base.cpp b/src/GraphCall/graph_calls_base.cpp index 8d55bdc..94fdd43 100644 --- a/src/GraphCall/graph_calls_base.cpp +++ b/src/GraphCall/graph_calls_base.cpp @@ -378,33 +378,6 @@ FuncInfo* isUserFunctionInProject(const string &func) return ret; } -string convertToString(const FuncInfo *currFunc) -{ - string result = ""; - if (currFunc) - { - result += "|" + currFunc->funcName + "|" + to_string(currFunc->linesNum.first) + - "#" + to_string(currFunc->linesNum.second) + - "#" + to_string(currFunc->callsFromDetailed.size()) + - "#" + to_string(currFunc->needToInline) + "#" + to_string(currFunc->doNotInline) + - "#" + to_string(currFunc->doNotAnalyze) + "#" + to_string((int)currFunc->isMain); - - result += "#" + to_string(currFunc->funcParams.countOfPars); - if (currFunc->funcParams.countOfPars) - { - for (int z = 0; z < currFunc->funcParams.countOfPars; ++z) - { - result += "#" + currFunc->funcParams.identificators[z] + "#" + to_string(currFunc->funcParams.inout_types[z]); - result += "#" + string(paramNames[currFunc->funcParams.parametersT[z]]); - } - } - - for (int i = 0; i < currFunc->callsFromDetailed.size(); ++i) - result += "|" + currFunc->callsFromDetailed[i].detailCallsFrom.first + "|" + to_string(currFunc->callsFromDetailed[i].detailCallsFrom.second); - } - return result; -} - // Find dead functions and fill callTo / callFrom information void findDeadFunctionsAndFillCalls(map> &allFuncInfo, map> &allMessages, bool noPrint) { diff --git a/src/GraphCall/graph_calls_func.h b/src/GraphCall/graph_calls_func.h index 0660d67..acba4a7 100644 --- a/src/GraphCall/graph_calls_func.h +++ b/src/GraphCall/graph_calls_func.h @@ -7,6 +7,7 @@ #include "graph_calls.h" #include "../GraphLoop/graph_loops.h" #include "../ParallelizationRegions/ParRegions.h" +#include "Utils/json.hpp" namespace Distribution { @@ -23,7 +24,6 @@ int CreateCallGraphViz(const char *fileName, const std::map> &funcByFile); std::string removeString(const std::string &toRemove, const std::string &inStr); FuncInfo* isUserFunctionInProject(const std::string &func); -std::string convertToString(const FuncInfo *currFunc); void findDeadFunctionsAndFillCalls(std::map> &allFuncInfo, std::map> &allMessages, bool noPrint = false); void createLinksBetweenFormalAndActualParams(std::map> &allFuncInfo, std::map> &arrayLinksByFuncCalls, const std::map, std::pair> &declaredArrays, @@ -53,5 +53,6 @@ void findContainsFunctions(SgStatement *st, std::vector &found, co void correctNameIfContains(SgStatement* call, SgExpression* exCall, std::string& name, const std::vector& containsFunctions, const std::string& prefix); int countPerfectLoopNest(SgStatement* st); void setInlineAttributeToCalls(const std::map& allFunctions, const std::map>>& inDataChains, const std::map>& hiddenData); +nlohmann::json convertToJson(const std::map>& funcsByFile); #endif diff --git a/src/GraphLoop/graph_loops.cpp b/src/GraphLoop/graph_loops.cpp index f275ce1..485fe21 100644 --- a/src/GraphLoop/graph_loops.cpp +++ b/src/GraphLoop/graph_loops.cpp @@ -940,28 +940,13 @@ static int getLoopState(const LoopGraph* currLoop) return loopState; } -static void printToBuffer(const LoopGraph *currLoop, const int childSize, char buf[512]) -{ - sprintf(buf, "#%d#%d#%d#%d#%d#%d#%d#%d", - currLoop->lineNum, currLoop->lineNumAfterLoop, currLoop->perfectLoop, currLoop->hasGoto, currLoop->hasPrints, childSize, getLoopState(currLoop), - currLoop->hasNonRectangularBounds); -} - -static int calculateNormalChildSize(const LoopGraph *currLoop) -{ - int count = 0; - for (auto &elem : currLoop->children) - count += (elem->lineNum > 0) ? 1 : 0; - return count; -} - static json convertToJson(const LoopGraph* currLoop) { json loop; - const auto& file = currLoop->fileName; + if (currLoop && currLoop->lineNum > 0) { - loop["file"] = file; + loop["file"] = currLoop->fileName; loop["line"] = currLoop->lineNum; loop["lineNumAfterLoop"] = currLoop->lineNumAfterLoop; loop["perfectLoop"] = currLoop->perfectLoop; @@ -974,8 +959,6 @@ static json convertToJson(const LoopGraph* currLoop) json call; call["line"] = line; call["funcName"] = func; - call["canBeInlined"] = 0; - call["parentLineOffset"] = 0; calls.push_back(call); } diff --git a/src/Utils/version.h b/src/Utils/version.h index 4a75125..67ae29b 100644 --- a/src/Utils/version.h +++ b/src/Utils/version.h @@ -1,3 +1,3 @@ #pragma once -#define VERSION_SPF "2404" +#define VERSION_SPF "2405" diff --git a/src/VisualizerCalls/get_information.cpp b/src/VisualizerCalls/get_information.cpp index 11320d6..90bd667 100644 --- a/src/VisualizerCalls/get_information.cpp +++ b/src/VisualizerCalls/get_information.cpp @@ -552,15 +552,7 @@ int SPF_GetGraphFunctions(void*& context, int winHandler, short *options, short { runPassesForVisualizer(projName, { FILL_PAR_REGIONS_LINES } ); - string resVal = ""; - resVal = to_string(allFuncInfo.size()); - for (auto f = allFuncInfo.begin(); f != allFuncInfo.end(); ++f) - { - resVal += "|" + f->first + "|" + to_string(f->second.size()); - for (int i = 0; i < f->second.size(); ++i) - resVal += convertToString(f->second[i]); - } - + string resVal = convertToJson(allFuncInfo).dump(); copyStringToShort(result, resVal); retSize = (int)resVal.size() + 1; } @@ -1429,15 +1421,7 @@ int SPF_SetFunctionsToInclude(void*& context, int winHandler, short *options, sh { runPassesForVisualizer(projName, { FIND_FUNC_TO_INCLUDE }); - string resVal = ""; - resVal = to_string(allFuncInfo.size()); - for (auto f = allFuncInfo.begin(); f != allFuncInfo.end(); ++f) - { - resVal += "|" + f->first + "|" + to_string(f->second.size()); - for (int i = 0; i < f->second.size(); ++i) - resVal += convertToString(f->second[i]); - } - + string resVal = convertToJson(allFuncInfo).dump(); copyStringToShort(result, resVal); retSize = (int)resVal.size() + 1; }