Skip to content

Commit 2d85ad3

Browse files
committed
Added ProjectConfiguration.cs to store project configs
1 parent 6600e0a commit 2d85ad3

8 files changed

Lines changed: 157 additions & 20 deletions

File tree

NetGenBox.CLI/NetGenBox.CLI.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@
1212
<ProjectReference Include="..\NetGenBox.Parser\NetGenBox.Parser.csproj" />
1313
</ItemGroup>
1414

15+
<ItemGroup>
16+
<PackageReference Include="CliFx" Version="2.3.5" />
17+
</ItemGroup>
18+
1519
</Project>

NetGenBox.CLI/NetListCommand.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using CliFx;
2+
using CliFx.Attributes;
3+
using CliFx.Infrastructure;
4+
5+
namespace NetGenBox.CLI;
6+
7+
[Command("netgen")]
8+
public class NetListCommand : ICommand
9+
{
10+
11+
[CommandOption("path", 'p', Description = "Path of EDIF netlist file generated by Xilinx, usually *.ndf")]
12+
public required string EdifPath { get; set; }
13+
14+
[CommandOption("output", 'o',Description = "Output path to write generated verilog file", IsRequired = false)]
15+
public string? OutputPath { get; set; }
16+
17+
public ValueTask ExecuteAsync(IConsole console)
18+
{
19+
20+
return default;
21+
}
22+
}

NetGenBox.Core/VerilogModuleParser.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,16 @@ public string ExportString(string moduleBody)
4545

