no message

This commit is contained in:
2024-10-14 15:19:13 +03:00
parent 8eef367bd4
commit 5e09fb44ea
634 changed files with 3751 additions and 3263 deletions

View File

@@ -1,8 +1,6 @@
package _VisualDVM.Repository.Component.Sapfor;
import Common.MainModule_;
import Common.Utils.Utils_;
import _VisualDVM.Current;
import _VisualDVM.Global;
import java.io.BufferedReader;
import java.io.InputStreamReader;
@@ -30,8 +28,8 @@ public class MessagesServer {
InputStreamReader(client.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
if (MainModule_.object.HasPassForm())
MainModule_.object.getPassForm().Result.ShowSapforMessage(line);
if (MainModule_.object.passForm != null)
MainModule_.object.passForm.Result.ShowSapforMessage(line);
}
} catch (Exception ex) {
// UI.Print(DebugPrintLevel.MessagesServer, "соединение сброшено!");

View File

@@ -1,20 +1,20 @@
package _VisualDVM.Repository.Component.Sapfor;
import Common.CommonConstants;
import Common.Passes.PassException;
import Common.Utils.Utils_;
import Common.Visual.UI_;
import _VisualDVM.Passes.Sapfor.SapforAnalysis;
import _VisualDVM.Constants;
import _VisualDVM.Global;
import _VisualDVM.Visual.UI;
import _VisualDVM.Utils;
import _VisualDVM.GlobalData.Settings.SettingName;
import _VisualDVM.Passes.PassCode;
import _VisualDVM.Passes.Sapfor.SapforAnalysis;
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 _VisualDVM.Passes.PassCode;
import Common.Passes.PassException;
import _VisualDVM.Utils;
import _VisualDVM.Visual.UI;
import org.apache.commons.io.FileUtils;
import java.io.File;
@@ -27,17 +27,18 @@ 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 static File temp_copy = null;
public Vector<String> Intrinsics = new Vector<>();
public LinkedHashMap<String, String> ModifiedFiles = new LinkedHashMap<>();
public LinkedHashMap<String, String> OldFiles = new LinkedHashMap<>();
int size;
int[] sizes;
String PID = "";
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();
@@ -45,16 +46,6 @@ public abstract class Sapfor extends OSDComponent {
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[] getAnalysesCodes() {
return new PassCode[]{
PassCode.SPF_ParseFilesWithOrder,
@@ -131,6 +122,219 @@ public abstract class Sapfor extends OSDComponent {
PassCode.SPF_InsertImplicitNone
};
}
//----------
public static Vector<PassCode> getScenariosCodes() {
Vector<PassCode> res = new Vector<>();
res.add(PassCode.SPF_InitDeclsWithZero);//+
res.add(PassCode.SPF_ConvertStructures);//+
res.add(PassCode.SPF_ExpressionSubstitution);//+
//--
res.add(PassCode.SPF_CreateCheckpoints); //+
res.add(PassCode.SPF_CreateIntervalsTree);//+
res.add(PassCode.SPF_RemoveDvmIntervals);//+
//--
res.add(PassCode.SPF_RemoveDvmDirectives); //+
res.add(PassCode.SPF_RemoveDvmDirectivesToComments); //+
res.add(PassCode.SPF_RemoveOmpDirectives);//+
res.add(PassCode.SPF_RemoveComments);//+
res.add(PassCode.SPF_RemoveDeadCode);//+
res.add(PassCode.SPF_RenameIncludes);
res.add(PassCode.SPF_InsertIncludesPass);//+
//--
res.add(PassCode.SPF_LoopEndDoConverterPass); //+
res.add(PassCode.SPF_LoopUnion);//+
res.add(PassCode.SPF_LoopFission);//+
//--
res.add(PassCode.SPF_PrivateShrinking);//+
res.add(PassCode.SPF_PrivateExpansion);//+
res.add(PassCode.SPF_PrivateRemoving);//+
//--
res.add(PassCode.SPF_RemoveUnusedFunctions);//+
res.add(PassCode.SPF_DuplicateFunctionChains);//+
//--
res.add(PassCode.SPF_ResolveParallelRegionConflicts);//+
res.add(PassCode.SPF_ResolveCommonBlockConflicts);//+
//-
res.add(PassCode.SPF_InsertDvmhRegions);//+
res.add(PassCode.SPF_SharedMemoryParallelization);//+
res.add(PassCode.SPF_InsertImplicitNone);//+
res.add(PassCode.CreateParallelVariants); //?
return 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_.forceDeleteWithCheck(outputFile);
Utils_.forceDeleteWithCheck(errorsFile);
//---
File file = new File(data_workspace, name + (Utils_.isWindows() ? ".bat" : ".sh"));
FileUtils.write(file,
Utils_.DQuotes(sapfor_drv)
+ (flags.isEmpty() ? "" : (" " + flags))
+ " -noLogo"
+ " " + command +
" 1>" +
Utils_.DQuotes(outputFile.getAbsolutePath()) +
" 2>" +
Utils_.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) {
Utils_.MainLog.PrintException(ex);
Utils_.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 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 getTempCopy(File src) throws Exception {
if (temp_copy == null || !temp_copy.exists()) {
temp_copy = Utils.getTempFileName("SAPFOR" + (Utils_.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.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;
}
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();
}
}
//<editor-fold desc="компонент">
@Override
public void GetVersionInfo() {
@@ -342,14 +546,14 @@ public abstract class Sapfor extends OSDComponent {
//</editor-fold>
public SapforAnalysis getAnalysisByPhase(String phase) {
for (PassCode analysis_code : getAnalysesCodes()) {
SapforAnalysis analysis = (SapforAnalysis) Global.mainModule.getPass(analysis_code);
SapforAnalysis analysis = (SapforAnalysis) Global.mainModule.getPass(analysis_code);
if (analysis.phase().equals(phase)) return analysis;
}
return null;
}
public void ResetAllAnalyses() {
for (PassCode code : getAnalysesCodes())
( Global.mainModule.getPass(code)).Reset();
(Global.mainModule.getPass(code)).Reset();
//------------------------------------------------------------------------------------------>>>> пакетный режим.
if (UI_.isActive()) {
Global.mainModule.getPass(PassCode.Precompilation).Reset();
@@ -366,46 +570,6 @@ public abstract class Sapfor extends OSDComponent {
public LanguageStyle getStyle() throws Exception {
return (Global.mainModule.getDb()).settings.get(SettingName.FREE_FORM).toBoolean() ? LanguageStyle.free : LanguageStyle.fixed;
}
//----------
public static Vector<PassCode> getScenariosCodes() {
Vector<PassCode> res = new Vector<>();
res.add(PassCode.SPF_InitDeclsWithZero);//+
res.add(PassCode.SPF_ConvertStructures);//+
res.add(PassCode.SPF_ExpressionSubstitution);//+
//--
res.add(PassCode.SPF_CreateCheckpoints); //+
res.add(PassCode.SPF_CreateIntervalsTree);//+
res.add(PassCode.SPF_RemoveDvmIntervals);//+
//--
res.add(PassCode.SPF_RemoveDvmDirectives); //+
res.add(PassCode.SPF_RemoveDvmDirectivesToComments); //+
res.add(PassCode.SPF_RemoveOmpDirectives);//+
res.add(PassCode.SPF_RemoveComments);//+
res.add(PassCode.SPF_RemoveDeadCode);//+
res.add(PassCode.SPF_RenameIncludes);
res.add(PassCode.SPF_InsertIncludesPass);//+
//--
res.add(PassCode.SPF_LoopEndDoConverterPass); //+
res.add(PassCode.SPF_LoopUnion);//+
res.add(PassCode.SPF_LoopFission);//+
//--
res.add(PassCode.SPF_PrivateShrinking);//+
res.add(PassCode.SPF_PrivateExpansion);//+
res.add(PassCode.SPF_PrivateRemoving);//+
//--
res.add(PassCode.SPF_RemoveUnusedFunctions);//+
res.add(PassCode.SPF_DuplicateFunctionChains);//+
//--
res.add(PassCode.SPF_ResolveParallelRegionConflicts);//+
res.add(PassCode.SPF_ResolveCommonBlockConflicts);//+
//-
res.add(PassCode.SPF_InsertDvmhRegions);//+
res.add(PassCode.SPF_SharedMemoryParallelization);//+
res.add(PassCode.SPF_InsertImplicitNone);//+
res.add(PassCode.CreateParallelVariants); //?
return res;
}
//------------------------------------------------------------------------------------------------------------------
public String getConsoleFlags() throws Exception {
Vector<String> res = new Vector<>();
@@ -418,169 +582,4 @@ public abstract class Sapfor extends OSDComponent {
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_.forceDeleteWithCheck(outputFile);
Utils_.forceDeleteWithCheck(errorsFile);
//---
File file = new File(data_workspace, name + (Utils_.isWindows() ? ".bat" : ".sh"));
FileUtils.write(file,
Utils_.DQuotes(sapfor_drv)
+ (flags.isEmpty() ? "" : (" " + flags))
+ " -noLogo"
+ " " + command +
" 1>" +
Utils_.DQuotes(outputFile.getAbsolutePath()) +
" 2>" +
Utils_.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) {
Utils_.MainLog.PrintException(ex);
Utils_.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 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" + (Utils_.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.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;
}
}