From 422af1193cd468c8dcccf424bd1a121902e88fa7 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Sat, 4 Jan 2020 15:11:59 -0800 Subject: [PATCH] Tweak def symbol sort order The list of EQUs at the top of the file is sorted, by type, then value, then name. This adds width as an additional check, so that if you have overlapping items the widest comes first. This is nice when you have a general entry for a block of data, and then specific entries for some locations within the block. --- SourceGen/DisasmProject.cs | 18 +++++++++++++++++- .../Expected/2021-external-symbols_64tass.S | 2 +- .../Expected/2021-external-symbols_Merlin32.S | 2 +- .../Expected/2021-external-symbols_acme.S | 2 +- .../Expected/2021-external-symbols_cc65.S | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/SourceGen/DisasmProject.cs b/SourceGen/DisasmProject.cs index ef43cf2..38ddc14 100644 --- a/SourceGen/DisasmProject.cs +++ b/SourceGen/DisasmProject.cs @@ -1673,7 +1673,7 @@ namespace SourceGen { // Sort order: // - constants appear before addresses - // - ascending numeric value + // - ascending numeric value, wider items first // - ascending label ActiveDefSymbolList.Sort(delegate (DefSymbol a, DefSymbol b) { // Put constants first. @@ -1687,11 +1687,27 @@ namespace SourceGen { return -1; } else if (a.Value > b.Value) { return 1; + } else if (IsWider(a, b)) { + return -1; + } else if (IsWider(b, a)) { + return 1; } return Asm65.Label.LABEL_COMPARER.Compare(a.Label, b.Label); }); } + private bool IsWider(DefSymbol a, DefSymbol b) { + if (!a.HasWidth && !b.HasWidth) { + return false; + } else if (a.HasWidth && !b.HasWidth) { + return true; + } else if (!a.HasWidth && !b.HasWidth) { + return true; + } else { + return a.DataDescriptor.Length > b.DataDescriptor.Length; + } + } + #endregion Analysis diff --git a/SourceGen/SGTestData/Expected/2021-external-symbols_64tass.S b/SourceGen/SGTestData/Expected/2021-external-symbols_64tass.S index 5aab27b..7a8d89f 100644 --- a/SourceGen/SGTestData/Expected/2021-external-symbols_64tass.S +++ b/SourceGen/SGTestData/Expected/2021-external-symbols_64tass.S @@ -15,8 +15,8 @@ ChkProj2 = $2204 ProjSym2 = $220a Over1 = $3000 ;$3000-300f, inclusive Over2 = $3002 ;$3002-3009 -Over2a = $3006 ;$3006 Over3 = $3006 ;$3006-300c +Over2a = $3006 ;$3006 SepOver1 = $3100 ;$3100-3103, inclusive SepOver2 = $3102 ;$3102-3105, inclusive ReadOnly = $5000 ;R diff --git a/SourceGen/SGTestData/Expected/2021-external-symbols_Merlin32.S b/SourceGen/SGTestData/Expected/2021-external-symbols_Merlin32.S index 7db01be..88f4252 100644 --- a/SourceGen/SGTestData/Expected/2021-external-symbols_Merlin32.S +++ b/SourceGen/SGTestData/Expected/2021-external-symbols_Merlin32.S @@ -14,8 +14,8 @@ ChkProj2 equ $2204 ProjSym2 equ $220a Over1 equ $3000 ;$3000-300f, inclusive Over2 equ $3002 ;$3002-3009 -Over2a equ $3006 ;$3006 Over3 equ $3006 ;$3006-300c +Over2a equ $3006 ;$3006 SepOver1 equ $3100 ;$3100-3103, inclusive SepOver2 equ $3102 ;$3102-3105, inclusive ReadOnly equ $5000 ;R diff --git a/SourceGen/SGTestData/Expected/2021-external-symbols_acme.S b/SourceGen/SGTestData/Expected/2021-external-symbols_acme.S index f680f93..2439019 100644 --- a/SourceGen/SGTestData/Expected/2021-external-symbols_acme.S +++ b/SourceGen/SGTestData/Expected/2021-external-symbols_acme.S @@ -15,8 +15,8 @@ ChkProj2 = $2204 ProjSym2 = $220a Over1 = $3000 ;$3000-300f, inclusive Over2 = $3002 ;$3002-3009 -Over2a = $3006 ;$3006 Over3 = $3006 ;$3006-300c +Over2a = $3006 ;$3006 SepOver1 = $3100 ;$3100-3103, inclusive SepOver2 = $3102 ;$3102-3105, inclusive ReadOnly = $5000 ;R diff --git a/SourceGen/SGTestData/Expected/2021-external-symbols_cc65.S b/SourceGen/SGTestData/Expected/2021-external-symbols_cc65.S index 11a8bb4..b3f3a22 100644 --- a/SourceGen/SGTestData/Expected/2021-external-symbols_cc65.S +++ b/SourceGen/SGTestData/Expected/2021-external-symbols_cc65.S @@ -15,8 +15,8 @@ ChkProj2 = $2204 ProjSym2 = $220a Over1 = $3000 ;$3000-300f, inclusive Over2 = $3002 ;$3002-3009 -Over2a = $3006 ;$3006 Over3 = $3006 ;$3006-300c +Over2a = $3006 ;$3006 SepOver1 = $3100 ;$3100-3103, inclusive SepOver2 = $3102 ;$3102-3105, inclusive ReadOnly = $5000 ;R