Skip to content

Commit

Permalink
basic verilog nodeprovider
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Nov 19, 2023
1 parent 784a3de commit 8561341
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 44 deletions.
4 changes: 0 additions & 4 deletions src/OneWare.Core/Styles/DataGrid.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,4 @@
<Setter Property="Fill" Value="{DynamicResource ThemeAccentBrush4}" />
</Style>

<Style Selector="DataGridRow:selected">
<Setter Property="Foreground" Value="{DynamicResource ThemeForegroundBrush}" />
</Style>

</Styles>
2 changes: 1 addition & 1 deletion src/OneWare.Core/Styles/ListBox.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Design.PreviewWith>
<Border Padding="10" Background="Gray">
<ListBox Height="400" Width="400">
<ListBoxItem Content="Test" />
<ListBoxItem Content="Test" IsSelected="True" />
<ListBoxItem Content="Test2" />
<ListBoxItem Content="Test3" />
</ListBox>
Expand Down
2 changes: 1 addition & 1 deletion src/OneWare.OssCadSuiteIntegration/Yosys/YosysToolchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void SaveConnections(UniversalFpgaProjectRoot project, FpgaModel fpga)

foreach (var conn in fpga.PinModels.Where(x => x.Value.Connection is not null))
{
pcf += $"\nset_io {conn.Value.Connection!.FpgaNode.Name} {conn.Value.Pin.Name}";
pcf += $"\nset_io {conn.Value.Connection!.Node.Name} {conn.Value.Pin.Name}";
}
pcf = pcf.Trim() + '\n';

Expand Down
22 changes: 19 additions & 3 deletions src/OneWare.UniversalFpgaProjectSystem/Models/FpgaModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,30 @@ public class FpgaModel : ObservableObject
public FpgaPinModel? SelectedPinModel
{
get => _selectedPinModel;
set => SetProperty(ref _selectedPinModel, value);
set
{
SetProperty(ref _selectedPinModel, value);
LastSelection = value;
}
}

private FpgaNodeModel? _selectedNodeModel;
public FpgaNodeModel? SelectedNodeModel
{
get => _selectedNodeModel;
set => SetProperty(ref _selectedNodeModel, value);
set
{
SetProperty(ref _selectedNodeModel, value);
LastSelection = value;
}
}

private object? _lastSelection;

public object? LastSelection
{
get => _lastSelection;
set => SetProperty(ref _lastSelection, value);
}

public RelayCommand ConnectCommand { get; }
Expand Down Expand Up @@ -104,7 +120,7 @@ private void SearchNodes(string? search)
return;
}

SelectedNodeModel = VisibleNodeModels.FirstOrDefault(x => x.FpgaNode.Name.Contains(search, StringComparison.OrdinalIgnoreCase));
SelectedNodeModel = VisibleNodeModels.FirstOrDefault(x => x.Node.Name.Contains(search, StringComparison.OrdinalIgnoreCase));
}

public void Connect(FpgaPinModel pin, FpgaNodeModel fpgaNode)
Expand Down
11 changes: 8 additions & 3 deletions src/OneWare.UniversalFpgaProjectSystem/Models/FpgaNodeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace OneWare.UniversalFpgaProjectSystem.Models;

public class FpgaNodeModel : ObservableObject
{
public FpgaNode FpgaNode { get; }
public FpgaNode Node { get; }

private FpgaPinModel? _connection;
public FpgaPinModel? Connection
Expand All @@ -14,8 +14,13 @@ public FpgaPinModel? Connection
set => SetProperty(ref _connection, value);
}

public FpgaNodeModel(FpgaNode fpgaNode)
public FpgaNodeModel(FpgaNode node)
{
FpgaNode = fpgaNode;
Node = node;
}

public override string ToString()
{
return Connection is null ? Node.Name : $"{Node.Name} <-> {Connection.Pin.Name}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public FpgaNodeModel? Connection
{
this.SetProperty(ref _connection, value);
if (_connection == null) ToolTipText = "Click to connect " + Pin.Name;
else ToolTipText = Pin.Name + " is connected with " + _connection.FpgaNode.Name;
else ToolTipText = Pin.Name + " is connected with " + _connection.Node.Name;
}
}

