From 9e4949ab217629006850b922cfb6487556408a7e Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Thu, 29 Aug 2019 15:20:38 -0700 Subject: [PATCH] Tweak var table sort order Still primarily ascending numeric order, but now we use the symbol type as the secondary sort instead of the label. Also, fix References crash on first line of empty var table. --- SourceGen/LineListGen.cs | 9 ++++++--- SourceGen/LocalVariableTable.cs | 13 ++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/SourceGen/LineListGen.cs b/SourceGen/LineListGen.cs index 483009e..9cae379 100644 --- a/SourceGen/LineListGen.cs +++ b/SourceGen/LineListGen.cs @@ -1345,9 +1345,12 @@ namespace SourceGen { } int tableIndex = line.SubLineIndex; if (lvt.ClearPrevious) { - if (--tableIndex < 0) { - return null; - } + tableIndex--; + } + if (tableIndex < 0 || tableIndex >= lvt.Count) { + // Will be -1 on first line when ClearPrevious was set. Will be zero on + // first line of empty table. + return null; } return lvt[tableIndex]; diff --git a/SourceGen/LocalVariableTable.cs b/SourceGen/LocalVariableTable.cs index 1bef4c6..2a98cc4 100644 --- a/SourceGen/LocalVariableTable.cs +++ b/SourceGen/LocalVariableTable.cs @@ -112,15 +112,22 @@ namespace SourceGen { private void SortIfNeeded() { if (mNeedSort) { - // Currently sorting primarily by value, secondarily by label. This ordering - // determines how it appears in the code list. If we want to make it + // Currently sorting primarily by value, secondarily by symbol type. This + // ordering determines how it appears in the code list. If we want to make it // configurable we just need to replace the sort function. mVarByValue.Sort((a, b) => { + // Numeric ascending. int diff = a.Value - b.Value; if (diff != 0) { return diff; } - return a.Label.CompareTo(b.Label); + // DP addr first, StackRel const second + if (a.SymbolType == Symbol.Type.ExternalAddr) { + return -1; + } else { + return 1; + } + //return a.Label.CompareTo(b.Label); }); mNeedSort = false; }