Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/OneWare.GhdlExtension/GhdlExtensionModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using OneWare.Essentials.Models;
using OneWare.Essentials.PackageManager;
using OneWare.Essentials.Services;
using OneWare.Essentials.ToolEngine;
using OneWare.Essentials.ToolEngine.Strategies;
using OneWare.Essentials.ViewModels;
using OneWare.GhdlExtension.Services;
using OneWare.GhdlExtension.ViewModels;
Expand Down Expand Up @@ -279,7 +281,7 @@

serviceProvider.Resolve<IPackageService>().RegisterPackage(GhdlPackage);

serviceProvider.Resolve<ISettingsService>().RegisterTitledFilePath("Simulator", "GHDL", GhdlPathSetting,

Check warning on line 284 in src/OneWare.GhdlExtension/GhdlExtensionModule.cs

View workflow job for this annotation

GitHub Actions / build

'ISettingsService.RegisterTitledFilePath(string, string, string, string, string, string, string?, string?, Func<string, bool>?, params FilePickerFileType[])' is obsolete: 'Use RegisterSetting instead'

Check warning on line 284 in src/OneWare.GhdlExtension/GhdlExtensionModule.cs

View workflow job for this annotation

GitHub Actions / build

'ISettingsService.RegisterTitledFilePath(string, string, string, string, string, string, string?, string?, Func<string, bool>?, params FilePickerFileType[])' is obsolete: 'Use RegisterSetting instead'
"GHDL Path", "Path for GHDL executable", "",
null, serviceProvider.Resolve<IPaths>().NativeToolsDirectory, File.Exists);

Expand Down Expand Up @@ -396,11 +398,13 @@
}
}
}));

toolService.Register(new ToolContext("ghdl", "Synth Tool", "ghdl"), new NativeStrategy());

