code refactoring
This commit is contained in:
@@ -337,7 +337,9 @@ set(PROJ_MAN _src/ProjectManipulation/ParseFiles.cpp
|
||||
_src/ProjectManipulation/PerfAnalyzer.cpp
|
||||
_src/ProjectManipulation/PerfAnalyzer.h
|
||||
_src/ProjectManipulation/FileInfo.cpp
|
||||
_src/ProjectManipulation/FileInfo.h)
|
||||
_src/ProjectManipulation/FileInfo.h
|
||||
_src/ProjectManipulation/ConvertFiles.cpp
|
||||
_src/ProjectManipulation/ConvertFiles.h)
|
||||
|
||||
set(PARSER ${parser_sources}/cftn.c
|
||||
${parser_sources}/errors.c
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "../Utils/leak_detector.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../Utils/errors.h"
|
||||
#include "../Utils/SgUtils.h"
|
||||
|
||||
#include "ConvertFiles.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern int convert_file(int argc, char* argv[], const char* proj_name);
|
||||
|
||||
void convertFiles(int argc, char* argv[], const char* proj_name)
|
||||
{
|
||||
convert_file(argc, argv, proj_name);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
void convertFiles(int argc, char* argv[], const char* proj_name = "dvm.proj");
|
||||
@@ -313,13 +313,12 @@ static vector<string> parseList(vector<FileInfo>& listOfProject,
|
||||
#else
|
||||
sendMessage_2lvl(L" processing file '" + to_wstring(file) + L"'");
|
||||
#endif
|
||||
StdCapture stdCapture;
|
||||
stdCapture.Init();
|
||||
StdCapture::Init();
|
||||
string errorMessage = "";
|
||||
try
|
||||
{
|
||||
set<FileInfo*> filesModified;
|
||||
stdCapture.BeginCapture();
|
||||
StdCapture::BeginCapture();
|
||||
if (needToInclude)
|
||||
filesModified = applyModuleDeclsForFile(&elem, mapFiles, moduleDelc, mapModuleDeps, modDirectOrder, optSplited, needToIncludeForInline);
|
||||
else if (needToIncludeForInline) // TODO for modules
|
||||
@@ -334,22 +333,22 @@ static vector<string> parseList(vector<FileInfo>& listOfProject,
|
||||
}
|
||||
|
||||
elem.error = retCode;
|
||||
stdCapture.EndCapture();
|
||||
errorMessage = stdCapture.GetCapture();
|
||||
StdCapture::EndCapture();
|
||||
errorMessage = StdCapture::GetCapture();
|
||||
checkRetCode(elem, errorMessage);
|
||||
}
|
||||
catch (int err)
|
||||
{
|
||||
stdCapture.EndCapture();
|
||||
errorMessage = stdCapture.GetCapture();
|
||||
StdCapture::EndCapture();
|
||||
errorMessage = StdCapture::GetCapture();
|
||||
|
||||
if (needToInclude || needToIncludeForInline)
|
||||
restoreOriginalText(listOfProject);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
stdCapture.EndCapture();
|
||||
errorMessage = stdCapture.GetCapture();
|
||||
StdCapture::EndCapture();
|
||||
errorMessage = StdCapture::GetCapture();
|
||||
|
||||
if (needToInclude || needToIncludeForInline)
|
||||
restoreOriginalText(listOfProject);
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
#include "../Utils/errors.h"
|
||||
#include "../Utils/SgUtils.h"
|
||||
#include "../VisualizerCalls/get_information.h"
|
||||
#include "../VisualizerCalls/SendMessage.h"
|
||||
|
||||
#include "StdCapture.h"
|
||||
|
||||
@@ -26,13 +24,22 @@ int pppaAnalyzer(const char* options)
|
||||
for (int z = 0; z < splited.size(); ++z)
|
||||
argv[z] = (char*)splited[z].c_str();
|
||||
|
||||
StdCapture stdCapture;
|
||||
stdCapture.Init();
|
||||
StdCapture::Init();
|
||||
string errorMessage = "";
|
||||
int retCode = pppa_analyzer(splited.size(), argv);
|
||||
stdCapture.EndCapture();
|
||||
errorMessage = stdCapture.GetCapture();
|
||||
StdCapture::EndCapture();
|
||||
errorMessage = StdCapture::GetCapture();
|
||||
|
||||
delete []argv;
|
||||
return retCode;
|
||||
}
|
||||
|
||||
void pppaAnalyzer(int argc, char** argv)
|
||||
{
|
||||
int code = pppa_analyzer(argc, argv);
|
||||
if (code == 0)
|
||||
printf("PPPA was completed successfully\n");
|
||||
else
|
||||
printf("PPPA was completed with error code %d\n", code);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
int pppaAnalyzer(const char* options);
|
||||
void pppaAnalyzer(int argc, char** argv);
|
||||
|
||||
@@ -30,18 +30,18 @@
|
||||
#define STD_ERR_FD (fileno(stderr))
|
||||
#endif
|
||||
|
||||
static int m_pipe[2];
|
||||
static int m_oldStdOut;
|
||||
static int m_oldStdErr;
|
||||
static bool m_capturing;
|
||||
static std::mutex m_mutex;
|
||||
static std::string m_captured;
|
||||
|
||||
class StdCapture
|
||||
{
|
||||
int m_pipe[2];
|
||||
int m_oldStdOut;
|
||||
int m_oldStdErr;
|
||||
bool m_capturing;
|
||||
std::mutex m_mutex;
|
||||
std::string m_captured;
|
||||
|
||||
enum PIPES { READ, WRITE };
|
||||
|
||||
int secure_dup(int src)
|
||||
static int secure_dup(int src)
|
||||
{
|
||||
int ret = -1;
|
||||
bool fd_blocked = false;
|
||||
@@ -55,7 +55,7 @@ class StdCapture
|
||||
return ret;
|
||||
}
|
||||
|
||||
void secure_pipe(int* pipes)
|
||||
static void secure_pipe(int* pipes)
|
||||
{
|
||||
int ret = -1;
|
||||
bool fd_blocked = false;
|
||||
@@ -73,7 +73,7 @@ class StdCapture
|
||||
} while (ret < 0);
|
||||
}
|
||||
|
||||
void secure_dup2(int src, int dest)
|
||||
static void secure_dup2(int src, int dest)
|
||||
{
|
||||
int ret = -1;
|
||||
bool fd_blocked = false;
|
||||
@@ -86,7 +86,7 @@ class StdCapture
|
||||
} while (ret < 0);
|
||||
}
|
||||
|
||||
void secure_close(int& fd)
|
||||
static void secure_close(int& fd)
|
||||
{
|
||||
int ret = -1;
|
||||
bool fd_blocked = false;
|
||||
@@ -102,7 +102,7 @@ class StdCapture
|
||||
}
|
||||
|
||||
public:
|
||||
void Init()
|
||||
static void Init()
|
||||
{
|
||||
// make stdout & stderr streams unbuffered
|
||||
// so that we don't need to flush the streams
|
||||
@@ -113,7 +113,7 @@ public:
|
||||
setvbuf(stderr, NULL, _IONBF, 0);
|
||||
}
|
||||
|
||||
void BeginCapture()
|
||||
static void BeginCapture()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (m_capturing)
|
||||
@@ -130,13 +130,13 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
bool IsCapturing()
|
||||
static bool IsCapturing()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return m_capturing;
|
||||
}
|
||||
|
||||
void EndCapture()
|
||||
static void EndCapture()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (!m_capturing)
|
||||
@@ -182,7 +182,7 @@ public:
|
||||
m_capturing = false;
|
||||
}
|
||||
|
||||
std::string GetCapture()
|
||||
static std::string GetCapture()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return m_captured;
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#include "Utils/errors.h"
|
||||
#include "Utils/SgUtils.h"
|
||||
#include "ProjectManipulation/ParseFiles.h"
|
||||
#include "ProjectManipulation/PerfAnalyzer.h"
|
||||
#include "ProjectManipulation/ConvertFiles.h"
|
||||
|
||||
#include "LoopAnalyzer/loop_analyzer.h"
|
||||
#include "LoopAnalyzer/loop_analyzer_nodist.h"
|
||||
@@ -2566,8 +2568,6 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
|
||||
}
|
||||
}
|
||||
|
||||
extern int pppa_analyzer(int argv, char** argc);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int leakMemDump = 0;
|
||||
@@ -2730,17 +2730,12 @@ int main(int argc, char **argv)
|
||||
parallizeFreeLoops = 1;
|
||||
else if (string(curr_arg) == "-parse")
|
||||
parseFiles(argc - (i + 1), argv + (i + 1));
|
||||
else if (string(curr_arg) == "-pppa")
|
||||
pppaAnalyzer(argc - (i + 1), argv + (i + 1));
|
||||
else if (string(curr_arg) == "-fdvm")
|
||||
convertFiles(argc - (i + 1), argv + (i + 1));
|
||||
else if (string(curr_arg) == "-mpi")
|
||||
mpiProgram = 1;
|
||||
else if (string(curr_arg) == "-pppa")
|
||||
{
|
||||
int code = pppa_analyzer(argc - i, argv + i);
|
||||
if (code == 0)
|
||||
printf("PPPA was completed successfully\n");
|
||||
else
|
||||
printf("PPPA was completed with error code %d\n", code);
|
||||
exit(0);
|
||||
}
|
||||
else if (string(curr_arg) == "-client")
|
||||
{
|
||||
runAsClient = true;
|
||||
|
||||
@@ -151,6 +151,8 @@ void printHelp(const char **passNames, const int lastPass)
|
||||
printf(" -allVars get all parallel versions\n");
|
||||
printf(" -var N get specific parallel version, N=1,2,..\n");
|
||||
printf(" -parse run parser with next option (-inl option allow to parse project for -inlineH/I regime)\n");
|
||||
printf(" -pppa run performance statistic analyzer \n");
|
||||
printf(" -fdvm run fdvm convertation\n");
|
||||
printf(" -inlineH <funcName> run hierarchical inlining for all functions called from 'funcName'\n");
|
||||
printf(" -inlineI <funcName> <lineNum> <fileName> run incremental inlining for function 'funcName' on 'lineNum' of 'fileName'\n");
|
||||
printf(" -passInfo print passes information\n");
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define VERSION_SPF "2276"
|
||||
#define VERSION_SPF "2277"
|
||||
|
||||
Reference in New Issue
Block a user