no message
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package _VisualDVM.Repository.Component.Sapfor;
|
||||
import Common.Utils.CommonUtils;
|
||||
import _VisualDVM.Current;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
public class MessagesServer {
|
||||
ServerSocket serverSocket = null;
|
||||
Socket client = null;
|
||||
Thread thread = null;
|
||||
private int port;
|
||||
public MessagesServer() throws Exception {
|
||||
serverSocket = new ServerSocket(0, 5, InetAddress.getLoopbackAddress());
|
||||
setPort(serverSocket.getLocalPort());
|
||||
}
|
||||
public MessagesServer(int port_in) {
|
||||
port = port_in;
|
||||
}
|
||||
public void Start() {
|
||||
thread = new Thread(() -> {
|
||||
while (true) {
|
||||
try {
|
||||
client = serverSocket.accept();
|
||||
BufferedReader in = new BufferedReader(new
|
||||
InputStreamReader(client.getInputStream()));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
if (Current.HasPassForm())
|
||||
Current.getPassForm().Result.ShowSapforMessage(line);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// UI.Print(DebugPrintLevel.MessagesServer, "соединение сброшено!");
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
public void Shutdown() {
|
||||
try {
|
||||
if (client != null) {
|
||||
client.setSoLinger(true, 500);
|
||||
client.close();
|
||||
}
|
||||
if (serverSocket != null)
|
||||
serverSocket.close();
|
||||
} catch (Exception e) {
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
}
|
||||
588
src/_VisualDVM/Repository/Component/Sapfor/Sapfor.java
Normal file
588
src/_VisualDVM/Repository/Component/Sapfor/Sapfor.java
Normal file
@@ -0,0 +1,588 @@
|
||||
package _VisualDVM.Repository.Component.Sapfor;
|
||||
import Common.CommonConstants;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common.Visual.CommonUI;
|
||||
import _VisualDVM.Constants;
|
||||
import _VisualDVM.Current;
|
||||
import _VisualDVM.GlobalData.GlobalDatabase;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Visual.UI;
|
||||
import _VisualDVM.Utils;
|
||||
import _VisualDVM.GlobalData.Settings.SettingName;
|
||||
import _VisualDVM.ProjectData.Files.DBProjectFile;
|
||||
import _VisualDVM.ProjectData.Files.LanguageStyle;
|
||||
import _VisualDVM.Repository.Component.OSDComponent;
|
||||
import _VisualDVM.Repository.Component.Visualizer_2;
|
||||
import _VisualDVM.TestingSystem.Common.Test.Test;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
import Visual_DVM_2021.Passes.PassException;
|
||||
import Visual_DVM_2021.Passes.Pass_2021;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
public abstract class Sapfor extends OSDComponent {
|
||||
public static final int empty_code = -100;
|
||||
public static final int canceled_code = -99;
|
||||
public static final int invalid_proj_code = -2;
|
||||
public Vector<String> Intrinsics = new Vector<>();
|
||||
public LinkedHashMap<String, String> ModifiedFiles = new LinkedHashMap<>();
|
||||
public LinkedHashMap<String, String> OldFiles = new LinkedHashMap<>();
|
||||
int size;
|
||||
int[] sizes;
|
||||
private int errorCode;
|
||||
private String result;
|
||||
private String output;
|
||||
private String outputMessage;
|
||||
private String predictorStats;
|
||||
String PID = "";
|
||||
//-
|
||||
public static String pack(String... params) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (String param : params)
|
||||
res.append(param.length()).append(" ").append(param);
|
||||
return res.toString();
|
||||
}
|
||||
public void refreshPid() {
|
||||
try {
|
||||
// UI.Info("Calling SPF_GetCurrentPID...");
|
||||
RunAnalysis("SPF_GetCurrentPID", -1, "", "");
|
||||
PID = getResult();
|
||||
// UI.Info("PID = " + Utils.Brackets(PID));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static PassCode_2021[] getAnalysesCodes() {
|
||||
return new PassCode_2021[]{
|
||||
PassCode_2021.SPF_ParseFilesWithOrder,
|
||||
PassCode_2021.SPF_GetFileLineInfo,
|
||||
PassCode_2021.SPF_GetArrayDistributionOnlyRegions,
|
||||
PassCode_2021.SPF_GetIncludeDependencies,
|
||||
PassCode_2021.SPF_GetGraphLoops,
|
||||
PassCode_2021.SPF_GetGraphFunctions,
|
||||
PassCode_2021.SPF_GetAllDeclaratedArrays,
|
||||
PassCode_2021.SPF_GetArrayDistributionOnlyAnalysis,
|
||||
PassCode_2021.SPF_GetArrayDistribution
|
||||
};
|
||||
}
|
||||
public static PassCode_2021[] getLoopsTransformationsCodes() {
|
||||
return new PassCode_2021[]{
|
||||
PassCode_2021.SPF_LoopEndDoConverterPass,
|
||||
PassCode_2021.SPF_LoopFission,
|
||||
PassCode_2021.SPF_LoopUnion,
|
||||
PassCode_2021.SPF_LoopUnrolling
|
||||
};
|
||||
}
|
||||
public static PassCode_2021[] getPrivatesTransformationsCodes() {
|
||||
return new PassCode_2021[]{
|
||||
PassCode_2021.SPF_PrivateShrinking,
|
||||
PassCode_2021.SPF_PrivateExpansion,
|
||||
PassCode_2021.SPF_PrivateRemoving,
|
||||
PassCode_2021.SPF_InsertPrivateFromGUI
|
||||
};
|
||||
}
|
||||
public static PassCode_2021[] getProceduresTransformationsCodes() {
|
||||
return new PassCode_2021[]{
|
||||
PassCode_2021.SPF_InlineProcedures,
|
||||
PassCode_2021.SPF_InlineProceduresH,
|
||||
PassCode_2021.SPF_DuplicateFunctionChains,
|
||||
PassCode_2021.SPF_RemoveUnusedFunctions
|
||||
};
|
||||
}
|
||||
public static PassCode_2021[] getDVMTransformationsCodes() {
|
||||
return new PassCode_2021[]{
|
||||
PassCode_2021.SPF_RemoveDvmDirectivesToComments,
|
||||
PassCode_2021.SPF_RemoveDvmDirectives,
|
||||
PassCode_2021.SPF_RemoveOmpDirectives
|
||||
};
|
||||
}
|
||||
public static PassCode_2021[] getIntervalsTransformationsCodes() {
|
||||
return new PassCode_2021[]{
|
||||
PassCode_2021.SPF_CreateIntervalsTree,
|
||||
PassCode_2021.SPF_RemoveDvmIntervals
|
||||
};
|
||||
}
|
||||
public static PassCode_2021[] getRegionsTransformationsCodes() {
|
||||
return new PassCode_2021[]{
|
||||
PassCode_2021.SPF_ResolveParallelRegionConflicts,
|
||||
PassCode_2021.SPF_InsertDvmhRegions
|
||||
};
|
||||
}
|
||||
public static PassCode_2021[] getPreparationTransformationsCodes() {
|
||||
return new PassCode_2021[]{
|
||||
PassCode_2021.SPF_RenameIncludes,
|
||||
PassCode_2021.SPF_InsertIncludesPass,
|
||||
PassCode_2021.SPF_CorrectCodeStylePass,
|
||||
PassCode_2021.SPF_ConvertStructures,
|
||||
PassCode_2021.SPF_CreateCheckpoints,
|
||||
PassCode_2021.SPF_InitDeclsWithZero,
|
||||
PassCode_2021.SPF_ExpressionSubstitution,
|
||||
PassCode_2021.EraseBadSymbols,
|
||||
PassCode_2021.SPF_RemoveComments,
|
||||
PassCode_2021.SPF_RemoveDeadCode,
|
||||
PassCode_2021.CombineFiles,
|
||||
PassCode_2021.CopyProject,
|
||||
PassCode_2021.PrepareForModulesAssembly,
|
||||
PassCode_2021.DVMConvertProject,
|
||||
PassCode_2021.SPF_ResolveCommonBlockConflicts,
|
||||
PassCode_2021.SPF_InsertImplicitNone
|
||||
};
|
||||
}
|
||||
//<editor-fold desc="компонент">
|
||||
@Override
|
||||
public void GetVersionInfo() {
|
||||
try {
|
||||
RunAnalysis("SPF_GetVersionAndBuildDate", -1, "", "");
|
||||
Visualizer_2.UnpackVersionInfo(this, getResult());
|
||||
} catch (Exception e) {
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
CommonUI.Error("Не удалось получить версию компонента " + CommonUtils.DQuotes(getComponentType().getDescription()));
|
||||
}
|
||||
}
|
||||
public abstract String getUpdateCommand();
|
||||
public abstract String getRestartCommand();
|
||||
@Override
|
||||
public void Update() throws Exception {
|
||||
super.Update();
|
||||
Global.visualizer_2.Command(getUpdateCommand());
|
||||
GetVersionInfo();
|
||||
ResetAllAnalyses();
|
||||
refreshPid();
|
||||
}
|
||||
//</editor-fold>
|
||||
//--------
|
||||
//<editor-fold desc="функционал">
|
||||
public String readStatForAnalyzer(String src) throws Exception {
|
||||
RunAnalysis(
|
||||
"SPF_OpenDvmStatistic",
|
||||
-Global.messagesServer.getPort(),
|
||||
Global.packSapforSettings(),
|
||||
src);
|
||||
return result;
|
||||
}
|
||||
public void readStatToTxt(File src, File dst) throws Exception {
|
||||
RunAnalysis("SPF_StatisticAnalyzer",
|
||||
-1,
|
||||
"",
|
||||
CommonUtils.DQuotes(src.getAbsolutePath()) +
|
||||
" "
|
||||
+ CommonUtils.DQuotes(dst.getAbsolutePath())
|
||||
);
|
||||
}
|
||||
public void Restart() throws Exception {
|
||||
ResetAllAnalyses();
|
||||
Global.visualizer_2.Command(getRestartCommand());
|
||||
refreshPid();
|
||||
}
|
||||
public void Interrupt() throws Exception {
|
||||
Utils.Kill(PID, true);
|
||||
}
|
||||
public void cd(File directory_in) throws Exception {
|
||||
if (RunAnalysis("SPF_ChangeDirectory", -1, directory_in.getAbsolutePath(), "") != 0)
|
||||
throw new PassException("Sapfor: Не удалось перейти в папку "
|
||||
+ CommonUtils.Brackets(directory_in.getAbsolutePath()) +
|
||||
"\n" + "Код возврата: " + getErrorCode());
|
||||
}
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
public void setResult(String result) {
|
||||
this.result = result;
|
||||
}
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
public void setErrorCode(int errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
public String getOutput() {
|
||||
return output;
|
||||
}
|
||||
public void setOutput(String output) {
|
||||
this.output = output;
|
||||
}
|
||||
public String getOutputMessage() {
|
||||
return outputMessage;
|
||||
}
|
||||
public void setOutputMessage(String outputMessage) {
|
||||
this.outputMessage = outputMessage;
|
||||
}
|
||||
public String getPredictorStats() {
|
||||
return predictorStats;
|
||||
}
|
||||
public void setPredictorStats(String predictorStats) {
|
||||
this.predictorStats = predictorStats;
|
||||
}
|
||||
public void decodeString(String runResult) throws Exception {
|
||||
int codeIdx = runResult.indexOf(' ');
|
||||
if (codeIdx == -1) throw new PassException("Wrong input parameter");
|
||||
setErrorCode(Integer.parseInt(runResult.substring(0, codeIdx)));
|
||||
int lastCodeIdx = 0, count = 0;
|
||||
// for analysis and transformation
|
||||
for (int z = 0; z < 4; ++z) {
|
||||
lastCodeIdx = codeIdx;
|
||||
codeIdx = runResult.indexOf(' ', codeIdx + 1);
|
||||
if (codeIdx == -1) throw new PassException("Wrong input parameter");
|
||||
count = Integer.parseInt(runResult.substring(lastCodeIdx + 1, codeIdx));
|
||||
String sub = runResult.substring(codeIdx + 1, codeIdx + 1 + count);
|
||||
if (z == 0) setResult(sub);
|
||||
else if (z == 1) setOutput(sub);
|
||||
else if (z == 2) setOutputMessage(sub);
|
||||
else if (z == 3) setPredictorStats(sub);
|
||||
codeIdx += count;
|
||||
}
|
||||
// for modification
|
||||
String file_text = null;
|
||||
if (codeIdx + 1 + count < runResult.length())
|
||||
for (int z = 0; z < 3; ++z) {
|
||||
lastCodeIdx = codeIdx;
|
||||
codeIdx = runResult.indexOf(' ', codeIdx + 1);
|
||||
if (codeIdx == -1) throw new PassException("Wrong input parameter");
|
||||
count = Integer.parseInt(runResult.substring(lastCodeIdx + 1, codeIdx));
|
||||
String sub = runResult.substring(codeIdx + 1, codeIdx + 1 + count);
|
||||
if (z == 0) {
|
||||
String[] splited = sub.split("\\|");
|
||||
if (splited.length == 0 || sub.length() == 0)
|
||||
size = 0;
|
||||
else {
|
||||
size = splited.length - 1;
|
||||
sizes = new int[splited.length];
|
||||
for (int k = 0; k < size + 1; ++k)
|
||||
sizes[k] = Integer.parseInt(splited[k]);
|
||||
}
|
||||
} else if (z == 1) file_text = sub;
|
||||
else if (z == 2) {
|
||||
ModifiedFiles.put(CommonUtils.toW(sub), file_text);
|
||||
file_text = null;
|
||||
}
|
||||
codeIdx += count;
|
||||
}
|
||||
}
|
||||
//-
|
||||
public void Command(String request_in) throws Exception {
|
||||
setErrorCode(empty_code);
|
||||
outputMessage = output = result = predictorStats = "";
|
||||
size = 0;
|
||||
sizes = null;
|
||||
ModifiedFiles.clear();
|
||||
//модификации.-------------------------------------------------------------->>>>
|
||||
decodeString(Global.visualizer_2.Command(request_in).replace((char) 1, '\n'));
|
||||
}
|
||||
//-
|
||||
public int RunAnalysis(String analysisName,
|
||||
int winHandler,
|
||||
String options,
|
||||
String projName) throws Exception {
|
||||
Command("analysis:" + pack(analysisName, options, projName) + winHandler);
|
||||
return getErrorCode();
|
||||
}
|
||||
public void RunTransformation(String transformName,
|
||||
int winHandler,
|
||||
String options,
|
||||
String projName,
|
||||
String folderName,
|
||||
String addOpts) throws Exception {
|
||||
Command("transformation:" + pack(transformName, options, projName, folderName, addOpts) + winHandler);
|
||||
}
|
||||
/*
|
||||
Модификации:
|
||||
SPF_ModifyArrayDistribution (addOpt1_c -> regId, addOpt2_c-> int64_t arrArrs, '|' as delimiter)
|
||||
SPF_InlineProcedure (addOpt1_c -> name | file, addOpt2_c-> line)
|
||||
*/
|
||||
public void RunModification(String modifyName, int winHandler, String options, String projName,
|
||||
String folderName, String addOpt1, String addOpt2) throws Exception {
|
||||
Command("modification:" + pack(modifyName, options, projName, folderName, addOpt1, addOpt2) + winHandler);
|
||||
}
|
||||
public void GetIntrinsics() throws Exception {
|
||||
Intrinsics.clear();
|
||||
if (RunAnalysis("SPF_GetIntrinsics", -1, "", "") >= 0) {
|
||||
String[] data = getResult().split(" ");
|
||||
Collections.addAll(Intrinsics, data);
|
||||
}
|
||||
}
|
||||
public boolean isIntrinsic(String func_name) {
|
||||
return Intrinsics.contains(func_name.toLowerCase());
|
||||
}
|
||||
//todo рефакторить. отвязать от текущего проекта.
|
||||
public void UpdateProjectFiles(boolean mode) throws Exception {
|
||||
ResetAllAnalyses();
|
||||
Current.getProject().dropLastModification();
|
||||
DBProjectFile cuf = null;
|
||||
if (Current.HasFile()) {
|
||||
cuf = Current.getFile();
|
||||
Pass_2021.passes.get(PassCode_2021.CloseCurrentFile).Do();
|
||||
}
|
||||
if (mode) //модификация
|
||||
{
|
||||
OldFiles.clear();
|
||||
for (String name : ModifiedFiles.keySet()) {
|
||||
if (Current.getProject().db.files.Data.containsKey(name)) {
|
||||
File file = Current.getProject().db.files.Data.get(name).file;
|
||||
OldFiles.put(name, Utils.ReadAllText(file));
|
||||
Utils.WriteToFile(file, ModifiedFiles.get(name));
|
||||
}
|
||||
}
|
||||
ModifiedFiles.clear();
|
||||
} else //откат.
|
||||
{
|
||||
if (OldFiles.size() > 0) {
|
||||
for (String name : OldFiles.keySet()) {
|
||||
File file = Current.getProject().db.files.Data.get(name).file;
|
||||
Utils.WriteToFile(file, OldFiles.get(name));
|
||||
}
|
||||
OldFiles.clear();
|
||||
} else CommonUI.Info("Сохранение файлов отсутствует.");
|
||||
}
|
||||
if (cuf != null)
|
||||
Pass_2021.passes.get(PassCode_2021.OpenCurrentFile).Do(cuf);
|
||||
}
|
||||
//</editor-fold>
|
||||
public Visual_DVM_2021.Passes.SapforAnalysis getAnalysisByPhase(String phase) {
|
||||
for (PassCode_2021 analysis_code : getAnalysesCodes()) {
|
||||
Visual_DVM_2021.Passes.SapforAnalysis analysis = (Visual_DVM_2021.Passes.SapforAnalysis) Pass_2021.passes.get(analysis_code);
|
||||
if (analysis.phase().equals(phase)) return analysis;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void ResetAllAnalyses() {
|
||||
for (PassCode_2021 code : getAnalysesCodes())
|
||||
(Pass_2021.passes.get(code)).Reset();
|
||||
//------------------------------------------------------------------------------------------>>>> пакетный режим.
|
||||
if (CommonUI.isActive()) {
|
||||
Pass_2021.passes.get(PassCode_2021.Precompilation).Reset();
|
||||
Pass_2021.passes.get(PassCode_2021.SPF_GetGCovInfo).Reset();
|
||||
}
|
||||
Global.enable_text_changed = false;
|
||||
Global.transformationPermission = TransformationPermission.None;
|
||||
if ((CommonUI.isActive()) && (UI.HasMainWindow()) && (UI.getVersionsWindow() != null))
|
||||
UI.getVersionsWindow().BlockVariants();
|
||||
}
|
||||
//--------------------------------------------------------------------------->>
|
||||
//временный (?) проход, по тихому получить размерность теста, предварительно выполнив тихий парс.
|
||||
//тут все одноразовое. считаем что таблицы бд уже заполнены как надо.
|
||||
public LanguageStyle getStyle() throws Exception {
|
||||
return ((GlobalDatabase)CommonUtils.db).settings.get(SettingName.FREE_FORM).toBoolean() ? LanguageStyle.free : LanguageStyle.fixed;
|
||||
}
|
||||
//----------
|
||||
public static Vector<PassCode_2021> getScenariosCodes() {
|
||||
Vector<PassCode_2021> res = new Vector<>();
|
||||
res.add(PassCode_2021.SPF_InitDeclsWithZero);//+
|
||||
res.add(PassCode_2021.SPF_ConvertStructures);//+
|
||||
res.add(PassCode_2021.SPF_ExpressionSubstitution);//+
|
||||
//--
|
||||
res.add(PassCode_2021.SPF_CreateCheckpoints); //+
|
||||
res.add(PassCode_2021.SPF_CreateIntervalsTree);//+
|
||||
res.add(PassCode_2021.SPF_RemoveDvmIntervals);//+
|
||||
//--
|
||||
res.add(PassCode_2021.SPF_RemoveDvmDirectives); //+
|
||||
res.add(PassCode_2021.SPF_RemoveDvmDirectivesToComments); //+
|
||||
|
||||
res.add(PassCode_2021.SPF_RemoveOmpDirectives);//+
|
||||
res.add(PassCode_2021.SPF_RemoveComments);//+
|
||||
res.add(PassCode_2021.SPF_RemoveDeadCode);//+
|
||||
res.add(PassCode_2021.SPF_RenameIncludes);
|
||||
res.add(PassCode_2021.SPF_InsertIncludesPass);//+
|
||||
//--
|
||||
res.add(PassCode_2021.SPF_LoopEndDoConverterPass); //+
|
||||
res.add(PassCode_2021.SPF_LoopUnion);//+
|
||||
res.add(PassCode_2021.SPF_LoopFission);//+
|
||||
//--
|
||||
res.add(PassCode_2021.SPF_PrivateShrinking);//+
|
||||
res.add(PassCode_2021.SPF_PrivateExpansion);//+
|
||||
res.add(PassCode_2021.SPF_PrivateRemoving);//+
|
||||
//--
|
||||
res.add(PassCode_2021.SPF_RemoveUnusedFunctions);//+
|
||||
res.add(PassCode_2021.SPF_DuplicateFunctionChains);//+
|
||||
//--
|
||||
res.add(PassCode_2021.SPF_ResolveParallelRegionConflicts);//+
|
||||
res.add(PassCode_2021.SPF_ResolveCommonBlockConflicts);//+
|
||||
//-
|
||||
res.add(PassCode_2021.SPF_InsertDvmhRegions);//+
|
||||
res.add(PassCode_2021.SPF_SharedMemoryParallelization);//+
|
||||
res.add(PassCode_2021.SPF_InsertImplicitNone);//+
|
||||
res.add(PassCode_2021.CreateParallelVariants); //?
|
||||
return res;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
public String getConsoleFlags() throws Exception {
|
||||
Vector<String> res = new Vector<>();
|
||||
if (((GlobalDatabase)CommonUtils.db).settings.get(SettingName.FREE_FORM).toBoolean())
|
||||
res.add("-f90");
|
||||
if (((GlobalDatabase)CommonUtils.db).settings.get(SettingName.STATIC_SHADOW_ANALYSIS).toBoolean())
|
||||
res.add("-sh");
|
||||
res.add("-shwidth " + ((GlobalDatabase)CommonUtils.db).settings.get(SettingName.MAX_SHADOW_WIDTH));
|
||||
if (((GlobalDatabase)CommonUtils.db).settings.get(SettingName.KEEP_SPF_DIRECTIVES).toBoolean())
|
||||
res.add("-keepSPF");
|
||||
return String.join(" ", res);
|
||||
}
|
||||
public static boolean checkLines(Vector<String> lines) {
|
||||
for (String line : lines) {
|
||||
if (line.toLowerCase().contains("internal error")) {
|
||||
return false;
|
||||
}
|
||||
if (line.toLowerCase().contains("exception")) {
|
||||
return false;
|
||||
}
|
||||
if (line.contains("[ERROR]")) {
|
||||
return false;
|
||||
}
|
||||
if (line.toLowerCase().contains("segmentation fault")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//--
|
||||
public static boolean performScript(String name, //имя скрипта
|
||||
File sapfor_drv, //путь к сапфору
|
||||
File workspace, //проект
|
||||
String command, //проход
|
||||
String flags, //флаги
|
||||
String outName,
|
||||
String errName,
|
||||
Vector<String> resultLines
|
||||
) throws Exception {
|
||||
Process process = null;
|
||||
int exit_code = CommonConstants.Nan;
|
||||
//---
|
||||
File data_workspace = new File(workspace, Constants.data);
|
||||
Utils.CheckDirectory(data_workspace);
|
||||
File outputFile = new File(data_workspace, outName);
|
||||
File errorsFile = new File(data_workspace, errName);
|
||||
Utils.delete_with_check(outputFile);
|
||||
Utils.delete_with_check(errorsFile);
|
||||
//---
|
||||
File file = new File(data_workspace, name + (CommonUtils.isWindows() ? ".bat" : ".sh"));
|
||||
FileUtils.write(file,
|
||||
CommonUtils.DQuotes(sapfor_drv)
|
||||
+ (flags.isEmpty() ? "" : (" " + flags))
|
||||
+ " -noLogo"
|
||||
+ " " + command +
|
||||
" 1>" +
|
||||
CommonUtils.DQuotes(outputFile.getAbsolutePath()) +
|
||||
" 2>" +
|
||||
CommonUtils.DQuotes(errorsFile.getAbsolutePath()),
|
||||
Charset.defaultCharset());
|
||||
if (!file.setExecutable(true))
|
||||
throw new Exception("Не удалось сделать файл скрипта " + name + " исполняемым!");
|
||||
//--
|
||||
boolean flag = false;
|
||||
do {
|
||||
try {
|
||||
ProcessBuilder procBuilder = new ProcessBuilder(file.getAbsolutePath());
|
||||
procBuilder.directory(workspace);
|
||||
process = procBuilder.start();
|
||||
exit_code = process.waitFor();
|
||||
flag = true;
|
||||
} catch (Exception ex) {
|
||||
CommonUtils.MainLog.PrintException(ex);
|
||||
CommonUtils.sleep(1000);
|
||||
}
|
||||
}
|
||||
while (!flag);
|
||||
process = null;
|
||||
//---
|
||||
Vector<String> outputLines = new Vector<>(FileUtils.readLines(outputFile));
|
||||
Vector<String> errorsLines = new Vector<>(FileUtils.readLines(errorsFile));
|
||||
if (resultLines != null) {
|
||||
resultLines.addAll(outputLines);
|
||||
}
|
||||
return (exit_code == 0) &&
|
||||
checkLines(outputLines) &&
|
||||
checkLines(errorsLines);
|
||||
}
|
||||
public static boolean performScript(String name, //имя скрипта
|
||||
File sapfor_drv, //путь к сапфору
|
||||
File workspace, //проект
|
||||
String command, //проход
|
||||
String flags, //флаги
|
||||
String outName,
|
||||
String errName
|
||||
) throws Exception {
|
||||
return performScript(name, sapfor_drv, workspace, command, flags, outName, errName, null);
|
||||
}
|
||||
public static boolean parse(File sapfor_drv, File workspace, String flags) throws Exception {
|
||||
return performScript(
|
||||
"parse",
|
||||
sapfor_drv,
|
||||
workspace,
|
||||
"-parse -spf *.f* *.F*", // "-parse -spf *.f *.for *.fdv *.f90 *.f77",
|
||||
flags,
|
||||
Constants.parse_out_file,
|
||||
Constants.parse_err_file)
|
||||
&& (new File(workspace, "dvm.proj")).exists();
|
||||
}
|
||||
public static boolean analysis(File sapfor_drv, File workspace, PassCode_2021 code, String flags, Vector<String> result_lines) throws Exception {
|
||||
return performScript("analysis",
|
||||
sapfor_drv,
|
||||
workspace,
|
||||
code.getTestingCommand(),
|
||||
flags,
|
||||
Constants.out_file,
|
||||
Constants.err_file,
|
||||
result_lines
|
||||
);
|
||||
}
|
||||
public static File temp_copy = null;
|
||||
public static File getTempCopy(File src) throws Exception {
|
||||
if (temp_copy == null || !temp_copy.exists()) {
|
||||
temp_copy = Utils.getTempFileName("SAPFOR" + (CommonUtils.isWindows() ? ".exe" : ""));
|
||||
FileUtils.copyFile(src, temp_copy);
|
||||
temp_copy.setExecutable(true);
|
||||
}
|
||||
return temp_copy;
|
||||
}
|
||||
//--
|
||||
public static boolean getMinMaxDim(File sapfor_drv, File workspace, Test test) throws Exception {
|
||||
File sapfor = Sapfor.getTempCopy(sapfor_drv);
|
||||
String flags = "-noLogo";
|
||||
if (Sapfor.parse(sapfor, workspace, flags)
|
||||
) {
|
||||
Vector<String> outputLines = new Vector<>();
|
||||
if (Sapfor.analysis(sapfor, workspace, PassCode_2021.SPF_GetMaxMinBlockDistribution, flags, outputLines)) {
|
||||
//---
|
||||
for (String line : outputLines) {
|
||||
String prefix = "GET_MIN_MAX_BLOCK_DIST: ";
|
||||
if (line.startsWith(prefix)) {
|
||||
String s = line.substring(prefix.length());
|
||||
String[] data = s.split(" ");
|
||||
test.min_dim = Math.max(Integer.parseInt(data[0]), 0);
|
||||
test.max_dim = Math.max(Integer.parseInt(data[1]), 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static int readVersionFromCode(File versionFile) {
|
||||
int res = CommonConstants.Nan;
|
||||
if (versionFile.exists()) {
|
||||
try {
|
||||
List<String> data = FileUtils.readLines(versionFile);
|
||||
for (String s : data) {
|
||||
if (s.startsWith("#define VERSION_SPF ")) {
|
||||
String[] version_data = s.split("\"");
|
||||
if (version_data.length > 0) {
|
||||
String version_s = version_data[1];
|
||||
//-
|
||||
try {
|
||||
res = Integer.parseInt(version_s);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
32
src/_VisualDVM/Repository/Component/Sapfor/Sapfor_F.java
Normal file
32
src/_VisualDVM/Repository/Component/Sapfor/Sapfor_F.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package _VisualDVM.Repository.Component.Sapfor;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Repository.Component.ComponentType;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
public class Sapfor_F extends Sapfor {
|
||||
@Override
|
||||
public ComponentType getComponentType() {
|
||||
return ComponentType.Sapfor_F;
|
||||
}
|
||||
@Override
|
||||
public String getAssemblyCommand() {
|
||||
return "cd Repo/sapfor/experts/Sapfor_2017/_bin\n" +
|
||||
"cmake ../\n" +
|
||||
"make -j 4\n";
|
||||
}
|
||||
@Override
|
||||
public File getAssemblyFile() {
|
||||
return Paths.get(
|
||||
Global.RepoDirectory.getAbsolutePath(),
|
||||
"sapfor/experts/Sapfor_2017/_bin/Sapfor_F").toFile();
|
||||
}
|
||||
@Override
|
||||
public String getUpdateCommand() {
|
||||
return "update_spf: ";
|
||||
}
|
||||
@Override
|
||||
public String getRestartCommand() {
|
||||
return "restart: ";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package _VisualDVM.Repository.Component.Sapfor;
|
||||
public enum TransformationPermission {
|
||||
None,
|
||||
All,
|
||||
VariantsOnly
|
||||
}
|
||||
Reference in New Issue
Block a user