mirror of
https://github.com/fadden/6502bench.git
synced 2025-03-13 20:30:07 +00:00
First cut at label file generation
Some debuggers allow you to import a list of labels for addresses. This adds a command that generates a file full of labels in a specific format. Currently the VICE monitor format is supported. (issue #151)
This commit is contained in:
parent
da91d9fc0e
commit
e425237783
@ -127,6 +127,10 @@ namespace SourceGen {
|
||||
public const string SRCGEN_LONG_LABEL_NEW_LINE = "srcgen-long-label-new-line";
|
||||
public const string SRCGEN_SHOW_CYCLE_COUNTS = "srcgen-show-cycle-counts";
|
||||
|
||||
// Label file generation settings.
|
||||
public const string LABGEN_FORMAT = "labgen-format";
|
||||
public const string LABGEN_INCLUDE_AUTO = "labgen-include-auto";
|
||||
|
||||
// Assembler settings prefix
|
||||
public const string ASM_CONFIG_PREFIX = "asm-config-";
|
||||
|
||||
|
77
SourceGen/LabelFileGenerator.cs
Normal file
77
SourceGen/LabelFileGenerator.cs
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2019 faddenSoft
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace SourceGen {
|
||||
/// <summary>
|
||||
/// Label file generator.
|
||||
/// </summary>
|
||||
public class LabelFileGenerator {
|
||||
public enum LabelFmt {
|
||||
Unknown = 0,
|
||||
VICE,
|
||||
}
|
||||
|
||||
private DisasmProject mProject;
|
||||
private LabelFmt mFormat;
|
||||
private bool mIncludeAutoLabels;
|
||||
|
||||
public LabelFileGenerator(DisasmProject project, LabelFmt format, bool includeAutoLabels) {
|
||||
mProject = project;
|
||||
mFormat = format;
|
||||
mIncludeAutoLabels = includeAutoLabels;
|
||||
}
|
||||
|
||||
public void Generate(StreamWriter outStream) {
|
||||
List<Symbol> symList = new List<Symbol>();
|
||||
|
||||
foreach (Symbol sym in mProject.SymbolTable) {
|
||||
bool include;
|
||||
switch (sym.SymbolSource) {
|
||||
case Symbol.Source.User:
|
||||
case Symbol.Source.AddrPreLabel:
|
||||
include = true;
|
||||
break;
|
||||
case Symbol.Source.Auto:
|
||||
include = mIncludeAutoLabels;
|
||||
break;
|
||||
case Symbol.Source.Project:
|
||||
case Symbol.Source.Platform:
|
||||
case Symbol.Source.Variable:
|
||||
default:
|
||||
include = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (include) {
|
||||
symList.Add(sym);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort alphabetically. Not necessary, but it could make a "diff" easier to read.
|
||||
symList.Sort((a, b) => Symbol.Compare(Symbol.SymbolSortField.Name, true, a, b));
|
||||
|
||||
// VICE format is "add_label <address> <label>", but may be abbreviated "al".
|
||||
// We could also use ACME format ("labelname = $1234 ; Maybe a comment").
|
||||
foreach (Symbol sym in symList) {
|
||||
outStream.WriteLine("al " + sym.Value.ToString("x6") + " " + sym.Label);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2557,6 +2557,47 @@ namespace SourceGen {
|
||||
}
|
||||
}
|
||||
|
||||
public void GenerateLabels() {
|
||||
GenerateLabels dlg = new GenerateLabels(mMainWin);
|
||||
if (dlg.ShowDialog() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
string ext;
|
||||
string filter;
|
||||
switch (dlg.Format) {
|
||||
case LabelFileGenerator.LabelFmt.VICE:
|
||||
ext = ".vs";
|
||||
filter = "VICE commands (*.vs)|*.vs";
|
||||
break;
|
||||
default:
|
||||
Debug.Assert(false, "bad format");
|
||||
return;
|
||||
}
|
||||
|
||||
SaveFileDialog fileDlg = new SaveFileDialog() {
|
||||
Filter = filter,
|
||||
FilterIndex = 1,
|
||||
ValidateNames = true,
|
||||
AddExtension = true, // doesn't add extension if non-ext file exists
|
||||
FileName = "labels" + ext
|
||||
};
|
||||
if (fileDlg.ShowDialog() != true) {
|
||||
return;
|
||||
}
|
||||
string pathName = Path.GetFullPath(fileDlg.FileName);
|
||||
try {
|
||||
using (StreamWriter writer = new StreamWriter(pathName, false)) {
|
||||
LabelFileGenerator gen = new LabelFileGenerator(mProject,
|
||||
dlg.Format, dlg.IncludeAutoLabels);
|
||||
gen.Generate(writer);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
MessageBox.Show("Error: " + ex.Message, "Failed", MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public void Find() {
|
||||
FindBox dlg = new FindBox(mMainWin, mFindString);
|
||||
if (dlg.ShowDialog() == true) {
|
||||
|
@ -79,6 +79,7 @@
|
||||
<Compile Include="DailyTips.cs" />
|
||||
<Compile Include="Exporter.cs" />
|
||||
<Compile Include="FormattedOperandCache.cs" />
|
||||
<Compile Include="LabelFileGenerator.cs" />
|
||||
<Compile Include="LocalVariableLookup.cs" />
|
||||
<Compile Include="MessageList.cs" />
|
||||
<Compile Include="Sgec.cs" />
|
||||
@ -188,6 +189,9 @@
|
||||
<Compile Include="WpfGui\FormatAddressTable.xaml.cs">
|
||||
<DependentUpon>FormatAddressTable.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="WpfGui\GenerateLabels.xaml.cs">
|
||||
<DependentUpon>GenerateLabels.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="WpfGui\GotoBox.xaml.cs">
|
||||
<DependentUpon>GotoBox.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@ -413,6 +417,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="WpfGui\GenerateLabels.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="WpfGui\GotoBox.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
@ -495,4 +503,4 @@
|
||||
<Resource Include="Res\RedX.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
</Project>
|
@ -20,9 +20,9 @@ using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Microsoft.Win32;
|
||||
|
||||
using CommonUtil;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace SourceGen.WpfGui {
|
||||
/// <summary>
|
||||
|
52
SourceGen/WpfGui/GenerateLabels.xaml
Normal file
52
SourceGen/WpfGui/GenerateLabels.xaml
Normal file
@ -0,0 +1,52 @@
|
||||
<!--
|
||||
Copyright 2024 faddenSoft
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<Window x:Class="SourceGen.WpfGui.GenerateLabels"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:SourceGen.WpfGui"
|
||||
mc:Ignorable="d"
|
||||
Title="Generate Label File"
|
||||
SizeToContent="WidthAndHeight" ResizeMode="NoResize"
|
||||
ShowInTaskbar="False" WindowStartupLocation="CenterOwner">
|
||||
|
||||
<Grid Margin="8">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<GroupBox Grid.Row="0" Header="Output Format" Padding="2,4">
|
||||
<StackPanel>
|
||||
<RadioButton Content="VICE label commands"
|
||||
ToolTip="Load in VICE monitor with 'll' command."
|
||||
IsChecked="{Binding Format_VICE}"/>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<CheckBox Grid.Row="1" Margin="0,4,0,0" Content="Include auto-generated labels"
|
||||
IsChecked="{Binding IncludeAutoLabels}"/>
|
||||
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal"
|
||||
HorizontalAlignment="Right" Margin="0,8,0,0">
|
||||
<Button Content="Generate" IsDefault="True" Width="70" Click="OkButton_Click"/>
|
||||
<Button Content="Cancel" IsCancel="True" Width="70" Margin="4,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
73
SourceGen/WpfGui/GenerateLabels.xaml.cs
Normal file
73
SourceGen/WpfGui/GenerateLabels.xaml.cs
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2019 faddenSoft
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGen.WpfGui {
|
||||
/// <summary>
|
||||
/// Select parameters for label file generation.
|
||||
/// </summary>
|
||||
public partial class GenerateLabels : Window, INotifyPropertyChanged {
|
||||
// INotifyPropertyChanged implementation
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
private void OnPropertyChanged([CallerMemberName] string propertyName = "") {
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public bool IncludeAutoLabels {
|
||||
get { return mIncludeAutoLabels; }
|
||||
set { mIncludeAutoLabels = value; OnPropertyChanged(); }
|
||||
}
|
||||
private bool mIncludeAutoLabels;
|
||||
|
||||
public LabelFileGenerator.LabelFmt Format { get; private set; }
|
||||
|
||||
public bool Format_VICE {
|
||||
get { return Format == LabelFileGenerator.LabelFmt.VICE;}
|
||||
set { Format = LabelFileGenerator.LabelFmt.VICE; UpdateFormats(); }
|
||||
}
|
||||
|
||||
private void UpdateFormats() {
|
||||
OnPropertyChanged(nameof(Format_VICE));
|
||||
}
|
||||
|
||||
|
||||
public GenerateLabels(Window owner) {
|
||||
InitializeComponent();
|
||||
Owner = owner;
|
||||
DataContext = this;
|
||||
|
||||
Format =
|
||||
(LabelFileGenerator.LabelFmt)AppSettings.Global.GetEnum(AppSettings.LABGEN_FORMAT,
|
||||
typeof(LabelFileGenerator.LabelFmt), (int)LabelFileGenerator.LabelFmt.VICE);
|
||||
UpdateFormats();
|
||||
mIncludeAutoLabels = AppSettings.Global.GetBool(AppSettings.LABGEN_INCLUDE_AUTO, false);
|
||||
}
|
||||
|
||||
private void OkButton_Click(object sender, RoutedEventArgs e) {
|
||||
// Save settings.
|
||||
AppSettings.Global.SetEnum(AppSettings.LABGEN_FORMAT,
|
||||
typeof(LabelFileGenerator.LabelFmt), (int)Format);
|
||||
AppSettings.Global.SetBool(AppSettings.LABGEN_INCLUDE_AUTO, mIncludeAutoLabels);
|
||||
DialogResult = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -136,6 +136,7 @@ limitations under the License.
|
||||
</RoutedUICommand.InputGestures>
|
||||
</RoutedUICommand>
|
||||
<RoutedUICommand x:Key="FormatAddressTableCmd" Text="Format Address Table..."/>
|
||||
<RoutedUICommand x:Key="GenerateLabelsCmd" Text="Generate Label File..."/>
|
||||
<RoutedUICommand x:Key="GotoCmd" Text="Go To...">
|
||||
<RoutedUICommand.InputGestures>
|
||||
<KeyGesture>Ctrl+G</KeyGesture>
|
||||
@ -284,6 +285,8 @@ limitations under the License.
|
||||
CanExecute="CanFormatAsWord" Executed="FormatAsWordCmd_Executed"/>
|
||||
<CommandBinding Command="{StaticResource FormatAddressTableCmd}"
|
||||
CanExecute="CanFormatAddressTable" Executed="FormatAddressTableCmd_Executed"/>
|
||||
<CommandBinding Command="{StaticResource GenerateLabelsCmd}"
|
||||
CanExecute="IsProjectOpen" Executed="GenerateLabelsCmd_Executed"/>
|
||||
<CommandBinding Command="{StaticResource GotoCmd}"
|
||||
CanExecute="IsProjectOpen" Executed="GotoCmd_Executed"/>
|
||||
<CommandBinding Command="{StaticResource GotoLastChangeCmd}"
|
||||
@ -392,8 +395,8 @@ limitations under the License.
|
||||
</MenuItem>
|
||||
<Separator/>
|
||||
<MenuItem Command="{StaticResource AssembleCmd}"/>
|
||||
<!--<MenuItem Command="Print"/>-->
|
||||
<MenuItem Command="{StaticResource ExportCmd}"/>
|
||||
<MenuItem Command="{StaticResource GenerateLabelsCmd}"/>
|
||||
<Separator/>
|
||||
<MenuItem Command="{StaticResource ReloadExternalFilesCmd}"/>
|
||||
<Separator/>
|
||||
|
@ -1332,6 +1332,10 @@ namespace SourceGen.WpfGui {
|
||||
mMainCtrl.FormatAddressTable();
|
||||
}
|
||||
|
||||
private void GenerateLabelsCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
|
||||
mMainCtrl.GenerateLabels();
|
||||
}
|
||||
|
||||
private void GotoCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
|
||||
mMainCtrl.Goto();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user