From 6df29e562f4ee5867010843a973fe8b73cf6b49f Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Mon, 11 Oct 2021 14:44:44 -0700 Subject: [PATCH] Various tweaks Changed the code that generates cross-references for pre-labels to ignore labels in regions with non-addressable parents. Also, changed the code that complains about references to labels in non-addressable areas to ignore pre-labels, because it was complaining about references to pre-labels on region starts that were followed by a non-addressable region start. In the address region edit dialog, split up the descriptive text for the "resize" option to make it easier to see the new end offset and length. It doesn't look quite right because it's not using the mono font like the text near the top, but it'll do. When multiple lines are selected, the Info window now shows the first line/offset, last line/offset, and bytes spanned by the selection. This is helpful if you're trying to figure out how big something is. --- SourceGen/DisasmProject.cs | 42 ++++++++++++++++---------- SourceGen/MainController.cs | 49 +++++++++++++++++++++++++++---- SourceGen/Res/Strings.xaml | 4 +++ SourceGen/Res/Strings.xaml.cs | 8 +++++ SourceGen/WpfGui/EditAddress.xaml | 6 ++-- 5 files changed, 85 insertions(+), 24 deletions(-) diff --git a/SourceGen/DisasmProject.cs b/SourceGen/DisasmProject.cs index cdec73b..9bb5c8f 100644 --- a/SourceGen/DisasmProject.cs +++ b/SourceGen/DisasmProject.cs @@ -1573,18 +1573,23 @@ namespace SourceGen { } } } - // Add all address region pre-labels, regardless of whether or not their parent - // is non-addressable. Duplicates of user labels will be rejected. Note the - // references will appear on the line for the next file offset, not the pre-label - // itself, because we need to associated it with a file offset. - foreach (AddressMap.AddressMapEntry ent in AddrMap) { - if (!string.IsNullOrEmpty(ent.PreLabel)) { + // Add all valid address region pre-labels. Duplicates of user labels will be + // rejected. Note the references will appear on the line for the next file offset, + // not the pre-label itself, because we need to associate it with a file offset. + IEnumerator addrIter = AddrMap.AddressChangeIterator; + while (addrIter.MoveNext()) { + AddressMap.AddressChange change = addrIter.Current; + if (!change.IsStart) { + continue; + } + if (change.Region.HasValidPreLabel) { try { - labelList.Add(ent.PreLabel, ent.Offset); + labelList.Add(change.Region.PreLabel, change.Region.Offset); } catch (ArgumentException ex) { - Debug.WriteLine("Xref ignoring pre-label duplicate '" + ent.PreLabel + - "': " + ex.Message); + Debug.WriteLine("Xref ignoring pre-label duplicate '" + + change.Region.PreLabel + "': " + ex.Message); } + } } @@ -1635,13 +1640,20 @@ namespace SourceGen { // Is this a reference to a label? if (labelList.TryGetValue(dfd.SymbolRef.Label, out int symOffset)) { + // Post a warning if the reference is to a non-addressable offset, + // unless the label in question is a pre-label. We need to ignore + // those because it's valid to have a pre-label on an addressable + // region that shares a start point with a non-addressable child. if (mAnattribs[symOffset].IsNonAddressable) { - Messages.Add(new MessageList.MessageEntry( - MessageList.MessageEntry.SeverityLevel.Warning, - offset, - MessageList.MessageEntry.MessageType.NonAddrLabelRef, - dfd.SymbolRef.Label, - MessageList.MessageEntry.ProblemResolution.None)); + if (mAnattribs[symOffset].Symbol != null && + mAnattribs[symOffset].Symbol.Label == dfd.SymbolRef.Label) { + Messages.Add(new MessageList.MessageEntry( + MessageList.MessageEntry.SeverityLevel.Warning, + offset, + MessageList.MessageEntry.MessageType.NonAddrLabelRef, + dfd.SymbolRef.Label, + MessageList.MessageEntry.ProblemResolution.None)); + } } // Compute adjustment. diff --git a/SourceGen/MainController.cs b/SourceGen/MainController.cs index 34f21d9..1643392 100644 --- a/SourceGen/MainController.cs +++ b/SourceGen/MainController.cs @@ -1603,9 +1603,9 @@ namespace SourceGen { break; case CodeListColumn.Opcode: if (IsPlbInstruction(line) && CanEditDataBank()) { - // Special handling for PLB instruction, so you can update the bank - // value just be double-clicking on it. Only used for PLBs without - // user- or auto-assigned bank changes. + // Special handling for PLB instruction, so you can update the bank + // value just by double-clicking on it. Only used for PLBs without + // user- or auto-assigned bank changes. EditDataBank(); } else { JumpToOperandTarget(line, false); @@ -3178,6 +3178,10 @@ namespace SourceGen { mLineType = LineListGen.Line.Type.Unclassified; mEntityCounts = new EntityCounts(); } + + public override string ToString() { + return "SelState: numSel=" + mNumItemsSelected + " type=" + mLineType; + } } /// @@ -3946,10 +3950,45 @@ namespace SourceGen { const string CRLF = "\r\n"; mMainWin.ClearInfoPanel(); - if (mMainWin.CodeListView_GetSelectionCount() != 1) { - // Nothing selected, or multiple lines selected. + int selCount = mMainWin.CodeListView_GetSelectionCount(); + if (selCount < 1) { + // Nothing selected. + return; + } else if (selCount > 1) { + // Multiple lines selected. + mMainWin.InfoLineDescrText = string.Format(Res.Strings.INFO_MULTI_LINE_SUM_FMT, + selCount); + + int firstIndex = mMainWin.CodeListView_GetFirstSelectedIndex(); + int lastIndex = mMainWin.CodeListView_GetLastSelectedIndex(); + int firstOffset = CodeLineList[firstIndex].FileOffset; + int nextOffset = CodeLineList[lastIndex].FileOffset + + CodeLineList[lastIndex].OffsetSpan; + if (firstOffset == nextOffset) { + return; // probably selected a bunch of lines from a long comment or note + } + if (firstOffset < 0 || nextOffset < 0) { + // We're in the header comment or .equ area. + return; + } + if (CodeLineList[lastIndex].LineType == LineListGen.Line.Type.ArEndDirective) { + nextOffset++; + } + + StringBuilder msb = new StringBuilder(); + msb.AppendFormat(Res.Strings.INFO_MULTI_LINE_START_FMT, firstIndex, + mFormatter.FormatOffset24(firstOffset)); + msb.Append(CRLF); + msb.AppendFormat(Res.Strings.INFO_MULTI_LINE_END_FMT, lastIndex, + mFormatter.FormatOffset24(nextOffset - 1)); + msb.Append(CRLF); + int len = nextOffset - firstOffset; + string lenStr = len.ToString() + " (" + mFormatter.FormatHexValue(len, 2) + ")"; + msb.AppendFormat(Res.Strings.INFO_MULTI_LINE_LEN_FMT, lenStr); + mMainWin.InfoPanelDetail1 = msb.ToString(); return; } + int lineIndex = mMainWin.CodeListView_GetFirstSelectedIndex(); LineListGen.Line line = CodeLineList[lineIndex]; diff --git a/SourceGen/Res/Strings.xaml b/SourceGen/Res/Strings.xaml index 7d2e1a2..32e2092 100644 --- a/SourceGen/Res/Strings.xaml +++ b/SourceGen/Res/Strings.xaml @@ -113,6 +113,10 @@ limitations under the License. Line {0}: {1} Line {0}: {1} bytes of {2} Line {0}: {1} byte of {2} + {0} lines selected + First: line {0} offset {1} + Last: line {0} offset {1} + Selection spans {0} bytes Extension scripts: Default settings: Symbol files: diff --git a/SourceGen/Res/Strings.xaml.cs b/SourceGen/Res/Strings.xaml.cs index acdcaf8..d0f9579 100644 --- a/SourceGen/Res/Strings.xaml.cs +++ b/SourceGen/Res/Strings.xaml.cs @@ -207,6 +207,14 @@ namespace SourceGen.Res { (string)Application.Current.FindResource("str_InfoLineSumPluralFmt"); public static string INFO_LINE_SUM_SINGULAR_FMT = (string)Application.Current.FindResource("str_InfoLineSumSingularFmt"); + public static string INFO_MULTI_LINE_SUM_FMT = + (string)Application.Current.FindResource("str_InfoMultiLineSumFmt"); + public static string INFO_MULTI_LINE_START_FMT = + (string)Application.Current.FindResource("str_InfoMultiLineStartFmt"); + public static string INFO_MULTI_LINE_END_FMT = + (string)Application.Current.FindResource("str_InfoMultiLineEndFmt"); + public static string INFO_MULTI_LINE_LEN_FMT = + (string)Application.Current.FindResource("str_InfoMultiLineLenFmt"); public static string INITIAL_EXTENSION_SCRIPTS = (string)Application.Current.FindResource("str_InitialExtensionScripts"); public static string INITIAL_PARAMETERS = diff --git a/SourceGen/WpfGui/EditAddress.xaml b/SourceGen/WpfGui/EditAddress.xaml index 4c5214e..66b07b9 100644 --- a/SourceGen/WpfGui/EditAddress.xaml +++ b/SourceGen/WpfGui/EditAddress.xaml @@ -48,10 +48,8 @@ limitations under the License. Resize. - - Edit the region's attributes, and resize it to the selection. The new - end offset will be {0}, for a length of {1}. - + Edit the region's attributes, and resize it to the selection. The new end offset will be: End: {0} Length: {1} Resize not available: cannot resize to the selection. {0}