added json for call graph
This commit is contained in:
@@ -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<string, FuncInfo*>& 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<string, vector<FuncInfo*>>& 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
|
||||
|
||||
@@ -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<string, vector<FuncInfo*>> &allFuncInfo, map<string, vector<Messages>> &allMessages, bool noPrint)
|
||||
{
|
||||
|
||||
@@ -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<std::string, std::ve
|
||||
int CreateFuncInfo(const char *fileName, const std::map<std::string, std::vector<FuncInfo*>> &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<std::string, std::vector<FuncInfo*>> &allFuncInfo, std::map<std::string, std::vector<Messages>> &allMessages, bool noPrint = false);
|
||||
void createLinksBetweenFormalAndActualParams(std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo, std::map<DIST::Array*, std::set<DIST::Array*>> &arrayLinksByFuncCalls,
|
||||
const std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>> &declaredArrays,
|
||||
@@ -53,5 +53,6 @@ void findContainsFunctions(SgStatement *st, std::vector<SgStatement*> &found, co
|
||||
void correctNameIfContains(SgStatement* call, SgExpression* exCall, std::string& name, const std::vector<SgStatement*>& containsFunctions, const std::string& prefix);
|
||||
int countPerfectLoopNest(SgStatement* st);
|
||||
void setInlineAttributeToCalls(const std::map<std::string, FuncInfo*>& allFunctions, const std::map<std::string, std::set<std::pair<std::string, int>>>& inDataChains, const std::map<std::string, std::vector<SgStatement*>>& hiddenData);
|
||||
nlohmann::json convertToJson(const std::map<std::string, std::vector<FuncInfo*>>& funcsByFile);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user