1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-06-25 05:29:31 +00:00

Change some EQU handling

Changed the sort order on EQU lines so that constants come before
address definitions.  This caused trivial changes to three of the
regression tests.

Added the ability to jump directly to an EQU line when an opcode
is double-clicked on.
This commit is contained in:
Andy McFadden 2019-10-10 13:49:21 -07:00
parent 475c31b886
commit 6d886ecc3a
14 changed files with 96 additions and 64 deletions

View File

@ -1479,7 +1479,8 @@ namespace SourceGen {
/// Generates the list of project/platform symbols that are being used. Any
/// DefSymbol with a non-empty Xrefs is included. Previous contents are cleared.
///
/// The list is sorted primarily by value, secondarily by symbol name.
/// The list is sorted primarily by value, secondarily by symbol name, with constants
/// appearing before addresses.
///
/// Call this after Xrefs are generated.
/// </summary>
@ -1497,12 +1498,18 @@ namespace SourceGen {
ActiveDefSymbolList.Add(defSym);
}
// We could make symbol source the primary sort key, so that all platform
// symbols appear before all project symbols. Not sure if that's better.
//
// Could also skip this by replacing the earlier foreach with a walk through
// SymbolTable.mSymbolsByValue, but I'm not sure that should be exposed.
// Sort order:
// - constants appear before addresses
// - ascending numeric value
// - ascending label
ActiveDefSymbolList.Sort(delegate (DefSymbol a, DefSymbol b) {
// Put constants first.
int ca = (a.SymbolType == Symbol.Type.Constant) ? 1 : 0;
int cb = (b.SymbolType == Symbol.Type.Constant) ? 1 : 0;
if (ca != cb) {
return cb - ca;
}
if (a.Value < b.Value) {
return -1;
} else if (a.Value > b.Value) {

View File

@ -772,12 +772,13 @@ namespace SourceGen {
}
/// <summary>
/// Generates a synthetic offset for the FileOffset field from an index value. The
/// index arg is the index of an entry in the DisasmProject.ActiveDefSymbolList.
/// Generates a synthetic offset for the FileOffset field from an index value.
/// (The exact algorithm isn't too important, as these offsets are not stored in the
/// project file.)
/// </summary>
private static int DefSymOffsetFromIndex(int index) {
/// <param name="index">Index into DisasmProject.ActiveDefSymbolListlist.</param>
/// <returns>Synthetic file offset. Value will be < 0.</returns>
public static int DefSymOffsetFromIndex(int index) {
Debug.Assert(index >= 0 && index < (1 << 24));
return index - (1 << 24);
}
@ -786,6 +787,8 @@ namespace SourceGen {
/// Returns the DisasmProject.ActiveDefSymbolList index for an EQU line with
/// the specified file offset.
/// </summary>
/// <param name="offset">Synthetic file offset, from DefSymOffsetFromIndex().</param>
/// <returns>Index into DisasmProject.ActiveDefSymbolListlist.</returns>
public static int DefSymIndexFromOffset(int offset) {
Debug.Assert(offset < 0);
return offset + (1 << 24);

View File

@ -1449,45 +1449,7 @@ namespace SourceGen {
}
break;
case CodeListColumn.Opcode:
// File offset should always be valid, since we excluded the EQU
// statements and header comment earlier.
if (line.FileOffset >= 0) {
Anattrib attr = mProject.GetAnattrib(line.FileOffset);
FormatDescriptor dfd = attr.DataDescriptor;
// Does this have an operand with an in-file target offset?
// (Resolve it as a numeric reference.)
if (attr.OperandOffset >= 0) {
// Yup, find the line for that offset and jump to it.
GoToLocation(
new NavStack.Location(attr.OperandOffset, 0, false),
GoToMode.JumpToCodeData, true);
} else if (dfd != null && dfd.HasSymbol) {
// Operand has a symbol, do a symbol lookup.
if (dfd.SymbolRef.IsVariable) {
GoToVarDefinition(line.FileOffset, dfd.SymbolRef, true);
} else {
int labelOffset = mProject.FindLabelOffsetByName(
dfd.SymbolRef.Label);
if (labelOffset >= 0) {
GoToLocation(
new NavStack.Location(labelOffset, 0, false),
GoToMode.JumpToCodeData, true);
}
}
} else if (attr.IsDataStart || attr.IsInlineDataStart) {
// If it's an Address or Symbol, we can try to resolve
// the value. (Symbols should have been resolved by the
// previous clause, but Address entries would not have been.)
int operandOffset = DataAnalysis.GetDataOperandOffset(
mProject, line.FileOffset);
if (operandOffset >= 0) {
GoToLocation(
new NavStack.Location(operandOffset, 0, false),
GoToMode.JumpToCodeData, true);
}
}
}
HandleDoubleClickOnOpcode(line);
break;
case CodeListColumn.Operand:
if (CanEditOperand()) {
@ -1509,6 +1471,66 @@ namespace SourceGen {
}
}
private void HandleDoubleClickOnOpcode(LineListGen.Line line) {
if (line.FileOffset < 0) {
// Double-click on project symbol EQUs and the file header comment are handled
// elsewhere.
return;
}
Anattrib attr = mProject.GetAnattrib(line.FileOffset);
FormatDescriptor dfd = attr.DataDescriptor;
// Does this have an operand with an in-file target offset?
// (Resolve it as a numeric reference.)
if (attr.OperandOffset >= 0) {
// Yup, find the line for that offset and jump to it.
GoToLocation(new NavStack.Location(attr.OperandOffset, 0, false),
GoToMode.JumpToCodeData, true);
} else if (dfd != null && dfd.HasSymbol) {
// Operand has a symbol, do a symbol lookup.
if (dfd.SymbolRef.IsVariable) {
GoToVarDefinition(line.FileOffset, dfd.SymbolRef, true);
} else {
if (mProject.SymbolTable.TryGetValue(dfd.SymbolRef.Label, out Symbol sym)) {
if (sym.SymbolSource == Symbol.Source.User ||
sym.SymbolSource == Symbol.Source.Auto) {
int labelOffset = mProject.FindLabelOffsetByName(dfd.SymbolRef.Label);
if (labelOffset >= 0) {
GoToLocation(new NavStack.Location(labelOffset, 0, false),
GoToMode.JumpToCodeData, true);
}
} else if (sym.SymbolSource == Symbol.Source.Platform ||
sym.SymbolSource == Symbol.Source.Project) {
// find entry
for (int i = 0; i < mProject.ActiveDefSymbolList.Count; i++) {
if (mProject.ActiveDefSymbolList[i] == sym) {
int offset = LineListGen.DefSymOffsetFromIndex(i);
GoToLocation(new NavStack.Location(offset, 0, false),
GoToMode.JumpToCodeData, true);
break;
}
}
} else {
Debug.Assert(false);
}
} else {
// must be a broken weak symbol ref
Debug.WriteLine("Operand symbol not found: " + dfd.SymbolRef.Label);
}
}
} else if (attr.IsDataStart || attr.IsInlineDataStart) {
// If it's an Address or Symbol, we can try to resolve
// the value. (Symbols should have been resolved by the
// previous clause, but Address entries would not have been.)
int operandOffset = DataAnalysis.GetDataOperandOffset(mProject, line.FileOffset);
if (operandOffset >= 0) {
GoToLocation(new NavStack.Location(operandOffset, 0, false),
GoToMode.JumpToCodeData, true);
}
}
}
public bool CanDeleteMlc() {
if (SelectionAnalysis.mNumItemsSelected != 1) {
return false;
@ -2348,8 +2370,8 @@ namespace SourceGen {
/// <param name="doPush">If set, push new offset onto navigation stack.</param>
public void GoToLocation(NavStack.Location loc, GoToMode mode, bool doPush) {
NavStack.Location prevLoc = GetCurrentlySelectedLocation();
Debug.WriteLine("GoToLocation: " + loc + " mode=" + mode + " doPush=" + doPush +
" (curLoc=" + prevLoc + ")");
//Debug.WriteLine("GoToLocation: " + loc + " mode=" + mode + " doPush=" + doPush +
// " (curLoc=" + prevLoc + ")");
// Avoid pushing multiple copies of the same address on. This doesn't quite work
// because we can't compare the LineDelta without figuring out JumpToCodeData first.

View File

@ -5,11 +5,11 @@
.cdef $20,$7e,$20
zip = $cd
absl = $1029
plataddr = $3000 ;address only in platform file
projalsa = $3200 ;same val as projalso
absh = $feed
biggie = $123456
thirty2 = $12345678 ;32-bit constant test
plataddr = $3000 ;address only in platform file
projalsa = $3200 ;same val as projalso
* = $012345
.as

View File

@ -2,11 +2,11 @@
;a duplicate label.
zip equ $cd
absl equ $1029
plataddr equ $3000 ;address only in platform file
projalsa equ $3200 ;same val as projalso
absh equ $feed
biggie equ $123456
thirty2 equ $12345678 ;32-bit constant test
plataddr equ $3000 ;address only in platform file
projalsa equ $3200 ;same val as projalso
org $012345
start clc

View File

@ -3,11 +3,11 @@
.setcpu "65816"
zip = $cd
absl = $1029
plataddr = $3000 ;address only in platform file
projalsa = $3200 ;same val as projalso
absh = $feed
biggie = $123456
thirty2 = $12345678 ;32-bit constant test
plataddr = $3000 ;address only in platform file
projalsa = $3200 ;same val as projalso
; .segment "SEG000"
.org $012345

View File

@ -2,9 +2,9 @@
.cpu "65816"
.enc sg_ascii
.cdef $20,$7e,$20
CONST_ZERO = $f0 ;project const
PROJ_ZERO = $00 ;project addr
PROJ_ONE = $01 ;project addr
CONST_ZERO = $f0 ;project const
* = $1000
.as

View File

@ -1,7 +1,7 @@
;Edited to have duplicate labels (PROJ_ZERO, DPCODE).
CONST_ZERO equ $f0 ;project const
PROJ_ZERO equ $00 ;project addr
PROJ_ONE equ $01 ;project addr
CONST_ZERO equ $f0 ;project const
org $1000
ldy PROJ_ZERO

View File

@ -1,8 +1,8 @@
;Edited to have duplicate labels (PROJ_ZERO, DPCODE).
!cpu 65816
CONST_ZERO = $f0 ;project const
PROJ_ZERO = $00 ;project addr
PROJ_ONE = $01 ;project addr
CONST_ZERO = $f0 ;project const
* = $1000
!as

View File

@ -1,8 +1,8 @@
;Edited to have duplicate labels (PROJ_ZERO, DPCODE).
.setcpu "65816"
CONST_ZERO = $f0 ;project const
PROJ_ZERO = $00 ;project addr
PROJ_ONE = $01 ;project addr
CONST_ZERO = $f0 ;project const
; .segment "SEG000"
.org $1000

View File

@ -1,4 +1,5 @@
.cpu "6502"
FatConst = $4000
OverVar = $40
CodeWrap = $0f00 ;encases program
SameName1 = $2000
@ -17,7 +18,6 @@ Over2a = $3006 ;$3006
Over3 = $3006 ;$3006-300c
SepOver1 = $3100 ;$3100-3103, inclusive
SepOver2 = $3102 ;$3102-3105, inclusive
FatConst = $4000
BankWrap = $fff0
* = $1000

View File

@ -1,3 +1,4 @@
FatConst equ $4000
OverVar equ $40
CodeWrap equ $0f00 ;encases program
SameName1 equ $2000
@ -16,7 +17,6 @@ Over2a equ $3006 ;$3006
Over3 equ $3006 ;$3006-300c
SepOver1 equ $3100 ;$3100-3103, inclusive
SepOver2 equ $3102 ;$3102-3105, inclusive
FatConst equ $4000
BankWrap equ $fff0
org $1000

View File

@ -1,4 +1,5 @@
!cpu 6502
FatConst = $4000
OverVar = $40
CodeWrap = $0f00 ;encases program
SameName1 = $2000
@ -17,7 +18,6 @@ Over2a = $3006 ;$3006
Over3 = $3006 ;$3006-300c
SepOver1 = $3100 ;$3100-3103, inclusive
SepOver2 = $3102 ;$3102-3105, inclusive
FatConst = $4000
BankWrap = $fff0
* = $1000

View File

@ -1,4 +1,5 @@
.setcpu "6502"
FatConst = $4000
OverVar = $40
CodeWrap = $0f00 ;encases program
SameName1 = $2000
@ -17,7 +18,6 @@ Over2a = $3006 ;$3006
Over3 = $3006 ;$3006-300c
SepOver1 = $3100 ;$3100-3103, inclusive
SepOver2 = $3102 ;$3102-3105, inclusive
FatConst = $4000
BankWrap = $fff0
; .segment "SEG000"