1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-09-30 23:55:09 +00:00

Tweak "nearby" label finder

The code that found a nearby data target for an instruction operand
was searching backward but not forward.  We now take one step
forward, so that "LDA TABLE-1,Y" fills in automatically.

This altered 2008-address-changes, which had just this situation.
It didn't alter 2010-target-adjustment, but the existing tests were
insufficient and have been improved.
This commit is contained in:
Andy McFadden 2019-10-29 18:12:22 -07:00
parent 7000a5094e
commit 51081c5db0
13 changed files with 192 additions and 25 deletions

View File

@ -381,24 +381,57 @@ namespace SourceGen {
// We want to use user-defined labels whenever possible. If they're accessing
// memory within a few bytes, use that. We don't want to do this for
// code references, though, or our branches will get all weird.
// TODO(someday): make MAX user-configurable? Seek forward as well as backward?
const int MAX = 4;
for (int probeOffset = targetOffset - 1;
probeOffset >= 0 && probeOffset != targetOffset - MAX; probeOffset--) {
//
// We look a few back and one forward. Stuff backward (which turns into
// LABEL+N) has priority over forward (which becomes LABEL-N).
//
// TODO(someday): make parameters user-configurable?
const int MAX_FWD = 1;
const int MAX_BACK = 3;
int probeOffset = targetOffset;
bool back = true;
while (true) {
if (back) {
// moving backward
probeOffset--;
if (probeOffset < 0 || probeOffset < targetOffset - MAX_BACK) {
// too far back, reverse direction
probeOffset = targetOffset;
back = false;
}
}
if (!back) {
// moving forward
probeOffset++;
if (probeOffset >= mAnattribs.Length ||
probeOffset > targetOffset + MAX_FWD) {
break; // done
}
}
Symbol sym = mAnattribs[probeOffset].Symbol;
if (sym != null && sym.SymbolSource == Symbol.Source.User) {
// Found a nearby user label. Make sure it's actually nearby.
int addrDiff = mAnattribs[targetOffset].Address -
mAnattribs[probeOffset].Address;
mAnattribs[probeOffset].Address;
if (addrDiff == targetOffset - probeOffset) {
targetOffset = probeOffset;
break;
} else {
Debug.WriteLine("NOT probing past address boundary change (src=+" +
srcOffset.ToString("x6") +
" targ=+" + targetOffset.ToString("x6") +
" probe=+" + probeOffset.ToString("x6") + ")");
// No point in continuing to search this direction, but we might
// need to look the other way.
if (back) {
probeOffset = targetOffset;
back = false;
} else {
break;
}
}
break;
}
}
return targetOffset;

View File

@ -1,8 +1,8 @@
### 6502bench SourceGen dis65 v1.0 ###
{
"_ContentVersion":1,"FileDataLength":145,"FileDataCrc32":-56227824,"ProjectProps":{
"CpuName":"65816","IncludeUndocumentedInstr":false,"EntryFlags":33489103,"AnalysisParams":{
"AnalyzeUncategorizedData":true,"MinCharsForString":4,"SeekNearbyTargets":true},
"_ContentVersion":2,"FileDataLength":191,"FileDataCrc32":1554487300,"ProjectProps":{
"CpuName":"65816","IncludeUndocumentedInstr":false,"TwoByteBrk":false,"EntryFlags":33489103,"AutoLabelStyle":"Simple","AnalysisParams":{
"AnalyzeUncategorizedData":true,"DefaultTextScanMode":"LowHighAscii","MinCharsForString":4,"SeekNearbyTargets":true,"SmartPlpHandling":true},
"PlatformSymbolFileIdentifiers":[],"ExtensionScriptFileIdentifiers":[],"ProjectSyms":{
}},
"AddressMap":[{
@ -12,7 +12,7 @@
"Low":0,"High":0,"Hint":"Code"}],"StatusFlagOverrides":{
},
"Comments":{
},
"125":"self-ref; operand format refs nonexistent symbol"},
"LongComments":{
},
"Notes":{
@ -29,7 +29,9 @@
"49":{
"Label":"fill0","Value":4145,"Source":"User","Type":"LocalOrGlobalAddr"},
"132":{
"Label":"dat81","Value":4228,"Source":"User","Type":"LocalOrGlobalAddr"}},
"Label":"dat81","Value":4228,"Source":"User","Type":"LocalOrGlobalAddr"},
"150":{
"Label":"nearby","Value":8209,"Source":"User","Type":"LocalOrGlobalAddr"}},
"OperandFormats":{
"10":{
"Length":2,"Format":"NumericLE","SubFormat":"Hex","SymbolRef":null},
@ -60,4 +62,6 @@
"Label":"fill0","Part":"Low"}},
"125":{
"Length":3,"Format":"NumericLE","SubFormat":"Symbol","SymbolRef":{
"Label":"nonexistent","Part":"Low"}}}}
"Label":"nonexistent","Part":"Low"}}},
"LvTables":{
}}

View File

@ -90,14 +90,14 @@ ulabel .byte $00
.byte $01
.here
.logical $3100
L3100 .byte $02
.byte $02
fwd bit fwd
lda ulabel
lda ulabel+1
lda $300e
lda $300f
lda L3100
lda fwd-1
beq L3182
.byte $ea
.byte $ea

View File

