From e425237783939e2dbefd72541e83604a5d48f915 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Sat, 20 Apr 2024 15:36:15 -0700 Subject: [PATCH] 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) --- SourceGen/AppSettings.cs | 4 ++ SourceGen/LabelFileGenerator.cs | 77 +++++++++++++++++++++++++ SourceGen/MainController.cs | 41 +++++++++++++ SourceGen/SourceGen.csproj | 10 +++- SourceGen/WpfGui/Export.xaml.cs | 2 +- SourceGen/WpfGui/GenerateLabels.xaml | 52 +++++++++++++++++ SourceGen/WpfGui/GenerateLabels.xaml.cs | 73 +++++++++++++++++++++++ SourceGen/WpfGui/MainWindow.xaml | 5 +- SourceGen/WpfGui/MainWindow.xaml.cs | 4 ++ 9 files changed, 265 insertions(+), 3 deletions(-) create mode 100644 SourceGen/LabelFileGenerator.cs create mode 100644 SourceGen/WpfGui/GenerateLabels.xaml create mode 100644 SourceGen/WpfGui/GenerateLabels.xaml.cs diff --git a/SourceGen/AppSettings.cs b/SourceGen/AppSettings.cs index 6daf125..e700d0e 100644 --- a/SourceGen/AppSettings.cs +++ b/SourceGen/AppSettings.cs @@ -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-"; diff --git a/SourceGen/LabelFileGenerator.cs b/SourceGen/LabelFileGenerator.cs new file mode 100644 index 0000000..7bfdfec --- /dev/null +++ b/SourceGen/LabelFileGenerator.cs @@ -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 { + /// + /// Label file generator. + /// + 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 symList = new List(); + + 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