4646
public class VerilogModuleParser
4747
{
48-
private readonly string _module;
49-
5048

51-
public VerilogModuleParser(string module)
52-
{
53-
_module = module;
54-
}
55-
56-
public VerilogModule? ParseModule()
49+
public static VerilogModule? ParseModule(string module)
5750
{
5851
// Pattern to match the module name and its ports
5952
string modulePattern = @"module\s+(\w+)\s*\((.*?)\);";
6053
// Pattern to match input and output declarations
6154
string ioPattern = @"(input|output)\s*((?:\[\d+:\d+\])?\s*\w+)";
6255

6356
// Find the module declaration
64-
var moduleMatch = Regex.Match(_module, modulePattern);
57+
var moduleMatch = Regex.Match(module, modulePattern);
6558
if (moduleMatch.Success)
6659
{
6760

@@ -72,10 +65,10 @@ public VerilogModuleParser(string module)
7265
};
7366

7467
string ports = moduleMatch.Groups[2].Value;
75-
verilogModule.IoDefinitions = ports.Split(',').ToList();
68+
verilogModule.IoDefinitions = ports.Split(',').Select(t => t.TrimStart().TrimEnd()).ToList();
7669

7770
// Find all input and output declarations
78-
var matches = Regex.Matches(_module, ioPattern);
71+
var matches = Regex.Matches(module, ioPattern);
7972
foreach (Match m in matches)
8073
{
8174
var type = m.Groups[1].Value;

NetGenBox.UI/MainWindow.axaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
<DockPanel LastChildFill="True">
1212
<Menu DockPanel.Dock="Top">
1313
<MenuItem Header="_File">
14-
<MenuItem Header="_Open Files" Name="OpenFilesMenuItem" Click="OpenFilesMenuItem_OnClick"/>
14+
<MenuItem Header="_New Project Files" Name="OpenFilesMenuItem" Click="OpenFilesMenuItem_OnClick"/>
15+
<MenuItem Header="_Open Project" Name="OpenProjectMenuItem" Click="OpenProjectMenuItem_OnClick"></MenuItem>
1516
<Separator/>
1617
<MenuItem Header="_Exit" Name="ExitMenuItem" Click="ExitMenuItem_OnClick"/>
1718
</MenuItem>
@@ -38,9 +39,10 @@
3839
<ComboBox Name="IseDeviceCombo" HorizontalAlignment="Stretch" SelectionChanged="IseDeviceCombo_OnSelectionChanged"></ComboBox>
3940
<Label Margin="0 10 0 0"> Selected Files</Label>
4041
<ListBox Name="SelectedFilesListBox" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinHeight="150" CornerRadius="8" DoubleTapped="SelectedFilesListBox_OnDoubleTapped"> </ListBox>
42+
<TextBlock Margin="0 10 0 0" TextWrapping="Wrap" Foreground="MediumBlue" FontStyle="Italic"> DoubleClick on file name to view code</TextBlock>
4143
</StackPanel>
4244
<StackPanel DockPanel.Dock="Bottom" VerticalAlignment="Bottom" Margin="16" Spacing="16">
43-
<Button DockPanel.Dock="Bottom" HorizontalAlignment="Stretch" Name="RunButton" Click="RunButton_OnClick">Run</Button>
45+
<Button DockPanel.Dock="Bottom" HorizontalAlignment="Stretch" Name="RunButton" Click="RunButton_OnClick" >Save Project | Synthesis</Button>
4446
<Button DockPanel.Dock="Bottom" HorizontalAlignment="Stretch" Name="GenerateEdifButton" Click="GenerateEdifButton_OnClick">Generate EDIF</Button>
4547
</StackPanel>
4648
</DockPanel>

NetGenBox.UI/MainWindow.axaml.cs

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,23 @@ public partial class MainWindow : Window
4242
public List<string> ModuleNames { get; set; }
4343

4444
private string _edifFileName;
45-
45+
46+
private ProjectConfiguration? _projectConfiguration;
4647

4748
public MainWindow()
4849
{
4950
InitializeComponent();
5051
}
5152

52-
private void CustomModuleMenuItem_OnClick(object? sender, RoutedEventArgs e)
53+
private async void CustomModuleMenuItem_OnClick(object? sender, RoutedEventArgs e)
5354
{
55+
56+
var customModuleWindow = new CustomModules()
57+
{
58+
BasePath = Configuration["isePath"]
59+
};
60+
customModuleWindow.Show(this);
61+
return;
5462
VerilogEdit verilogEdit = new VerilogEdit()
5563
{
5664
WorkDir = _selectedDirectory
@@ -256,7 +264,20 @@ private async void RunButton_OnClick(object? sender, RoutedEventArgs e)
256264
var box = MessageBoxManager
257265
.GetMessageBoxStandard("Result", "Synthesize completed successfully",
258266
ButtonEnum.Ok, MsBox.Avalonia.Enums.Icon.Success);
259-
await box.ShowWindowDialogAsync(this);
267+
string customPath = "custommodules";
268+
if (Directory.Exists(customPath))
269+
Directory.CreateDirectory(Path.Combine(_selectedDirectory, customPath));
270+
_projectConfiguration = new ProjectConfiguration()
271+
{
272+
BaseProject = _selectedDirectory,
273+
VerilogFiles = _selectedFiles.Select(t => t.Name).ToList(),
274+
EdifFile = "",
275+
TopModule = VerilogTopInstanceCombo.SelectedItem.ToString() ?? "",
276+
CustomModulePath = customPath
277+
};
278+
await _projectConfiguration.Save();
279+
280+
await box.ShowAsPopupAsync(this);
260281
}
261282

262283
}
@@ -307,11 +328,18 @@ private async void GenerateEdifButton_OnClick(object? sender, RoutedEventArgs e)
307328

308329
if (result == 0)
309330
{
331+
_edifFileName = _selectedDirectory + "/" + topModule + "_edif.ndf";
332+
if (_projectConfiguration is not null)
333+
{
334+
_projectConfiguration.EdifFile = topModule + "_edif.ndf";
335+
await _projectConfiguration.Save();
336+
}
310337
var box = MessageBoxManager
311338
.GetMessageBoxStandard("Result", "EDIF generation completed successfully",
312339
ButtonEnum.Ok, MsBox.Avalonia.Enums.Icon.Success);
340+
313341
await box.ShowWindowDialogAsync(this);
314-
_edifFileName = _selectedDirectory + "/" + topModule + "_edif.ndf";
342+
315343
}
316344
}
317345

@@ -434,13 +462,60 @@ private async void GenerateNetlistMenuItem_OnClick(object? sender, RoutedEventAr
434462
netGenBox.Parse();
435463
var verilogGenerator = new VerilogGenerator(netGenBox.Nets);
436464
var verilogFile = verilogGenerator.GenerateGateLevel();
437-
var selectedModule = _fileContents[VerilogTopInstanceCombo?.SelectedValue as string];
438-
var moduleParser = new VerilogModuleParser(selectedModule);
439-
var module = moduleParser.ParseModule();
465+
var selectedModule = string.Empty;
466+
if (_fileContents.ContainsKey(VerilogTopInstanceCombo?.SelectedItem as string ?? "TP"))
467+
selectedModule = _fileContents[VerilogTopInstanceCombo?.SelectedValue as string ?? "TP"];
468+
else
469+
{
470+
var msgBox = MessageBoxManager.GetMessageBoxStandard("Warning",
471+
"You didn't select top module, select top module verilog file", ButtonEnum.Ok,
472+
MsBox.Avalonia.Enums.Icon.Warning);
473+
await msgBox.ShowAsPopupAsync(this);
474+
var topLevel = TopLevel.GetTopLevel(this);
475+
var selectedFile = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
476+
{
477+
Title = "Open Verilog Files",
478+
AllowMultiple = false,
479+
FileTypeFilter = new FilePickerFileType[]
480+
{
481+
new FilePickerFileType("Verilog File | (*.v)")
482+
{
483+
Patterns = new []{"*.v"}
484+
}
485+
},
486+
});
487+
if (selectedFile.Count != 1)
488+
return;
489+
selectedModule = await File.ReadAllTextAsync(selectedFile.First().Path.AbsolutePath);
490+
_fileContents["TP"] = selectedModule;
491+
}
492+
var module = VerilogModuleParser.ParseModule(selectedModule);
440493
var codeViewer = new CodeViewer(module.ExportString(verilogFile))
441494
{
442495
Title = "NetList"
443496
};
444497
codeViewer.Show(this);
445498
}
499+
500+
private async void OpenProjectMenuItem_OnClick(object? sender, RoutedEventArgs e)
501+
{
502+
var topLevel = TopLevel.GetTopLevel(this);
503+
504+
var selectedFiles = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
505+
{
506+
Title = "Open Project File",
507+
AllowMultiple = false,
508+
FileTypeFilter = new FilePickerFileType[]
509+
{
510+
new FilePickerFileType("Project Configuration File | (*.json)")
511+
{
512+
Patterns = new []{"*.json"}
513+
}
514+
}
515+
});
516+
if (selectedFiles.Count == 1)
517+
{
518+
_projectConfiguration = await ProjectConfiguration.ReadConfigAsync(selectedFiles.First().Path.AbsolutePath);
519+
}
520+
}
446521
}