Expand All @@ -33,4 +33,9 @@ public FpgaPinModel(FpgaPin pin, FpgaModel parent)
_toolTipText = "Click to connect " + Pin.Name;
Parent = parent;
}

public override string ToString()
{
return Connection is null ? Pin.Name : $"{Pin.Name} <-> {Connection.Node.Name}";
}
}
20 changes: 20 additions & 0 deletions src/OneWare.UniversalFpgaProjectSystem/Services/FpgaService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using NodeEditor.Controls;
using OneWare.UniversalFpgaProjectSystem.Fpga;
using OneWare.UniversalFpgaProjectSystem.Models;
using Prism.Ioc;
Expand All @@ -8,6 +9,7 @@ namespace OneWare.UniversalFpgaProjectSystem.Services;
public class FpgaService
{
public Dictionary<IFpga, Type> CustomFpgaModels { get; } = new();
public Dictionary<string, Type> NodeProviders { get; } = new();
public ObservableCollection<IFpga> Fpgas { get; } = new();
public ObservableCollection<IFpgaToolchain> Toolchains { get; } = new();
public ObservableCollection<IFpgaLoader> Loaders { get; } = new();
Expand All @@ -17,6 +19,14 @@ public void RegisterFpga(IFpga fpga)
Fpgas.Add(fpga);
}

public void RegisterNodeProvider<T>(params string[] extensions) where T : INodeProvider
{
foreach (var ext in extensions)
{
NodeProviders[ext] = typeof(T);
}
}

