diff --git a/Broker/Broker/Broker.csproj b/Broker/Broker/Broker.csproj index dba7e8ab4633ee16cc72333ec645872af3b7ff1b..831277d3de40e8cbbb969a52a14d06f8e762c839 100644 --- a/Broker/Broker/Broker.csproj +++ b/Broker/Broker/Broker.csproj @@ -8,10 +8,12 @@ </PropertyGroup> <ItemGroup> + <Compile Include="..\..\Shared\ProcessKiller.cs" Link="ProcessKiller.cs" /> <Compile Include="..\..\Shared\ProjectSettings.cs" Link="ProjectSettings.cs" /> </ItemGroup> <ItemGroup> + <PackageReference Include="System.Management" Version="9.0.3" /> <PackageReference Include="System.Security.Cryptography.ProtectedData" Version="9.0.2" /> </ItemGroup> diff --git a/Broker/Broker/Program.cs b/Broker/Broker/Program.cs index 093384206d5f449b007fe9e7eb7aa1ad84ea93a6..b90c808cb8b88490e7a7bef1012db73638abf5d2 100644 --- a/Broker/Broker/Program.cs +++ b/Broker/Broker/Program.cs @@ -38,6 +38,27 @@ namespace HDLNoCGen static void Main(string[] args) { + Process manager = new Process(); + Process veriloger = new Process(); + Process quartuser = new Process(); + + Process[] processes = { manager, veriloger, quartuser }; + + AppDomain.CurrentDomain.ProcessExit += new EventHandler((sender, e) => + { + foreach (Process process in processes) + { + try + { + ProcessKiller.killProcessAndChildren(process.Id); + } + catch (InvalidOperationException) + { + // Process hasn't started + } + } + }); + bool launch_manager = false; string project_name = ""; string project_location = ""; @@ -306,79 +327,107 @@ namespace HDLNoCGen if (launch_manager) { - using (Process manager = new Process()) - { - string manager_location = "../../../../../Project_manager/Project_manager/bin/Debug/net8.0"; - string manager_arguments = $"-l {project_location} -n {project_name} -{project_action} {(project_action == "r" ? project_new_name : "")}"; - string output_data = ""; + string manager_location = "../../../../../Project_manager/Project_manager/bin/Debug/net8.0"; + string manager_arguments = $"-l {project_location} -n {project_name} -{project_action} {(project_action == "r" ? project_new_name : "")}"; + string output_data = ""; - manager.StartInfo.FileName = $"{manager_location}/Project_manager.exe"; - manager.StartInfo.Arguments = manager_arguments; - manager.StartInfo.RedirectStandardOutput = true; - manager.StartInfo.WorkingDirectory = manager_location; + manager.StartInfo.FileName = $"{manager_location}/Project_manager.exe"; + manager.StartInfo.Arguments = manager_arguments; + manager.StartInfo.RedirectStandardOutput = true; + manager.StartInfo.WorkingDirectory = manager_location; - manager.OutputDataReceived += new DataReceivedEventHandler((sender, e) => - { - if (!String.IsNullOrEmpty(e.Data)) - { - output_data = $"{e.Data}\n"; - } - }); - - manager.Start(); - manager.BeginOutputReadLine(); - manager.WaitForExit(); - manager.Kill(); - - if (manager.ExitCode != 0) + manager.OutputDataReceived += new DataReceivedEventHandler((sender, e) => + { + if (!String.IsNullOrEmpty(e.Data)) { - Console.WriteLine("Project_manager failure:"); - Console.Write(output_data); - Environment.Exit(1); + output_data = $"{e.Data}\n"; } + }); + + manager.Start(); + manager.BeginOutputReadLine(); + manager.WaitForExit(); + manager.Kill(); + + if (manager.ExitCode != 0) + { + Console.WriteLine("Project_manager failure:"); + Console.Write(output_data); + Environment.Exit(1); } } if (launch_graph) { uncheckMetadata($"{project_location}/{project_name}_metadata.json", 0); - using (Process veriloger = new Process()) + + string veriloger_location = "../../../../../Graph_verilog_generator/Graph_verilog_generator/bin/Debug/net8.0"; + string veriloger_arguments = $"-l {project_location} -n {project_name} {topology} {String.Join(" ", generators)} " + + $"--queue_type {queue_type} " + + $"--queue_position {queue_position} " + + $"--arbiter_type {arbiter_type} " + + $"--algorithm {algorithm} " + + $"--info_width {info_width} " + + $"--queue_length {queue_length} " + + $"{(create_verilog ? "-v" : " ")}"; + string output_data = ""; + + veriloger.StartInfo.FileName = $"{veriloger_location}/Graph_verilog_generator.exe"; + veriloger.StartInfo.Arguments = veriloger_arguments; + veriloger.StartInfo.RedirectStandardOutput = true; + veriloger.StartInfo.WorkingDirectory = veriloger_location; + + veriloger.OutputDataReceived += new DataReceivedEventHandler((sender, e) => { - string veriloger_location = "../../../../../Graph_verilog_generator/Graph_verilog_generator/bin/Debug/net8.0"; - string veriloger_arguments = $"-l {project_location} -n {project_name} {topology} {String.Join(" ", generators)} " + - $"--queue_type {queue_type} " + - $"--queue_position {queue_position} " + - $"--arbiter_type {arbiter_type} " + - $"--algorithm {algorithm} " + - $"--info_width {info_width} " + - $"--queue_length {queue_length} " + - $"{(create_verilog ? "-v" : " ")}"; - string output_data = ""; - - veriloger.StartInfo.FileName = $"{veriloger_location}/Graph_verilog_generator.exe"; - veriloger.StartInfo.Arguments = veriloger_arguments; - veriloger.StartInfo.RedirectStandardOutput = true; - veriloger.StartInfo.WorkingDirectory = veriloger_location; - - veriloger.OutputDataReceived += new DataReceivedEventHandler((sender, e) => + if (!String.IsNullOrEmpty(e.Data)) { - if (!String.IsNullOrEmpty(e.Data)) - { - output_data = $"{e.Data}\n"; - } - }); - - veriloger.Start(); - veriloger.BeginOutputReadLine(); - veriloger.WaitForExit(); - veriloger.Kill(); - - if (veriloger.ExitCode != 0) + output_data = $"{e.Data}\n"; + } + }); + + veriloger.Start(); + veriloger.BeginOutputReadLine(); + veriloger.WaitForExit(); + veriloger.Kill(); + + if (veriloger.ExitCode != 0) + { + Console.WriteLine("Graph_verilog_generator failure:"); + Console.Write(output_data); + Environment.Exit(1); + } + } + + if (launch_quartus) + { + uncheckMetadata($"{project_location}/{project_name}_metadata.json", 2); + + string quartuser_location = "../../../../../Quartus_compiler/Quartus_compiler/bin/Debug/net8.0"; + string quartuser_arguments = $"-l {project_location} -n {project_name}"; + string output_data = ""; + + quartuser.StartInfo.FileName = $"{quartuser_location}/Quartus_compiler.exe"; + quartuser.StartInfo.Arguments = quartuser_arguments; + quartuser.StartInfo.RedirectStandardOutput = true; + quartuser.StartInfo.WorkingDirectory = quartuser_location; + + quartuser.OutputDataReceived += new DataReceivedEventHandler((sender, e) => + { + if (!String.IsNullOrEmpty(e.Data)) { - Console.WriteLine("Graph_verilog_generator failure:"); - Console.Write(output_data); - Environment.Exit(1); + Console.WriteLine($"{e.Data}"); } + }); + + quartuser.Start(); + quartuser.BeginOutputReadLine(); + quartuser.WaitForExit(); + quartuser.Kill(); + + if (quartuser.ExitCode != 0) + { + Console.WriteLine("Quartus_compiler failure"); + Environment.Exit(1); } } } diff --git a/Broker/Broker/Properties/launchSettings.json b/Broker/Broker/Properties/launchSettings.json index cc3414f7b6f98aa7a49879ba85970e229c61c182..b055aec9cc653c6ed7759d76f755a30c13864f5c 100644 --- a/Broker/Broker/Properties/launchSettings.json +++ b/Broker/Broker/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Broker": { "commandName": "Project", - "commandLineArgs": "--project -l D:/kal -n kal -c --graph m 3 3 --queue_type pointer --queue_position front --arbiter_type round_robin --algorithm xy --info_width 8 --queue_length 16 -v" + "commandLineArgs": "--project -l D:/kal -n kal -c --graph m 3 3 --queue_type pointer --queue_position front --arbiter_type round_robin --algorithm xy --info_width 8 --queue_length 16 -v --quartus" } } } \ No newline at end of file diff --git a/GUI/GUI/FormMain.Designer.cs b/GUI/GUI/FormMain.Designer.cs index 123907f9bcc683f882a10f23aab5f43445f0845e..ec505f3af1964ff394dce873ad18c5987e62d1d4 100644 --- a/GUI/GUI/FormMain.Designer.cs +++ b/GUI/GUI/FormMain.Designer.cs @@ -36,7 +36,7 @@ pictureBox1 = new PictureBox(); tabControl2 = new TabControl(); output = new TabPage(); - richTextBoxOutput = new RichTextBox(); + textBoxOutput = new TextBox(); labelEfficiency = new Label(); labelDiameter = new Label(); buttonRouting = new Button(); @@ -71,20 +71,22 @@ columnHeader4 = new ColumnHeader(); columnHeader5 = new ColumnHeader(); columnHeader6 = new ColumnHeader(); - button2 = new Button(); + buttonCompile = new Button(); buttonSerializeGraph = new Button(); buttonCreateVerilog = new Button(); buttonCompileQuartus = new Button(); - button6 = new Button(); + buttonWriteToDB = new Button(); buttonOpenProject = new Button(); buttonCreateProject = new Button(); buttonProjSettings = new Button(); label8 = new Label(); label9 = new Label(); buttonAppSettings = new Button(); - button12 = new Button(); - button13 = new Button(); + buttonBuildTopologyUpper = new Button(); + buttonRoutingUpper = new Button(); label12 = new Label(); + buttonStop = new Button(); + buttonProjectDirectory = new Button(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); splitContainer1.Panel1.SuspendLayout(); @@ -207,7 +209,7 @@ // // output // - output.Controls.Add(richTextBoxOutput); + output.Controls.Add(textBoxOutput); output.Location = new Point(4, 24); output.Name = "output"; output.Padding = new Padding(3); @@ -216,17 +218,16 @@ output.Text = "Вывод"; output.UseVisualStyleBackColor = true; // - // richTextBoxOutput + // textBoxOutput // - richTextBoxOutput.BackColor = Color.White; - richTextBoxOutput.BorderStyle = BorderStyle.None; - richTextBoxOutput.Dock = DockStyle.Fill; - richTextBoxOutput.Location = new Point(3, 3); - richTextBoxOutput.Name = "richTextBoxOutput"; - richTextBoxOutput.ReadOnly = true; - richTextBoxOutput.Size = new Size(1034, 78); - richTextBoxOutput.TabIndex = 0; - richTextBoxOutput.Text = ""; + textBoxOutput.BorderStyle = BorderStyle.None; + textBoxOutput.Dock = DockStyle.Fill; + textBoxOutput.Location = new Point(3, 3); + textBoxOutput.Multiline = true; + textBoxOutput.Name = "textBoxOutput"; + textBoxOutput.ScrollBars = ScrollBars.Vertical; + textBoxOutput.Size = new Size(1034, 78); + textBoxOutput.TabIndex = 18; // // labelEfficiency // @@ -552,21 +553,21 @@ columnHeader6.Text = "L"; columnHeader6.Width = 30; // - // button2 + // buttonCompile // - button2.Enabled = false; - button2.Image = GUI.Properties.Resources.kal; - button2.Location = new Point(208, 27); - button2.Name = "button2"; - button2.Size = new Size(30, 30); - button2.TabIndex = 1; - button2.UseVisualStyleBackColor = true; + buttonCompile.Enabled = false; + buttonCompile.Image = GUI.Properties.Resources.kal; + buttonCompile.Location = new Point(244, 27); + buttonCompile.Name = "buttonCompile"; + buttonCompile.Size = new Size(30, 30); + buttonCompile.TabIndex = 1; + buttonCompile.UseVisualStyleBackColor = true; // // buttonSerializeGraph // buttonSerializeGraph.Enabled = false; buttonSerializeGraph.Image = GUI.Properties.Resources.kal2; - buttonSerializeGraph.Location = new Point(244, 27); + buttonSerializeGraph.Location = new Point(280, 27); buttonSerializeGraph.Name = "buttonSerializeGraph"; buttonSerializeGraph.Size = new Size(30, 30); buttonSerializeGraph.TabIndex = 2; @@ -577,7 +578,7 @@ // buttonCreateVerilog.Enabled = false; buttonCreateVerilog.Image = GUI.Properties.Resources.kal21; - buttonCreateVerilog.Location = new Point(280, 27); + buttonCreateVerilog.Location = new Point(316, 27); buttonCreateVerilog.Name = "buttonCreateVerilog"; buttonCreateVerilog.Size = new Size(30, 30); buttonCreateVerilog.TabIndex = 3; @@ -588,22 +589,23 @@ // buttonCompileQuartus.Enabled = false; buttonCompileQuartus.Image = GUI.Properties.Resources.kal31; - buttonCompileQuartus.Location = new Point(316, 27); + buttonCompileQuartus.Location = new Point(352, 27); buttonCompileQuartus.Name = "buttonCompileQuartus"; buttonCompileQuartus.Size = new Size(30, 30); buttonCompileQuartus.TabIndex = 4; buttonCompileQuartus.UseVisualStyleBackColor = true; buttonCompileQuartus.Click += buttonCompileQuartus_Click; // - // button6 + // buttonWriteToDB // - button6.Enabled = false; - button6.Image = GUI.Properties.Resources.kal4; - button6.Location = new Point(352, 27); - button6.Name = "button6"; - button6.Size = new Size(30, 30); - button6.TabIndex = 5; - button6.UseVisualStyleBackColor = true; + buttonWriteToDB.Enabled = false; + buttonWriteToDB.Image = GUI.Properties.Resources.kal4; + buttonWriteToDB.Location = new Point(388, 27); + buttonWriteToDB.Name = "buttonWriteToDB"; + buttonWriteToDB.Size = new Size(30, 30); + buttonWriteToDB.TabIndex = 5; + buttonWriteToDB.UseVisualStyleBackColor = true; + buttonWriteToDB.Click += buttonWriteToDB_Click; // // buttonOpenProject // @@ -629,7 +631,7 @@ // buttonProjSettings.Enabled = false; buttonProjSettings.Image = GUI.Properties.Resources.kal7; - buttonProjSettings.Location = new Point(84, 27); + buttonProjSettings.Location = new Point(120, 27); buttonProjSettings.Name = "buttonProjSettings"; buttonProjSettings.Size = new Size(30, 30); buttonProjSettings.TabIndex = 8; @@ -640,7 +642,7 @@ // label8.AutoSize = true; label8.BorderStyle = BorderStyle.Fixed3D; - label8.Location = new Point(120, 35); + label8.Location = new Point(156, 35); label8.Name = "label8"; label8.Size = new Size(2, 17); label8.TabIndex = 9; @@ -649,7 +651,7 @@ // label9.AutoSize = true; label9.BorderStyle = BorderStyle.Fixed3D; - label9.Location = new Point(388, 35); + label9.Location = new Point(460, 35); label9.Name = "label9"; label9.Size = new Size(2, 17); label9.TabIndex = 10; @@ -657,67 +659,92 @@ // buttonAppSettings // buttonAppSettings.Image = GUI.Properties.Resources.kal8; - buttonAppSettings.Location = new Point(396, 27); + buttonAppSettings.Location = new Point(468, 27); buttonAppSettings.Name = "buttonAppSettings"; buttonAppSettings.Size = new Size(30, 30); buttonAppSettings.TabIndex = 11; buttonAppSettings.UseVisualStyleBackColor = true; buttonAppSettings.Click += buttonAppSettings_Click; // - // button12 + // buttonBuildTopologyUpper // - button12.Image = GUI.Properties.Resources.kal9; - button12.Location = new Point(128, 27); - button12.Name = "button12"; - button12.Size = new Size(30, 30); - button12.TabIndex = 12; - button12.UseVisualStyleBackColor = true; - button12.Click += BuildTopology_Click; + buttonBuildTopologyUpper.Image = GUI.Properties.Resources.kal9; + buttonBuildTopologyUpper.Location = new Point(164, 27); + buttonBuildTopologyUpper.Name = "buttonBuildTopologyUpper"; + buttonBuildTopologyUpper.Size = new Size(30, 30); + buttonBuildTopologyUpper.TabIndex = 12; + buttonBuildTopologyUpper.UseVisualStyleBackColor = true; + buttonBuildTopologyUpper.Click += BuildTopology_Click; // - // button13 + // buttonRoutingUpper // - button13.Image = GUI.Properties.Resources.kal10; - button13.Location = new Point(164, 27); - button13.Name = "button13"; - button13.Size = new Size(30, 30); - button13.TabIndex = 13; - button13.UseVisualStyleBackColor = true; - button13.Click += ButtonRouting_Click; + buttonRoutingUpper.Image = GUI.Properties.Resources.kal10; + buttonRoutingUpper.Location = new Point(200, 27); + buttonRoutingUpper.Name = "buttonRoutingUpper"; + buttonRoutingUpper.Size = new Size(30, 30); + buttonRoutingUpper.TabIndex = 13; + buttonRoutingUpper.UseVisualStyleBackColor = true; + buttonRoutingUpper.Click += ButtonRouting_Click; // // label12 // label12.AutoSize = true; label12.BorderStyle = BorderStyle.Fixed3D; - label12.Location = new Point(200, 35); + label12.Location = new Point(236, 35); label12.Name = "label12"; label12.Size = new Size(2, 17); label12.TabIndex = 14; // + // buttonStop + // + buttonStop.Image = GUI.Properties.Resources.kal15; + buttonStop.Location = new Point(424, 27); + buttonStop.Name = "buttonStop"; + buttonStop.Size = new Size(30, 30); + buttonStop.TabIndex = 15; + buttonStop.UseVisualStyleBackColor = true; + buttonStop.Click += buttonStop_Click; + // + // buttonProjectDirectory + // + buttonProjectDirectory.Enabled = false; + buttonProjectDirectory.Image = GUI.Properties.Resources.kal42; + buttonProjectDirectory.Location = new Point(84, 27); + buttonProjectDirectory.Name = "buttonProjectDirectory"; + buttonProjectDirectory.Size = new Size(30, 30); + buttonProjectDirectory.TabIndex = 16; + buttonProjectDirectory.UseVisualStyleBackColor = true; + buttonProjectDirectory.Click += buttonProjectDirectory_Click; + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(1339, 614); + Controls.Add(buttonProjectDirectory); + Controls.Add(buttonStop); Controls.Add(label12); - Controls.Add(button13); - Controls.Add(button12); + Controls.Add(buttonRoutingUpper); + Controls.Add(buttonBuildTopologyUpper); Controls.Add(buttonAppSettings); Controls.Add(label9); Controls.Add(label8); Controls.Add(buttonProjSettings); Controls.Add(buttonCreateProject); Controls.Add(buttonOpenProject); - Controls.Add(button6); + Controls.Add(buttonWriteToDB); Controls.Add(buttonCompileQuartus); Controls.Add(buttonCreateVerilog); Controls.Add(buttonSerializeGraph); - Controls.Add(button2); + Controls.Add(buttonCompile); Controls.Add(splitContainer1); Controls.Add(menuStrip1); MainMenuStrip = menuStrip1; MinimumSize = new Size(600, 463); Name = "FormMain"; - Text = "d"; + Text = "HDLNoCGen"; + FormClosing += FormMain_FormClosing; + Load += FormMain_Load; Resize += FormMain_Resize; menuStrip1.ResumeLayout(false); menuStrip1.PerformLayout(); @@ -733,6 +760,7 @@ ((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit(); tabControl2.ResumeLayout(false); output.ResumeLayout(false); + output.PerformLayout(); ((System.ComponentModel.ISupportInitialize)numericUpDownQLength).EndInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownWidth).EndInit(); tabControl1.ResumeLayout(false); @@ -776,12 +804,11 @@ private ColumnHeader columnHeader2; private ColumnHeader columnHeader3; private TabPage XY; - private RichTextBox richTextBoxOutput; - private Button button2; + private Button buttonCompile; private Button buttonSerializeGraph; private Button buttonCreateVerilog; private Button buttonCompileQuartus; - private Button button6; + private Button buttonWriteToDB; private Button buttonOpenProject; private Button buttonCreateProject; private Button buttonProjSettings; @@ -799,8 +826,11 @@ private ColumnHeader columnHeader6; private Label labelDiameter; private Label labelEfficiency; - private Button button12; - private Button button13; + private Button buttonBuildTopologyUpper; + private Button buttonRoutingUpper; private Label label12; + private TextBox textBoxOutput; + private Button buttonStop; + private Button buttonProjectDirectory; } } \ No newline at end of file diff --git a/GUI/GUI/FormMain.cs b/GUI/GUI/FormMain.cs index 0ef8615d63d13b3189c03df9c8178dbca9422772..42c914a2209bb44b70a23d7ceb8039c5ae09470c 100644 --- a/GUI/GUI/FormMain.cs +++ b/GUI/GUI/FormMain.cs @@ -16,6 +16,8 @@ namespace HDLNoCGen public partial class FormMain : Form { string broker_location = "../../../../../Broker/Broker/bin/Debug/net8.0"; + Process broker = new Process(); + int broker_mode = 0; // 0 - nothing, 1 - project manager, 2 - graph_verilog, 3 - quartus Dictionary<string, string> graph_args = new Dictionary<string, string>(); private static Task CreateGraphFromBufferThread, RoutingThread, DrawGraphThread, DrawRouteThread; @@ -30,7 +32,6 @@ namespace HDLNoCGen Dictionary<string, Dictionary<string, Dictionary<string, double>>> algorithmMetrics; - bool projectOpened = false; string projectLocation = ""; string projectName = ""; @@ -452,6 +453,8 @@ namespace HDLNoCGen RoutingCTS = new CancellationTokenSource(); CancellationToken token = CreateGraphFromBufferCTS.Token; Task.Run(() => CreateGraphFromBufferThreadRoutine(buffer, parameters, token), token); + buttonCompileQuartus.Enabled = false; + buttonWriteToDB.Enabled = false; } catch (System.Exception) { @@ -599,8 +602,9 @@ namespace HDLNoCGen private void manageProject(string mode) { + broker = new Process(); - Process broker = new Process(); + broker_mode = 1; broker.StartInfo.RedirectStandardOutput = true; broker.StartInfo.CreateNoWindow = true; @@ -613,10 +617,10 @@ namespace HDLNoCGen { if (!String.IsNullOrEmpty(e.Data)) { - richTextBoxOutput.Invoke(new Action(() => + textBoxOutput.Invoke(new Action(() => { - richTextBoxOutput.AppendText($"{e.Data}\n"); - richTextBoxOutput.ScrollToCaret(); + textBoxOutput.AppendText($"{e.Data}\r\n"); + textBoxOutput.ScrollToCaret(); })); } }); @@ -626,24 +630,25 @@ namespace HDLNoCGen broker.Exited += new EventHandler((sender, e) => { + broker_mode = 0; if (broker.ExitCode == 0) { - richTextBoxOutput.Invoke(new Action(() => + textBoxOutput.Invoke(new Action(() => { if (mode == "-c") { - richTextBoxOutput.AppendText($"Creation of project {projectName} at {projectLocation} was successful\n\n"); + textBoxOutput.AppendText($"Creation of project {projectName} at {projectLocation} was successful\r\n\r\n"); } else if (mode == "-o") { - richTextBoxOutput.AppendText($"Opened project {projectName} at {projectLocation}\n\n"); + textBoxOutput.AppendText($"Opened project {projectName} at {projectLocation}\r\n\r\n"); } else if (mode.Substring(0, 2) == "-r") { - richTextBoxOutput.AppendText($"Renamed project {projectName} at {projectLocation} to {mode.Substring(3)}\n\n"); + textBoxOutput.AppendText($"Renamed project {projectName} at {projectLocation} to {mode.Substring(3)}\r\n\r\n"); projectName = mode.Substring(3); } - richTextBoxOutput.ScrollToCaret(); + textBoxOutput.ScrollToCaret(); })); projectOpened = true; @@ -673,8 +678,8 @@ namespace HDLNoCGen break; } - numericUpDownQLength.Value = graph.parameters.queue_length; - numericUpDownWidth.Value = graph.parameters.info_width; + numericUpDownQLength.Invoke(new Action(() => numericUpDownQLength.Value = graph.parameters.queue_length)); + numericUpDownWidth.Invoke(new Action(() => numericUpDownWidth.Value = graph.parameters.info_width)); if ((int)graph.parameters.queue_type < comboBoxQType.Items.Count) { @@ -700,36 +705,40 @@ namespace HDLNoCGen } buttonProjSettings.Invoke(new Action(() => buttonProjSettings.Enabled = true)); + buttonProjectDirectory.Invoke(new Action(() => buttonProjectDirectory.Enabled = true)); buttonSerializeGraph.Invoke(new Action(() => buttonSerializeGraph.Enabled = graph.is_created)); buttonCreateVerilog.Invoke(new Action(() => buttonCreateVerilog.Enabled = graph.is_created)); buttonCompileQuartus.Invoke(new Action(() => buttonCompileQuartus.Enabled = graph.is_created && projectSettings.graphVerilogMetadata.verilogGenerated)); + buttonWriteToDB.Invoke(new Action(() => buttonWriteToDB.Enabled = graph.is_created && projectSettings.quartusMetadata.quartusCompiled)); } else { - richTextBoxOutput.Invoke(new Action(() => + textBoxOutput.Invoke(new Action(() => { if (mode == "-c") { - richTextBoxOutput.AppendText($"Failed to create project {projectName} at {projectLocation}\n\n"); + textBoxOutput.AppendText($"Failed to create project {projectName} at {projectLocation}\r\n\r\n"); } else if (mode == "-o") { - richTextBoxOutput.AppendText($"Failed to open project {projectName} at {projectLocation}\n\n"); + textBoxOutput.AppendText($"Failed to open project {projectName} at {projectLocation}\r\n\r\n"); } else if (mode.Substring(0, 2) == "-r") { - richTextBoxOutput.AppendText($"Failed to rename project {projectName} at {projectLocation} to {mode.Substring(3)}\n\n"); + textBoxOutput.AppendText($"Failed to rename project {projectName} at {projectLocation} to {mode.Substring(3)}\r\n\r\n"); } - richTextBoxOutput.ScrollToCaret(); + textBoxOutput.ScrollToCaret(); })); projectLocation = ""; projectName = ""; projectOpened = false; buttonProjSettings.Invoke(new Action(() => buttonProjSettings.Enabled = false)); + buttonProjectDirectory.Invoke(new Action(() => buttonProjectDirectory.Enabled = false)); buttonSerializeGraph.Invoke(new Action(() => buttonSerializeGraph.Enabled = false)); buttonCreateVerilog.Invoke(new Action(() => buttonCreateVerilog.Enabled = false)); buttonCompileQuartus.Invoke(new Action(() => buttonCompileQuartus.Enabled = false)); + buttonWriteToDB.Invoke(new Action(() => buttonWriteToDB.Enabled = false)); } }); } @@ -760,7 +769,8 @@ namespace HDLNoCGen graph_args_string += " -v"; } - Process broker = new Process(); + broker = new Process(); + broker_mode = 2; broker.StartInfo.RedirectStandardOutput = true; broker.StartInfo.CreateNoWindow = true; @@ -774,10 +784,10 @@ namespace HDLNoCGen { if (!String.IsNullOrEmpty(e.Data)) { - richTextBoxOutput.Invoke(new Action(() => + textBoxOutput.Invoke(new Action(() => { - richTextBoxOutput.AppendText($"{e.Data}\n"); - richTextBoxOutput.ScrollToCaret(); + textBoxOutput.AppendText($"{e.Data}\r\n"); + textBoxOutput.ScrollToCaret(); })); } }); @@ -787,35 +797,36 @@ namespace HDLNoCGen broker.Exited += new EventHandler((sender, e) => { + broker_mode = 0; if (broker.ExitCode == 0) { - richTextBoxOutput.Invoke(new Action(() => + textBoxOutput.Invoke(new Action(() => { if (!createVerilog) { - richTextBoxOutput.AppendText($"Graph at project {projectName} at {projectLocation} was serialized\n\n"); + textBoxOutput.AppendText($"Graph at project {projectName} at {projectLocation} was serialized\r\n\r\n"); } else { - richTextBoxOutput.AppendText($"Created SystemVerilog description at project {projectName} at {projectLocation}\n\n"); + textBoxOutput.AppendText($"Created SystemVerilog description at project {projectName} at {projectLocation}\r\n\r\n"); + buttonCompileQuartus.Invoke(new Action(() => buttonCompileQuartus.Enabled = true)); } - richTextBoxOutput.ScrollToCaret(); + textBoxOutput.ScrollToCaret(); })); - buttonCompileQuartus.Invoke(new Action(() => buttonCompileQuartus.Enabled = true)); } else { - richTextBoxOutput.Invoke(new Action(() => + textBoxOutput.Invoke(new Action(() => { if (!createVerilog) { - richTextBoxOutput.AppendText($"Failed to serialize graph at project {projectName} at {projectLocation}\n\n"); + textBoxOutput.AppendText($"Failed to serialize graph at project {projectName} at {projectLocation}\r\n\r\n"); } else { - richTextBoxOutput.AppendText($"Failed to create SystemVerilog description at project {projectName} at {projectLocation}\n\n"); + textBoxOutput.AppendText($"Failed to create SystemVerilog description at project {projectName} at {projectLocation}\r\n\r\n"); } - richTextBoxOutput.ScrollToCaret(); + textBoxOutput.ScrollToCaret(); })); } }); @@ -869,6 +880,150 @@ namespace HDLNoCGen } private void buttonCompileQuartus_Click(object sender, EventArgs e) + { + broker = new Process(); + broker_mode = 3; + + broker.StartInfo.RedirectStandardOutput = true; + broker.StartInfo.CreateNoWindow = true; + broker.EnableRaisingEvents = true; + broker.StartInfo.FileName = $"{broker_location}/Broker.exe"; + broker.StartInfo.WorkingDirectory = broker_location; + broker.StartInfo.Arguments = $"--project -l {projectLocation} -n {projectName} -o " + + $"--quartus"; + + broker.OutputDataReceived += new DataReceivedEventHandler((sender, e) => + { + if (!String.IsNullOrEmpty(e.Data)) + { + textBoxOutput.Invoke(new Action(() => + { + textBoxOutput.AppendText($"{e.Data}\r\n"); + textBoxOutput.ScrollToCaret(); + })); + } + }); + + broker.Start(); + broker.BeginOutputReadLine(); + + broker.Exited += new EventHandler((sender, e) => + { + broker_mode = 0; + if (broker.ExitCode == 0) + { + textBoxOutput.Invoke(new Action(() => + { + textBoxOutput.AppendText($"Compiled Quartus-project at project {projectName} at {projectLocation}\r\n\r\n"); + })); + buttonWriteToDB.Invoke(new Action(() => buttonWriteToDB.Enabled = true)); + } + else + { + textBoxOutput.Invoke(new Action(() => + { + textBoxOutput.AppendText($"Failed to compiled Quartus-project at project {projectName} at {projectLocation}\r\n\r\n"); + })); + } + }); + } + + private void FormMain_FormClosing(object sender, FormClosingEventArgs e) + { + try + { + ProcessKiller.killProcessAndChildren(broker.Id); + } + catch (InvalidOperationException) + { + //Process hasn't started + } + } + + private void buttonStop_Click(object sender, EventArgs e) + { + try + { + ProcessKiller.killProcessAndChildren(broker.Id); + if (broker_mode == 1) + { + textBoxOutput.AppendText("Project management was interrupted\r\n"); + buttonProjSettings.Enabled = false; + buttonProjectDirectory.Enabled = false; + buttonCreateVerilog.Enabled = false; + buttonSerializeGraph.Enabled = false; + + } + else if (broker_mode == 2) + { + textBoxOutput.AppendText("Graph/Verilog generation was interrupted\r\n"); + buttonCompileQuartus.Enabled = false; + buttonWriteToDB.Enabled = false; + } + else if (broker_mode == 3) + { + textBoxOutput.AppendText("Quartus compilation was interrupted\r\n"); + buttonWriteToDB.Enabled = false; + } + broker_mode = 0; + } + catch (InvalidOperationException) + { + //Process hasn't started + } + } + + private void buttonProjectDirectory_Click(object sender, EventArgs e) + { + Process.Start("explorer.exe", projectLocation); + } + + private void FormMain_Load(object sender, EventArgs e) + { + + ToolTip toolTip = new ToolTip(); + + Button[] toolTippedButtons = { + buttonCreateProject, + buttonOpenProject, + buttonProjectDirectory, + buttonProjSettings, + buttonBuildTopologyUpper, + buttonRoutingUpper, + buttonCompile, + buttonSerializeGraph, + buttonCreateVerilog, + buttonCompileQuartus, + buttonWriteToDB, + buttonStop, + buttonAppSettings + }; + + string[] toolTips = + { + "Создать проект", + "Открыть проект", + "Открыть папку проекта", + "Настройки проекта", + "Построить", + "Рассчитать", + "Полная компиляция", + "Сериализация объекта графа", + "Создаине SystemVerilog файлов", + "Quartus компиляция", + "Запись в базу данных", + "Остановка компиляции", + "Настройки приложения" + }; + + for (int i = 0; i < toolTippedButtons.Length; i++) + { + toolTip.SetToolTip(toolTippedButtons[i], toolTips[i]); + } + + } + + private void buttonWriteToDB_Click(object sender, EventArgs e) { FormPeterMessage formPeterMessage = new FormPeterMessage(); formPeterMessage.ShowDialog(); diff --git a/GUI/GUI/GUI.csproj b/GUI/GUI/GUI.csproj index b115caff5b8538975e21662ee9394d8f1734d6a4..16bc37bc8163b0f2d8ad922eeb96cebab3b4f70b 100644 --- a/GUI/GUI/GUI.csproj +++ b/GUI/GUI/GUI.csproj @@ -15,12 +15,14 @@ <Compile Include="..\..\Shared\GraphTorus.cs" Link="GraphTorus.cs" /> <Compile Include="..\..\Shared\IRectangleLike.cs" Link="IRectangleLike.cs" /> <Compile Include="..\..\Shared\IRoundLike.cs" Link="IRoundLike.cs" /> + <Compile Include="..\..\Shared\ProcessKiller.cs" Link="ProcessKiller.cs" /> <Compile Include="..\..\Shared\ProjectSettings.cs" Link="ProjectSettings.cs" /> <Compile Include="..\..\Shared\Settings.cs" Link="Settings.cs" /> </ItemGroup> <ItemGroup> <PackageReference Include="Npgsql" Version="9.0.3" /> + <PackageReference Include="System.Management" Version="9.0.3" /> </ItemGroup> <ItemGroup> diff --git a/GUI/GUI/Properties/Resources.Designer.cs b/GUI/GUI/Properties/Resources.Designer.cs index 4e543fc90af95e092c000cdb12c271c1b047f1b4..ecee966e527c5dc7089d8db01538adec38d8ff8b 100644 --- a/GUI/GUI/Properties/Resources.Designer.cs +++ b/GUI/GUI/Properties/Resources.Designer.cs @@ -90,6 +90,16 @@ namespace GUI.Properties { } } + /// <summary> + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// </summary> + internal static System.Drawing.Bitmap kal15 { + get { + object obj = ResourceManager.GetObject("kal15", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// <summary> /// Поиск локализованного ресурса типа System.Drawing.Bitmap. /// </summary> @@ -150,6 +160,16 @@ namespace GUI.Properties { } } + /// <summary> + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// </summary> + internal static System.Drawing.Bitmap kal42 { + get { + object obj = ResourceManager.GetObject("kal42", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// <summary> /// Поиск локализованного ресурса типа System.Drawing.Bitmap. /// </summary> diff --git a/GUI/GUI/Properties/Resources.resx b/GUI/GUI/Properties/Resources.resx index 72ea76549f0df5ced6a5a4ae512fe8f3cb838d98..517aa51c9549302fd897ac78e094342fdad540f8 100644 --- a/GUI/GUI/Properties/Resources.resx +++ b/GUI/GUI/Properties/Resources.resx @@ -118,43 +118,49 @@ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </resheader> <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> - <data name="kal2" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\kal2.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> + <data name="kal8" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>..\Resources\kal8.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> </data> - <data name="kal21" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\kal21.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> + <data name="kal15" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>..\Resources\kal15.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> </data> <data name="kal41" type="System.Resources.ResXFileRef, System.Windows.Forms"> <value>..\Resources\kal41.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> </data> - <data name="kal10" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\kal10.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> + <data name="kal9" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>..\Resources\kal9.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> + </data> + <data name="kal21" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>..\Resources\kal21.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> </data> <data name="kal31" type="System.Resources.ResXFileRef, System.Windows.Forms"> <value>..\Resources\kal31.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> </data> - <data name="kal" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\kal.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> - <data name="kal8" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\kal8.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> - <data name="kal3" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\kal3.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> + <data name="kal4" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>..\Resources\kal4.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> </data> <data name="kal6" type="System.Resources.ResXFileRef, System.Windows.Forms"> <value>..\Resources\kal6.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> </data> - <data name="kal9" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\kal9.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> - <data name="kal4" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\kal4.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> <data name="kal7" type="System.Resources.ResXFileRef, System.Windows.Forms"> <value>..\Resources\kal7.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> </data> <data name="kal1" type="System.Resources.ResXFileRef, System.Windows.Forms"> <value>..\Resources\kal1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> </data> + <data name="kal3" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>..\Resources\kal3.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> + </data> + <data name="kal" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>..\Resources\kal.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> + </data> + <data name="kal10" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>..\Resources\kal10.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> + </data> + <data name="kal2" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>..\Resources\kal2.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> + </data> + <data name="kal42" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>..\Resources\kal42.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> + </data> </root> \ No newline at end of file diff --git a/GUI/GUI/Resources/kal15.png b/GUI/GUI/Resources/kal15.png new file mode 100644 index 0000000000000000000000000000000000000000..952aacefd8bebd616889f19fc5ce604ab5f724ee Binary files /dev/null and b/GUI/GUI/Resources/kal15.png differ diff --git a/GUI/GUI/Resources/kal42.png b/GUI/GUI/Resources/kal42.png new file mode 100644 index 0000000000000000000000000000000000000000..cf80cc6860a53d32b32d90296b87253ff2cf5123 Binary files /dev/null and b/GUI/GUI/Resources/kal42.png differ diff --git a/Quartus_compiler/Quartus_compiler.sln b/Quartus_compiler/Quartus_compiler.sln new file mode 100644 index 0000000000000000000000000000000000000000..532e5c8f902c81f751801f303a3f7f12df823f96 --- /dev/null +++ b/Quartus_compiler/Quartus_compiler.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Quartus_compiler", "Quartus_compiler\Quartus_compiler.csproj", "{6D199C93-7010-4C77-B509-2D90CD1E708A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6D199C93-7010-4C77-B509-2D90CD1E708A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6D199C93-7010-4C77-B509-2D90CD1E708A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6D199C93-7010-4C77-B509-2D90CD1E708A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6D199C93-7010-4C77-B509-2D90CD1E708A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DA7C1573-FCE0-48C9-8EA2-73A28E11D2FE} + EndGlobalSection +EndGlobal diff --git a/Quartus_compiler/Quartus_compiler/Program.cs b/Quartus_compiler/Quartus_compiler/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..681e7fd271211e7af62797f72797a41fbc35aaa0 --- /dev/null +++ b/Quartus_compiler/Quartus_compiler/Program.cs @@ -0,0 +1,308 @@ +using System; +using System.IO; +using System.Text.Json; +using System.Diagnostics; +using System.Threading.Tasks; +using System.Management; +using System.Text; +using System.Threading; +using System.Collections.Generic; + +namespace HDLNoCGen +{ + public static class NetworkCompilationService + { + + private static async Task<bool> CheckProjectPath(string projectPath) + { + if (string.IsNullOrEmpty(projectPath)) + { + Console.WriteLine("Error: no project path"); + return false; + } + + if (!Directory.Exists(projectPath)) + { + Console.WriteLine($"Error: project path not found: {projectPath}"); + return false; + } + + return true; + } + + /// <summary> + /// Запускает компиляцию сети с параметрами из Settings + /// </summary> + public static async Task CompileNetworkFromSettings(string projectPath, string projectName) + { + try + { + if (string.IsNullOrEmpty(projectPath)) + { + Console.WriteLine("Error: no project path"); + Environment.Exit(1); + } + await CompileNetwork(projectPath, projectName); + } + catch (Exception ex) + { + Console.WriteLine($"Compilation error: {ex.Message}"); + Environment.Exit(1); + } + } + + public static async Task CompileNetwork(string projectPath, string projectName) + { + try + { + if (!await CheckProjectPath(projectPath)) + { + Console.WriteLine($"Error: project path not found: {projectPath}"); + Environment.Exit(1); + } + + // Проверяем метаданные проекта + string metadataPath = Path.Combine(projectPath, $"{projectName}_metadata.json"); + if (!File.Exists(metadataPath)) + { + Console.WriteLine($"Error: no {metadataPath} metadata file"); + Environment.Exit(1); + } + + string metadataJson = await File.ReadAllTextAsync(metadataPath); + var metadata = JsonSerializer.Deserialize<ProjectSettings>(metadataJson); + + if (!metadata.graphVerilogMetadata.graphSerialized || !metadata.graphVerilogMetadata.verilogGenerated) + { + Console.WriteLine("Error: graphSerialized or verilogGenerated is false"); + Environment.Exit(1); + } + + // Путь к директории с верилог файлами + string verilogPath = Path.Combine(projectPath, $"{projectName}_NoC_description"); + string simulateQPath = Path.Combine(verilogPath, "Simulate_q.bat"); + string simulateRPath = Path.Combine(verilogPath, "Simulate_r.bat"); + string compilePath = Path.Combine(verilogPath, "Compile.bat"); + + if (!File.Exists(simulateQPath) || !File.Exists(simulateRPath) || !File.Exists(compilePath)) + { + Console.WriteLine($"Error: files Simulate_q.bat, Simulate_r.bat or Compile.bat not found: {verilogPath}"); + Environment.Exit(1); + } + + string simulation_report = ""; + string simulation_error = ""; + string[] separators = { "Errors: ", ", Warnings: " }; + + DataReceivedEventHandler simulateLineTextReader = (s, ev) => + { + if (!String.IsNullOrEmpty(ev.Data)) + { + simulation_report += $"{ev.Data}\n"; + Console.WriteLine(ev.Data); + } + }; + + DataReceivedEventHandler simulateLineErrorReader = (s, ev) => + { + if (!String.IsNullOrEmpty(ev.Data)) + { + simulation_error += $"{ev.Data}\n"; + Console.WriteLine($"Error: {ev.Data}"); + } + }; + + DataReceivedEventHandler compileLineTextReader = (s, ev) => + { + if (!String.IsNullOrEmpty(ev.Data)) + { + Console.WriteLine(ev.Data); + } + }; + + DataReceivedEventHandler compileLineErrorReader = (s, ev) => + { + if (!String.IsNullOrEmpty(ev.Data)) + { + Console.WriteLine($"Error: {ev.Data}"); + } + }; + + + Process simulation_process = new Process(); + Process compilation_process = new Process(); + + EventHandler simulationFinishingHandler = (s, ev) => + { + List<string> sliced_report = simulation_report.Split(separators, System.StringSplitOptions.None).ToList(); + + if (!sliced_report[1].Equals("0") || !sliced_report[3].Equals("0")) + { + + ProcessKiller.killProcessAndChildren(simulation_process.Id); + + throw new Exception("Simulation error"); + } + + simulation_report = ""; + + }; + + simulation_process.StartInfo.FileName = simulateQPath; + simulation_process.StartInfo.UseShellExecute = false; + simulation_process.StartInfo.RedirectStandardOutput = true; + simulation_process.StartInfo.RedirectStandardError = true; + simulation_process.StartInfo.CreateNoWindow = true; + simulation_process.StartInfo.WorkingDirectory = verilogPath; + simulation_process.EnableRaisingEvents = true; + + simulation_process.Exited += simulationFinishingHandler; + simulation_process.OutputDataReceived += simulateLineTextReader; + simulation_process.ErrorDataReceived += simulateLineErrorReader; + + Console.CancelKeyPress += delegate { + ProcessKiller.killProcessAndChildren(compilation_process.Id); + ProcessKiller.killProcessAndChildren(simulation_process.Id); + }; + + // Настройка процесса симуляции + + // Запуск симуляции + simulation_process.Start(); + simulation_process.BeginOutputReadLine(); + simulation_process.BeginErrorReadLine(); + await simulation_process.WaitForExitAsync(); + simulation_process.CancelOutputRead(); + simulation_process.CancelErrorRead(); + + if (simulation_process.ExitCode != 0) + { + Console.WriteLine("Error when executing Simulate_q.bat"); + Environment.Exit(1); + } + + Console.CancelKeyPress += delegate { + ProcessKiller.killProcessAndChildren(compilation_process.Id); + ProcessKiller.killProcessAndChildren(simulation_process.Id); + }; + + // Настройка процесса симуляции + simulation_process.StartInfo.FileName = simulateRPath; + + // Запуск симуляции + simulation_process.Start(); + simulation_process.BeginOutputReadLine(); + simulation_process.BeginErrorReadLine(); + await simulation_process.WaitForExitAsync(); + + if (simulation_process.ExitCode != 0) + { + Console.WriteLine("Error when executing Simulate_r.bat"); + Environment.Exit(1); + } + + // Настройка процесса компиляции + compilation_process.StartInfo.FileName = compilePath; + compilation_process.StartInfo.UseShellExecute = false; + compilation_process.StartInfo.RedirectStandardOutput = true; + compilation_process.StartInfo.RedirectStandardError = true; + compilation_process.StartInfo.CreateNoWindow = true; + compilation_process.StartInfo.WorkingDirectory = verilogPath; + + compilation_process.OutputDataReceived += compileLineTextReader; + compilation_process.ErrorDataReceived += compileLineErrorReader; + + // Запуск компиляции + compilation_process.Start(); + compilation_process.BeginOutputReadLine(); + compilation_process.BeginErrorReadLine(); + await compilation_process.WaitForExitAsync(); + + // Проверка успешности компиляции + string clockerLoggerPath = Path.Combine(verilogPath, "clocker.logger"); + + if (compilation_process.ExitCode != 0 || !File.Exists(clockerLoggerPath)) + { + Console.WriteLine("Error when compiling a Quartus-project"); + if (!File.Exists(clockerLoggerPath)) + { + Console.WriteLine("File clocker.logger not found"); + } + Environment.Exit(1); + } + + // Если компиляция успешна, обновляем метаданные + metadata.quartusMetadata.quartusCompiled = true; + string updatedMetadataJson = JsonSerializer.Serialize(metadata, new JsonSerializerOptions { WriteIndented = true }); + await File.WriteAllTextAsync(metadataPath, updatedMetadataJson); + + Console.WriteLine("Compilation successful"); + } + catch (Exception ex) + { + Console.WriteLine($"Error when compiling {projectName}: {ex.Message}"); + throw; + } + finally + { + GC.Collect(); + } + } + + /// <summary> + /// Точка входа для запуска микросервиса + /// </summary> + public static async Task Main(string[] args) + { + try + { + if (args.Length == 0) + { + Console.WriteLine("Usage: NetworkCompilationService.exe [--project_folder path] [--quartus_path path]"); + return; + } + + string project_path = ""; + string project_name = ""; + + // Парсим аргументы + for (int i = 0; i < args.Length; i++) + { + switch (args[i].ToLower()) + { + case "-l": + case "--location": + if (i + 1 < args.Length) + { + project_path = args[++i]; + } + break; + case "-n": + case "--name": + if (i + 1 < args.Length) + { + project_name = args[++i]; + } + break; + default: + Console.WriteLine($"Non-existent arguments: {args[i]}"); + return; + } + } + + // Запускаем компиляцию + await CompileNetworkFromSettings(project_path, project_name); + Console.WriteLine("Compilation successful"); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + Environment.Exit(1); + } + finally + { + GC.Collect(); + } + } + } +} \ No newline at end of file diff --git a/Quartus_compiler/Quartus_compiler/Properties/launchSettings.json b/Quartus_compiler/Quartus_compiler/Properties/launchSettings.json new file mode 100644 index 0000000000000000000000000000000000000000..5e1c894e5dec1347e14061d29b765a797fc900f4 --- /dev/null +++ b/Quartus_compiler/Quartus_compiler/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "Quartus_compiler": { + "commandName": "Project", + "commandLineArgs": "-l D:/kal -n kal" + } + } +} \ No newline at end of file diff --git a/Quartus_compiler/Quartus_compiler/Quartus_compiler.csproj b/Quartus_compiler/Quartus_compiler/Quartus_compiler.csproj new file mode 100644 index 0000000000000000000000000000000000000000..564b38e9ab4e968d46f348efc37d264b43ad3e1e --- /dev/null +++ b/Quartus_compiler/Quartus_compiler/Quartus_compiler.csproj @@ -0,0 +1,19 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + + <ItemGroup> + <Compile Include="..\..\Shared\ProcessKiller.cs" Link="ProcessKiller.cs" /> + <Compile Include="..\..\Shared\ProjectSettings.cs" Link="ProjectSettings.cs" /> + </ItemGroup> + + <ItemGroup> + <PackageReference Include="System.Management" Version="9.0.3" /> + </ItemGroup> + +</Project> diff --git a/Shared/ProcessKiller.cs b/Shared/ProcessKiller.cs new file mode 100644 index 0000000000000000000000000000000000000000..039b576d249518f9de630ab2a9cf85cef87038d3 --- /dev/null +++ b/Shared/ProcessKiller.cs @@ -0,0 +1,44 @@ +using System.Diagnostics; +using System.Globalization; +using System.Management; +using System.Reflection.Metadata; +using System.Text; + +namespace HDLNoCGen +{ + + static class ProcessKiller + { + + public static void killProcessAndChildren(int pid) + { + if (pid == 0) + { + return; + } + ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * From Win32_Process Where ParentProcessID=" + pid); + ManagementObjectCollection moc = searcher.Get(); + foreach (ManagementObject mo in moc) + { + killProcessAndChildren(Convert.ToInt32(mo["ProcessID"])); + } + try + { + Process proc = Process.GetProcessById(pid); + proc.Kill(); + } + catch (ArgumentException) + { + // Process already exited. + } + catch (System.ComponentModel.Win32Exception) + { + //Access rejected + } + + GC.Collect(); + + } + } +} + diff --git a/Shared/ProjectGenerator.cs b/Shared/ProjectGenerator.cs index 652c1d10f7adbb5eafb52d3827226ebd6010d410..406b54817b196facc93c186c2a19902b71952077 100644 --- a/Shared/ProjectGenerator.cs +++ b/Shared/ProjectGenerator.cs @@ -1,6 +1,4 @@ -using Npgsql; -using NpgsqlTypes; -using System.Diagnostics; +using System.Diagnostics; using System.Globalization; using System.Management; using System.Reflection.Metadata;