@ -77,14 +77,14 @@ L3000 bit L3000
ulabel dfb $00
dfb $01
org $3100
L3100 dfb $02
dfb $02
fwd bit fwd
lda ulabel
lda ulabel+1
lda $300e
lda $300f
lda L3100
lda fwd-1
beq L3182
dfb $ea
dfb $ea

View File

@ -90,14 +90,14 @@ ulabel !byte $00
!byte $01
} ;!pseudopc
!pseudopc $3100 {
L3100 !byte $02
!byte $02
fwd bit fwd
lda ulabel
lda ulabel+1
lda $300e
lda $300f
lda L3100
lda fwd-1
beq L3182
!byte $ea
!byte $ea

View File

@ -92,14 +92,14 @@ ulabel: .byte $00
.byte $01
; .segment "SEG011"
.org $3100
L3100: .byte $02
.byte $02
fwd: bit fwd
lda ulabel
lda ulabel+1
lda $300e
lda $300f
lda L3100
lda fwd-1
beq L3182
.byte $ea
.byte $ea

View File

@ -45,7 +45,7 @@ L1069 pea L1069-1
lda #$ea
L1077 sta L1077
L107A sta L107A+1
sta $107f
sta $107f ;self-ref; operand format refs nonexistent symbol
brl L2002
.byte $80
@ -57,6 +57,31 @@ L2000 .byte $82
L2002 bit L2002
lda dat81
lda L2000
bra L2018
L200D .byte $7c
L200E .byte $7d
L200F .byte $7e
.byte $7f
nearby .byte $80
.byte $81
.byte $82
.byte $83
L2015 .byte $84
L2016 .byte $85
L2017 .byte $86
L2018 lda L200D
lda L200E
lda L200F
lda nearby-1
lda nearby
lda nearby+1
lda nearby+2
lda nearby+3
lda L2015
lda L2016
lda L2017
rts
.here

View File

@ -40,7 +40,7 @@ L1069 pea L1069-1
lda #$ea
L1077 sta L1077
L107A sta L107A+1
sta $107f
sta $107f ;self-ref; operand format refs nonexistent symbol
brl L2002
dfb $80
@ -52,5 +52,30 @@ L2000 dfb $82
L2002 bit L2002
lda dat81
lda L2000
bra L2018
L200D dfb $7c
L200E dfb $7d
L200F dfb $7e
dfb $7f
nearby dfb $80
dfb $81
dfb $82
dfb $83
L2015 dfb $84
L2016 dfb $85
L2017 dfb $86
L2018 lda L200D
lda L200E
lda L200F
lda nearby-1
lda nearby
lda nearby+1
lda nearby+2
lda nearby+3
lda L2015
lda L2016
lda L2017
rts

View File

@ -43,7 +43,7 @@ L1069 pea L1069-1
lda #$ea
L1077 sta L1077
L107A sta L107A+1
sta $107f
sta $107f ;self-ref; operand format refs nonexistent symbol
brl L2002
!byte $80
@ -55,6 +55,31 @@ L2000 !byte $82
L2002 bit L2002
lda dat81
lda L2000
bra L2018
L200D !byte $7c
L200E !byte $7d
L200F !byte $7e
!byte $7f
nearby !byte $80
!byte $81
!byte $82
!byte $83
L2015 !byte $84
L2016 !byte $85
L2017 !byte $86
L2018 lda L200D
lda L200E
lda L200F
lda nearby-1
lda nearby
lda nearby+1
lda nearby+2
lda nearby+3
lda L2015
lda L2016
lda L2017
rts
} ;!pseudopc

View File

@ -44,7 +44,7 @@ L1069: pea L1069-1
lda #$ea
L1077: sta L1077
L107A: sta L107A+1
sta $107f
sta $107f ;self-ref; operand format refs nonexistent symbol
brl L2002
.byte $80
@ -57,5 +57,30 @@ L2000: .byte $82
L2002: bit L2002
lda dat81
lda L2000
bra L2018
L200D: .byte $7c
L200E: .byte $7d
L200F: .byte $7e
.byte $7f
nearby: .byte $80
.byte $81
.byte $82
.byte $83
L2015: .byte $84
L2016: .byte $85
L2017: .byte $86
L2018: lda L200D
lda L200E
lda L200F
lda nearby-1
lda nearby
lda nearby+1
lda nearby+2
lda nearby+3
lda L2015
lda L2016
lda L2017
rts

View File

@ -2,7 +2,7 @@
MEMORY {
MAIN: file=%O, start=%S, size=65536;
# MEM000: file=%O, start=$1000, size=133;
# MEM001: file=%O, start=$2000, size=12;
# MEM001: file=%O, start=$2000, size=58;
}
SEGMENTS {
CODE: load=MAIN, type=rw;

View File

@ -72,4 +72,34 @@ skipdat1
bit skipdat1
lda dat81
lda dat82 ;this should NOT use dat81
;
; Test the precise extent to which we associate a label with nearby elements.
;
bra skipmore
dfb $7c
dfb $7d
dfb $7e
dfb $7f
nearby dfb $80 ;EDIT: label this
dfb $81
dfb $82
dfb $83
dfb $84
dfb $85
dfb $86
skipmore
lda nearby-4
lda nearby-3
lda nearby-2
lda nearby-1
lda nearby
lda nearby+1
lda nearby+2
lda nearby+3
lda nearby+4
lda nearby+5
lda nearby+6
rts