moved LoopGraph to json

This commit is contained in:
ALEXks
2025-04-01 15:28:53 +03:00
parent 381e3c5355
commit a7f199ad4c
7 changed files with 22938 additions and 27 deletions

View File

@@ -26,11 +26,11 @@
#include "../Utils/errors.h"
#include "../Utils/AstWrapper.h"
#include "../Utils/json.hpp"
#include "../DirectiveProcessing/directive_parser.h"
#include "../DynamicAnalysis/gCov_parser_func.h"
#include "../GraphCall/graph_calls_func.h"
#include "../Transformations/array_assign_to_loop.h"
using std::vector;
@@ -40,6 +40,8 @@ using std::string;
using std::wstring;
using std::pair;
using json = nlohmann::json;
#define DEBUG 0
static inline void insertLabels(SgExpression *lb, map<int, vector<int>> &gotoLabels, const int line)
{
@@ -918,7 +920,7 @@ void* LoopGraph::getRealStat(const char* file) const
}
extern int PASSES_DONE[EMPTY_PASS];
static void printToBuffer(const LoopGraph *currLoop, const int childSize, char buf[512])
static int getLoopState(const LoopGraph* currLoop)
{
int loopState = 0; // 0 - unknown, 1 - good, 2 - bad
if (PASSES_DONE[CREATE_TEMPLATE_LINKS] ||
@@ -934,8 +936,14 @@ static void printToBuffer(const LoopGraph *currLoop, const int childSize, char b
if (currLoop->hasLimitsToParallel())
loopState = 2;
}
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, loopState,
currLoop->lineNum, currLoop->lineNumAfterLoop, currLoop->perfectLoop, currLoop->hasGoto, currLoop->hasPrints, childSize, getLoopState(currLoop),
currLoop->hasNonRectangularBounds);
}
@@ -979,6 +987,92 @@ void convertToString(const LoopGraph *currLoop, string &result)
}
}
json convertToJson(const LoopGraph* currLoop)
{
json loop;
const auto& file = currLoop->fileName;
if (currLoop && currLoop->lineNum > 0)
{
loop["file"] = file;
loop["line"] = currLoop->lineNum;
loop["lineNumAfterLoop"] = currLoop->lineNumAfterLoop;
loop["perfectLoop"] = currLoop->perfectLoop;
loop["loopState"] = getLoopState(currLoop);
loop["hasNonRectangularBounds"] = (int)currLoop->hasNonRectangularBounds;
json calls = json::array();
for (auto& [func, line] : currLoop->calls)
{
json call;
call["line"] = line;
call["funcName"] = func;
call["canBeInlined"] = 0;
call["parentLineOffset"] = 0;
calls.push_back(call);
}
loop["funcCalls"] = calls;
json e_gotos = json::array();
for (auto& line : currLoop->linesOfExternalGoTo)
e_gotos.push_back(line);
loop["extGotos"] = e_gotos;
json i_gotos = json::array();
for (auto& line : currLoop->linesOfInternalGoTo)
i_gotos.push_back(line);
loop["intGotos"] = i_gotos;
json ios = json::array();
for (auto& line : currLoop->linesOfIO)
ios.push_back(line);
loop["ios"] = ios;
json stops = json::array();
for (auto& line : currLoop->linesOfStop)
stops.push_back(line);
loop["stops"] = stops;
json children = json::array();
for (const auto& ch : currLoop->children)
{
auto conv = convertToJson(ch);
if (!conv.empty())
children.push_back(conv);
}
loop["children"] = children;
}
return loop;
}
json convertToJson(const map<string, vector<LoopGraph*>>& loopsByFileMap)
{
json loopsByFile = json::array();
for (auto& byFile : loopsByFileMap)
{
json loop;
const string& file = byFile.first;
json loops_array = json::array();
for (auto& loop : byFile.second)
{
auto conv = convertToJson(loop);
if (!conv.empty())
loops_array.push_back(conv);
}
loop["file"] = file;
loop["loops"] = loops_array;
loopsByFile.push_back(loop);
}
json allLoops;
allLoops["allLoops"] = loopsByFile;
return allLoops;
}
void createMapLoopGraph(const vector<LoopGraph*> &loops, map<int, LoopGraph*> &mapGraph)
{
for (auto &elem : loops)