public void RegisterCustomFpgaModel<T>(IFpga fpga) where T : FpgaModel
{
CustomFpgaModels.Add(fpga, typeof(T));
Expand All @@ -31,4 +41,14 @@ public void RegisterLoader<T>() where T : IFpgaLoader
{
Loaders.Add(ContainerLocator.Container.Resolve<T>());
}

public INodeProvider? GetNodeProvider(string extension)
{
NodeProviders.TryGetValue(extension, out var provider);
if (provider != null)
{
return ContainerLocator.Container.Resolve(provider) as INodeProvider;
}
return null;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterSingleton<UniversalFpgaProjectManager>();
containerRegistry.RegisterSingleton<FpgaService>();
containerRegistry.RegisterSingleton<NodeProviderService>();
}

public void OnInitialized(IContainerProvider containerProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using OneWare.Shared.Models;
using OneWare.Shared.Services;
using OneWare.Shared.ViewModels;
using OneWare.UniversalFpgaProjectSystem.Fpga;
using OneWare.UniversalFpgaProjectSystem.Models;
using OneWare.UniversalFpgaProjectSystem.Services;

Expand Down Expand Up @@ -57,7 +56,7 @@ public bool HideExtensions
set => SetProperty(ref _hideExtensions, value);
}

public UniversalFpgaProjectCompileViewModel(IWindowService windowService, IProjectExplorerService projectExplorerService, FpgaService fpgaService, NodeProviderService nodeProviderService, UniversalFpgaProjectRoot project)
public UniversalFpgaProjectCompileViewModel(IWindowService windowService, IProjectExplorerService projectExplorerService, FpgaService fpgaService, UniversalFpgaProjectRoot project)
{
_windowService = windowService;
_projectExplorerService = projectExplorerService;
Expand All @@ -80,7 +79,7 @@ public UniversalFpgaProjectCompileViewModel(IWindowService windowService, IProje

if (_project.TopEntity is IProjectFile file)
{
var provider = nodeProviderService.GetNodeProvider(file.Extension);
var provider = fpgaService.GetNodeProvider(file.Extension);
if (provider is not null)
{
var nodes = provider.ExtractNodes(file).ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xmlns:controls="clr-namespace:OneWare.Shared.Controls;assembly=OneWare.Shared"
xmlns:behaviours="clr-namespace:OneWare.Shared.Behaviours;assembly=OneWare.Shared"
xmlns:converters="clr-namespace:OneWare.Shared.Converters;assembly=OneWare.Shared"
xmlns:models="clr-namespace:OneWare.UniversalFpgaProjectSystem.Models"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
PrefHeight="750" PrefWidth="900" Padding="4"
WindowBackground="{DynamicResource ThemeBackgroundBrush}"
Expand Down Expand Up @@ -40,7 +41,7 @@
IsVisible="{Binding Converter={x:Static converters:SharedConverters.ViewFoundConverter}}"
Content="{Binding }" />

<Grid ColumnDefinitions="*, 70, *" RowDefinitions="20, *" DockPanel.Dock="Top">
<Grid ColumnDefinitions="*, 90, *" RowDefinitions="20, *" DockPanel.Dock="Top">

<TextBlock Grid.Row="0" Grid.Column="0" Text="Pins:"></TextBlock>
<Border Grid.Column="0" Grid.Row="1" Background="{DynamicResource ThemeControlLowBrush}"
Expand All @@ -62,8 +63,27 @@
<DataGridTextColumn Header="Pin" Width="*" Binding="{Binding Pin.Name}" />
<DataGridTextColumn Header="Description" Width="*"
Binding="{Binding Pin.Description}" />
<DataGridTextColumn Header="Node" Width="*"
Binding="{Binding Connection.FpgaNode.Name, FallbackValue={}}" />
<DataGridTemplateColumn Header="Node" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DockPanel>
<Button DockPanel.Dock="Right"
Command="{Binding $parent[DataGrid].((models:FpgaModel)DataContext).Disconnect, FallbackValue={x:Null}}"
CommandParameter="{Binding }"
IsVisible="{Binding Connection, Converter={x:Static ObjectConverters.IsNotNull}}"
Height="20" Width="20"
ToolTip.Tip="Disconnect">
<Image Source="{DynamicResource MaterialDesign.Close}" Height="10"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</Button>
<TextBlock DockPanel.Dock="Left"
VerticalAlignment="Center"
Padding="5 0" Text="{Binding Connection.Node.Name, FallbackValue={}}">
</TextBlock>
</DockPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</DockPanel>
Expand All @@ -79,6 +99,27 @@
<Image Source="{DynamicResource VSImageLib2019.Plugged_16x}" Height="25"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</Button>

<!--
<ContentControl Content="{Binding LastSelection}" HorizontalAlignment="Center">
<ContentControl.DataTemplates>
<DataTemplate DataType="models:FpgaPinModel">
<Grid ColumnDefinitions="*, 8, *">
<TextBlock HorizontalAlignment="Right" Text="{Binding Pin.Name}"/>
<TextBlock Grid.Column="1" HorizontalAlignment="Center" Text="-" IsVisible="{Binding Connection, Converter={x:Static ObjectConverters.IsNotNull}}" />
<TextBlock Grid.Column="2" HorizontalAlignment="Left" Text="{Binding Connection.Node.Name, FallbackValue={x:Null}}"></TextBlock>
</Grid>
</DataTemplate>
<DataTemplate DataType="models:FpgaNodeModel">
<Grid ColumnDefinitions="*, 8, *">
<TextBlock HorizontalAlignment="Right" Text="{Binding Connection.Pin.Name, FallbackValue={x:Null}}"></TextBlock>
<TextBlock Grid.Column="1" HorizontalAlignment="Center" Text="-" IsVisible="{Binding Connection, Converter={x:Static ObjectConverters.IsNotNull}}" />
<TextBlock Grid.Column="2" HorizontalAlignment="Left" Text="{Binding Node.Name}"/>
</Grid>
</DataTemplate>
</ContentControl.DataTemplates>
</ContentControl>
<Button Command="{Binding DisconnectCommand}" Classes="BorderButton" Height="40"
ToolTip.Tip="Disconnect" Width="40" CornerRadius="5">
<Button.RenderTransform>
Expand All @@ -87,6 +128,7 @@
<Image Source="{DynamicResource VSImageLib2019.Unplugged_16x}" Height="25"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</Button>
-->
</StackPanel>
</Border>

Expand All @@ -107,10 +149,29 @@
BorderThickness="0 1 0 0"
VerticalScrollBarVisibility="Visible">
<DataGrid.Columns>
<DataGridTextColumn Header="Node" Width="*" Binding="{Binding FpgaNode.Name}" />
<DataGridTextColumn Header="Direction" Width="*" Binding="{Binding FpgaNode.Direction}" />
<DataGridTextColumn Header="Pin" Width="*"
Binding="{Binding Connection.Pin.Name, FallbackValue={}}" />
<DataGridTextColumn Header="Node" Width="*" Binding="{Binding Node.Name}" />
<DataGridTextColumn Header="Direction" Width="*" Binding="{Binding Node.Direction}" />
<DataGridTemplateColumn Header="Pin" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DockPanel>
<Button DockPanel.Dock="Right"
Command="{Binding $parent[DataGrid].((models:FpgaModel)DataContext).Disconnect, FallbackValue={x:Null}}"
CommandParameter="{Binding Connection}"
IsVisible="{Binding Connection, Converter={x:Static ObjectConverters.IsNotNull}}"
Height="20" Width="20"
ToolTip.Tip="Disconnect">
<Image Source="{DynamicResource MaterialDesign.Close}" Height="10"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</Button>
<TextBlock DockPanel.Dock="Left"
VerticalAlignment="Center"
Padding="5 0" Text="{Binding Connection.Pin.Name, FallbackValue={}}">
</TextBlock>
</DockPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</DockPanel>
Expand Down
1 change: 1 addition & 0 deletions src/OneWare.Verilog/OneWare.Verilog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<ItemGroup>
<ProjectReference Include="..\OneWare.Shared\OneWare.Shared.csproj" Private="false" ExcludeAssets="runtime"/>
<ProjectReference Include="..\OneWare.UniversalFpgaProjectSystem\OneWare.UniversalFpgaProjectSystem.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
46 changes: 46 additions & 0 deletions src/OneWare.Verilog/Parsing/VerilogNodeProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Text.RegularExpressions;
using OneWare.Shared.Models;
using OneWare.UniversalFpgaProjectSystem.Fpga;
using OneWare.UniversalFpgaProjectSystem.Services;

namespace OneWare.Verilog.Parsing;

public class VerilogNodeProvider : INodeProvider
{
public IEnumerable<FpgaNode> ExtractNodes(IProjectFile file)
{
string fileContent = File.ReadAllText(file.FullPath);

// Regex, um die Modul-Deklaration zu finden und die Ports zu extrahieren
string modulePattern = @"module\s+\w+\s*\((.*?)\);";
Match moduleMatch = Regex.Match(fileContent, modulePattern, RegexOptions.Singleline);

if (moduleMatch.Success)
{
// Extrahieren der Ports innerhalb des Moduls
string portSection = moduleMatch.Groups[1].Value;
return ExtractAndPrintPorts(portSection);
}
return new List<FpgaNode>();
}

private static IEnumerable<FpgaNode> ExtractAndPrintPorts(string portSection)
{
// Regex, um einzelne Port-Deklarationen zu identifizieren
string portPattern = @"(input|output|inout)(\s*\[\d+:\d+\])?\s+([^;,]+)";
MatchCollection portMatches = Regex.Matches(portSection, portPattern, RegexOptions.Singleline);

foreach (Match match in portMatches)
{
string portType = match.Groups[1].Value;
string vectorSize = match.Groups[2].Value.Trim();
string[] portNames = match.Groups[3].Value.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);

foreach (string portName in portNames)
{
Console.WriteLine($"Port: {portName}, Type: {portType}, Vector Size: {vectorSize}");
yield return new FpgaNode(portName, portType);
}
}
}
}
Loading

0 comments on commit 8561341

Please sign in to comment.