serviceProvider.Resolve<IProjectExplorerService>().RegisterConstructContextMenu(((list, models) =>
{
if (list[0] is IProjectFolder { Root: UniversalFpgaProjectRoot root } folder &&
folder.Children.Any(x => x is IProjectFile file))

Check warning on line 407 in src/OneWare.GhdlExtension/GhdlExtensionModule.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'source' in 'bool Enumerable.Any<IProjectExplorerNode>(IEnumerable<IProjectExplorerNode> source, Func<IProjectExplorerNode, bool> predicate)'.

Check warning on line 407 in src/OneWare.GhdlExtension/GhdlExtensionModule.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'source' in 'bool Enumerable.Any<IProjectExplorerNode>(IEnumerable<IProjectExplorerNode> source, Func<IProjectExplorerNode, bool> predicate)'.
{
IEnumerable<string>? libs = root.Properties.GetStringArray("GHDL_Libraries");

Expand Down Expand Up @@ -448,7 +452,7 @@
}));


var ghdlPreCompiler = serviceProvider.Resolve<GhdlVhdlToVerilogPreCompileStep>();
// var ghdlPreCompiler = serviceProvider.Resolve<GhdlVhdlToVerilogPreCompileStep>();
serviceProvider.Resolve<IWindowService>().RegisterUiExtension("UniversalFpgaToolBar_CompileMenuExtension",
new OneWareUiExtension(x =>
{
Expand Down Expand Up @@ -534,7 +538,7 @@
{
if (folder.Root is UniversalFpgaProjectRoot root)
{
foreach (var file in folder.Children.Where(x =>

Check warning on line 541 in src/OneWare.GhdlExtension/GhdlExtensionModule.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'source' in 'IEnumerable<IProjectExplorerNode> Enumerable.Where<IProjectExplorerNode>(IEnumerable<IProjectExplorerNode> source, Func<IProjectExplorerNode, bool> predicate)'.

Check warning on line 541 in src/OneWare.GhdlExtension/GhdlExtensionModule.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'source' in 'IEnumerable<IProjectExplorerNode> Enumerable.Where<IProjectExplorerNode>(IEnumerable<IProjectExplorerNode> source, Func<IProjectExplorerNode, bool> predicate)'.
x is IProjectFile { Extension: ".vhd" or ".vhdl" }))
{
await AddFileToLibraryAsync(library, (file as IProjectFile)!);
Expand Down
6 changes: 4 additions & 2 deletions src/OneWare.GhdlExtension/GhdlVhdlToVerilogPreCompileStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ public class GhdlVhdlToVerilogPreCompileStep(GhdlService ghdlService, ILogger lo
public string Name => "GHDL Vhdl to Verilog";

public readonly string BuildDir = "build";
public readonly string GhdlOutputDir = "ghdl-output";
public readonly string GhdlOutputDir = "gen_verilog";
public string? VerilogFileName;

public async Task<bool> PerformPreCompileStepAsync(UniversalFpgaProjectRoot project, FpgaModel fpga)
{
if (project.TopEntity == null || !project.TopEntity.EndsWith(".vhd")) return false;

try
{
var buildPath = Path.Combine(project.FullPath, BuildDir);
Expand All @@ -27,7 +29,7 @@ public async Task<bool> PerformPreCompileStepAsync(UniversalFpgaProjectRoot proj

var vhdlFile = Path.Combine(project.RootFolderPath, project.TopEntity ?? "");
VerilogFileName = Path.GetFileNameWithoutExtension(vhdlFile)+".v";

var success = await ghdlService.SynthAsync(vhdlFile, "verilog", ghdlOutputPath);
return success;
}
Expand Down
2 changes: 1 addition & 1 deletion src/OneWare.GhdlExtension/GhdlYosysToolchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace OneWare.GhdlExtension;

public class GhdlYosysToolchain(GhdlToolchainService ghdlToolchainService, YosysService yosysService) : YosysToolchain(yosysService)
{
public const string ToolchainId = "ghdl_yosys";
public const string ToolchainId = "GHDL_Yosys";

public override async Task<bool> CompileAsync(UniversalFpgaProjectRoot project, FpgaModel fpga)
{
Expand Down
38 changes: 19 additions & 19 deletions src/OneWare.GhdlExtension/Services/GhdlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using OneWare.Essentials.Models;
using OneWare.Essentials.PackageManager.Compatibility;
using OneWare.Essentials.Services;
using OneWare.Essentials.ToolEngine;
using OneWare.Essentials.ViewModels;
using OneWare.GhdlExtension.ViewModels;
using OneWare.UniversalFpgaProjectSystem.Context;
Expand All @@ -19,11 +20,11 @@ public class GhdlService
private readonly ILogger _logger;
private readonly IMainDockService _dockService;
private readonly IPackageService _packageService;
private readonly IChildProcessService _childProcessService;
private readonly IEnvironmentService _environmentService;
private readonly IOutputService _outputService;
private readonly ISettingsService _settingsService;
private readonly IProjectExplorerService _projectExplorerService;
private readonly IToolExecutionDispatcherService _toolExecutionDispatcherService;

public AsyncRelayCommand SimulateCommand { get; }

Expand All @@ -34,18 +35,19 @@ public class GhdlService
private string _path = string.Empty;

public GhdlService(ILogger logger, IMainDockService dockService, ISettingsService settingsService,
IPackageService packageService, IChildProcessService childProcessService,
IPackageService packageService,
IEnvironmentService environmentService,
IOutputService outputService, IProjectExplorerService projectExplorerService)
IOutputService outputService, IProjectExplorerService projectExplorerService,
IToolExecutionDispatcherService toolExecutionDispatcherService)
{
_logger = logger;
_dockService = dockService;
_packageService = packageService;
_childProcessService = childProcessService;
_environmentService = environmentService;
_outputService = outputService;
_settingsService = settingsService;
_projectExplorerService = projectExplorerService;
_toolExecutionDispatcherService = toolExecutionDispatcherService;

settingsService.GetSettingObservable<string>(GhdlExtensionModule.GhdlPathSetting).Subscribe(x =>
{
Expand All @@ -62,7 +64,7 @@ public GhdlService(ILogger logger, IMainDockService dockService, ISettingsServic
SynthToVerilogCommand = new AsyncRelayCommand(() => SynthCurrentFileAsync("verilog"),
() => Path.GetExtension(_dockService.CurrentDocument?.FullPath) is ".vhd" or ".vhdl");

_dockService.WhenValueChanged(x => x.CurrentDocument).Subscribe(x =>
_dockService.WhenValueChanged(x => x.CurrentDocument).Subscribe(_ =>
{
SimulateCommand.NotifyCanExecuteChanged();
});
Expand Down Expand Up @@ -90,8 +92,8 @@ or PackageStatus.Installing

StringBuilder stdoutBuilder = new StringBuilder();
StringBuilder stderrBuilder = new StringBuilder();

(bool success, _) = await _childProcessService.ExecuteShellAsync(_path, arguments, workingDirectory,
var command = ToolCommand.FromShellParams(_path, arguments, workingDirectory,
status, state, showTimer, x =>
{
if (x.StartsWith("ghdl:error:"))
Expand All @@ -116,6 +118,7 @@ or PackageStatus.Installing
return true;
});

var (success, _) = await _toolExecutionDispatcherService.ExecuteAsync(command);
return (success, stdoutBuilder.ToString(), stderrBuilder.ToString());
}

Expand Down Expand Up @@ -151,17 +154,17 @@ private void SetEnvironment()
private Task SynthCurrentFileAsync(string output)
{
if (_dockService.CurrentDocument?.FullPath is { } fullPath)
return SynthAsync(fullPath, output, Path.GetDirectoryName(fullPath));
return SynthAsync(fullPath, output, Path.GetDirectoryName(fullPath)!);
return Task.CompletedTask;
}

private async Task<bool> ElaborateAsync(string fullPath, TestBenchContext context)
{
if (_projectExplorerService.GetRootFromFile(fullPath) is not UniversalFpgaProjectRoot root) return false;

IEnumerable<string> libfiles = GetAllLibraryFiles(root);
var libfiles = GetAllLibraryFiles(root);

IEnumerable<string>? libnames = root.Properties.GetStringArray("GHDL_Libraries");
var libnames = root.Properties.GetStringArray("GHDL_Libraries");

var vhdlFiles = root.GetFiles("*.vhd").Concat(root.GetFiles("*.vhdl"))
.Where(x => !root.IsCompileExcluded(x))
Expand Down Expand Up @@ -218,12 +221,12 @@ private async Task<bool> ElaborateAsync(string fullPath, TestBenchContext contex
"GHDL Init...",
AppState.Loading, true);
if (!initFiles.success) return false;

if (libnames is not null)
{
foreach (string libname in libnames)
foreach (var libname in libnames)
{
bool success = await ImportLibraryAsync(root, context, libname, workingDirectory, ghdlOptions);
var success = await ImportLibraryAsync(root, context, libname, workingDirectory, ghdlOptions);

if (!success)
{
Expand Down Expand Up @@ -259,10 +262,9 @@ private async Task<bool> ElaborateAsync(string fullPath, TestBenchContext contex
private async Task<bool> ImportLibraryAsync(UniversalFpgaProjectRoot root, TestBenchContext context, string libname,
string workingDirectory, List<string> ghdlOptions)
{
string buildDirectory = Path.Combine(workingDirectory, "build");

// Get files contained in library
IEnumerable<string>? libraryFiles = root.Properties.GetStringArray($"GHDL-LIB_{libname}");
var libraryFiles = root.Properties.GetStringArray($"GHDL-LIB_{libname}");

if (libraryFiles is null)
{
Expand All @@ -271,7 +273,7 @@ private async Task<bool> ImportLibraryAsync(UniversalFpgaProjectRoot root, TestB
return true;
}

IEnumerable<string> vhdlFiles = root.GetFiles("*.vhd").Concat(root.GetFiles("*.vhdl"))
var vhdlFiles = root.GetFiles("*.vhd").Concat(root.GetFiles("*.vhdl"))
.Where(x => !root.IsCompileExcluded(x))
.Where(x => libraryFiles.Contains(x.ToUnixPath()));

Expand All @@ -290,8 +292,6 @@ private async Task<bool> ImportLibraryAsync(UniversalFpgaProjectRoot root, TestB
private async Task<bool> MakeLibraryAsync(UniversalFpgaProjectRoot root, TestBenchContext context, string libname,
string workingDirectory, List<string> ghdlOptions)
{
string buildDirectory = Path.Combine(workingDirectory, "build");

if (root.TopEntity == null)
{
_logger.Error("No toplevel entity has been set");
Expand Down Expand Up @@ -324,7 +324,7 @@ private IEnumerable<string> GetAllLibraryFiles(UniversalFpgaProjectRoot root)

foreach (string lib in libnames)
{
IEnumerable<string>? libfiles = root.Properties.GetStringArray($"GHDL-LIB_{lib}")?.ToArray();
var libfiles = root.Properties.GetStringArray($"GHDL-LIB_{lib}")?.ToArray();

if (libfiles is null || !libfiles.Any())
{
Expand Down
Loading