NetGenBox.UI/NetGenBox.UI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<PackageReference Include="Avalonia.AvaloniaEdit" Version="11.0.5" />
1515
<PackageReference Include="Avalonia.Controls.TreeDataGrid" Version="11.0.2" />
1616
<PackageReference Include="Avalonia.Desktop" Version="11.0.6"/>
17+
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.6" />
1718
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.6"/>
1819
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.6"/>
1920
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->

NetGenBox.UI/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Avalonia;
22
using System;
33
using Avalonia.Dialogs;
4+
using Avalonia.ReactiveUI;
45
using Microsoft.Extensions.Configuration;
56

67
namespace NetGenBox.UI;
@@ -21,5 +22,6 @@ public static AppBuilder BuildAvaloniaApp()
2122
.UsePlatformDetect()
2223
.UseSkia()
2324
.WithInterFont()
25+
.UseReactiveUI()
2426
.LogToTrace();
2527
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Text.Json;
4+
using System.Text.Json.Serialization;
5+
using System.Threading.Tasks;
6+
7+
namespace NetGenBox.UI;
8+
9+
public class ProjectConfiguration
10+
{
11+
[JsonPropertyName("basePath")]
12+
public string BaseProject { get; set; }
13+
14+
[JsonPropertyName("verilogFiles")]
15+
public List<string> VerilogFiles { get; set; }
16+
17+
[JsonPropertyName("topModule")] public string TopModule { get; set; }
18+
19+
[JsonPropertyName("edifFile")]
20+
public string EdifFile { get; set; }
21+
22+
[JsonPropertyName("customModulePath")]
23+
public string CustomModulePath { get; set; }
24+
25+
public async Task Save()
26+
{
27+
FileStream fs = File.OpenWrite(Path.Combine(BaseProject, "netgen.json"));
28+
await JsonSerializer.SerializeAsync(fs, this);
29+
}
30+
31+
public static async Task<ProjectConfiguration?> ReadConfigAsync(string path)
32+
{
33+
if (path.EndsWith("netgen.json") == false)
34+
path = Path.Combine(path, "netgen.json");
35+
var fs = File.OpenRead(path);
36+
return await JsonSerializer.DeserializeAsync<ProjectConfiguration>(fs);
37+
}
38+
}

0 commit comments

Comments
 (0)