mirror of
https://github.com/fadden/6502bench.git
synced 2025-02-20 06:29:04 +00:00
Finish the underscore handling in the label localizer
Correctly handle pre-existing underscores and avoidance of "reserved" labels. Also, add more underscores to 2012-label-localizer to exercise the code. (issue #16)
This commit is contained in:
parent
f7e5cf2f45
commit
f26a03869a
@ -211,7 +211,7 @@ namespace SourceGen.AsmGen {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void UpdateAssemblerControls() {
|
private void UpdateAssemblerControls() {
|
||||||
bool asmConf = IsAssemblerConfigured();
|
bool asmConf = IsAssemblerConfigured();
|
||||||
Debug.WriteLine("ID=" + mSelectedAssemblerId + " asmConf=" + asmConf);
|
//Debug.WriteLine("ID=" + mSelectedAssemblerId + " asmConf=" + asmConf);
|
||||||
configureAsmLinkLabel.Visible = !asmConf;
|
configureAsmLinkLabel.Visible = !asmConf;
|
||||||
if (mGenerationResults == null || !asmConf) {
|
if (mGenerationResults == null || !asmConf) {
|
||||||
runAssemblerButton.Enabled = false;
|
runAssemblerButton.Enabled = false;
|
||||||
|
@ -167,6 +167,8 @@ namespace SourceGen.AsmGen {
|
|||||||
/// Analyzes labels to identify which ones may be treated as non-global.
|
/// Analyzes labels to identify which ones may be treated as non-global.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Analyze() {
|
public void Analyze() {
|
||||||
|
Debug.Assert(LocalPrefix.Length > 0);
|
||||||
|
|
||||||
mGlobalFlags.SetAll(false);
|
mGlobalFlags.SetAll(false);
|
||||||
|
|
||||||
// Currently we only support the "local labels have scope that ends at a global
|
// Currently we only support the "local labels have scope that ends at a global
|
||||||
@ -317,6 +319,8 @@ namespace SourceGen.AsmGen {
|
|||||||
///
|
///
|
||||||
/// This may be called even if label localization is disabled. In that case we just
|
/// This may be called even if label localization is disabled. In that case we just
|
||||||
/// create an empty label map and populate as needed.
|
/// create an empty label map and populate as needed.
|
||||||
|
///
|
||||||
|
/// Only call this if underscores are used to indicate local labels.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void MaskLeadingUnderscores() {
|
public void MaskLeadingUnderscores() {
|
||||||
bool allGlobal = false;
|
bool allGlobal = false;
|
||||||
@ -325,6 +329,14 @@ namespace SourceGen.AsmGen {
|
|||||||
LabelMap = new Dictionary<string, string>();
|
LabelMap = new Dictionary<string, string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Throw out the original local label generation.
|
||||||
|
LabelMap.Clear();
|
||||||
|
|
||||||
|
// Use this to test for uniqueness. We add all labels here as we go, not just the
|
||||||
|
// ones being remapped. For each label we either add the original or the localized
|
||||||
|
// form.
|
||||||
|
SortedList<string, string> allLabels = new SortedList<string, string>();
|
||||||
|
|
||||||
for (int i = 0; i < mProject.FileDataLength; i++) {
|
for (int i = 0; i < mProject.FileDataLength; i++) {
|
||||||
Symbol sym = mProject.GetAnattrib(i).Symbol;
|
Symbol sym = mProject.GetAnattrib(i).Symbol;
|
||||||
if (sym == null) {
|
if (sym == null) {
|
||||||
@ -332,12 +344,43 @@ namespace SourceGen.AsmGen {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sym.Label.StartsWith("_") && (allGlobal || mGlobalFlags[i])) {
|
string newLabel;
|
||||||
Debug.WriteLine("Adjusting " + sym.Label);
|
if (allGlobal || mGlobalFlags[i]) {
|
||||||
// TODO: uniquify
|
// Global symbol. Don't let it start with '_'.
|
||||||
LabelMap[sym.Label] = "X" + sym.Label;
|
if (sym.Label.StartsWith("_")) {
|
||||||
|
// There's an underscore here that was added by the user. Stick some
|
||||||
|
// other character in front.
|
||||||
|
newLabel = "X" + sym.Label;
|
||||||
|
} else {
|
||||||
|
// No change needed.
|
||||||
|
newLabel = sym.Label;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Local symbol.
|
||||||
|
if (sym.Label.StartsWith("_")) {
|
||||||
|
// The original starts with one or more underscores. Adding another
|
||||||
|
// will create a "__" label, which is reserved in 64tass.
|
||||||
|
newLabel = "_X" + sym.Label;
|
||||||
|
} else {
|
||||||
|
newLabel = "_" + sym.Label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure it's unique.
|
||||||
|
string uniqueLabel = newLabel;
|
||||||
|
int uval = 1;
|
||||||
|
while (allLabels.ContainsKey(uniqueLabel)) {
|
||||||
|
uniqueLabel = newLabel + uval.ToString();
|
||||||
|
}
|
||||||
|
allLabels.Add(uniqueLabel, uniqueLabel);
|
||||||
|
|
||||||
|
// If it's different, add it to the label map.
|
||||||
|
if (sym.Label != uniqueLabel) {
|
||||||
|
LabelMap.Add(sym.Label, uniqueLabel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Debug.WriteLine("UMAP: allcount=" + allLabels.Count + " mapcount=" + LabelMap.Count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,6 +139,8 @@ code, but also needs to know how to handle the corner cases.</p>
|
|||||||
label is local. If you create labels with leading underscores that
|
label is local. If you create labels with leading underscores that
|
||||||
are not local, the labels must be altered to start with some other
|
are not local, the labels must be altered to start with some other
|
||||||
character, and made unique.</li>
|
character, and made unique.</li>
|
||||||
|
<li>Labels starting with two underscores are "reserved". Trying to
|
||||||
|
use them causes an error.</li>
|
||||||
<li>By default, 64tass sets the first two bytes of the output file to
|
<li>By default, 64tass sets the first two bytes of the output file to
|
||||||
the load address. The <code>--nostart</code> flag is used to
|
the load address. The <code>--nostart</code> flag is used to
|
||||||
suppress this.</li>
|
suppress this.</li>
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
"16":{
|
"16":{
|
||||||
"Label":"pastglob","Value":4112,"Source":"User","Type":"LocalOrGlobalAddr"},
|
"Label":"pastglob","Value":4112,"Source":"User","Type":"LocalOrGlobalAddr"},
|
||||||
"15":{
|
"15":{
|
||||||
"Label":"nextglob","Value":4111,"Source":"User","Type":"GlobalAddr"},
|
"Label":"X_start","Value":4111,"Source":"User","Type":"GlobalAddr"},
|
||||||
"20":{
|
"20":{
|
||||||
"Label":"nlocal","Value":4116,"Source":"User","Type":"GlobalAddr"},
|
"Label":"nlocal","Value":4116,"Source":"User","Type":"GlobalAddr"},
|
||||||
"22":{
|
"22":{
|
||||||
@ -40,9 +40,9 @@
|
|||||||
"30":{
|
"30":{
|
||||||
"Label":"reach3G","Value":4126,"Source":"User","Type":"GlobalAddr"},
|
"Label":"reach3G","Value":4126,"Source":"User","Type":"GlobalAddr"},
|
||||||
"31":{
|
"31":{
|
||||||
"Label":"reach4","Value":4127,"Source":"User","Type":"LocalOrGlobalAddr"},
|
"Label":"_reach4","Value":4127,"Source":"User","Type":"LocalOrGlobalAddr"},
|
||||||
"1":{
|
"1":{
|
||||||
"Label":"start","Value":4097,"Source":"User","Type":"LocalOrGlobalAddr"},
|
"Label":"_start","Value":4097,"Source":"User","Type":"LocalOrGlobalAddr"},
|
||||||
"50":{
|
"50":{
|
||||||
"Label":"gtest1","Value":4146,"Source":"User","Type":"GlobalAddr"},
|
"Label":"gtest1","Value":4146,"Source":"User","Type":"GlobalAddr"},
|
||||||
"54":{
|
"54":{
|
||||||
@ -52,7 +52,7 @@
|
|||||||
"61":{
|
"61":{
|
||||||
"Label":"topglob","Value":4157,"Source":"User","Type":"GlobalAddr"},
|
"Label":"topglob","Value":4157,"Source":"User","Type":"GlobalAddr"},
|
||||||
"70":{
|
"70":{
|
||||||
"Label":"globalnm","Value":4166,"Source":"User","Type":"LocalOrGlobalAddr"},
|
"Label":"globalnm","Value":4166,"Source":"User","Type":"GlobalAddr"},
|
||||||
"76":{
|
"76":{
|
||||||
"Label":"nglobal","Value":4172,"Source":"User","Type":"LocalOrGlobalAddr"},
|
"Label":"nglobal","Value":4172,"Source":"User","Type":"LocalOrGlobalAddr"},
|
||||||
"82":{
|
"82":{
|
||||||
@ -60,7 +60,11 @@
|
|||||||
"77":{
|
"77":{
|
||||||
"Label":"globlat","Value":4173,"Source":"User","Type":"GlobalAddr"},
|
"Label":"globlat","Value":4173,"Source":"User","Type":"GlobalAddr"},
|
||||||
"83":{
|
"83":{
|
||||||
"Label":"EXCESSIVELY_LONG_LABEL","Value":4179,"Source":"User","Type":"GlobalAddr"}},
|
"Label":"EXCESSIVELY_LONG_LABEL","Value":4179,"Source":"User","Type":"GlobalAddr"},
|
||||||
|
"14":{
|
||||||
|
"Label":"__nopped","Value":4110,"Source":"User","Type":"LocalOrGlobalAddr"},
|
||||||
|
"13":{
|
||||||
|
"Label":"start","Value":4109,"Source":"User","Type":"LocalOrGlobalAddr"}},
|
||||||
"OperandFormats":{
|
"OperandFormats":{
|
||||||
"23":{
|
"23":{
|
||||||
"Length":3,"Format":"NumericLE","SubFormat":"Symbol","SymbolRef":{
|
"Length":3,"Format":"NumericLE","SubFormat":"Symbol","SymbolRef":{
|
||||||
@ -70,6 +74,6 @@
|
|||||||
"Label":"reach2","Part":"Low"}},
|
"Label":"reach2","Part":"Low"}},
|
||||||
"32":{
|
"32":{
|
||||||
"Length":3,"Format":"NumericLE","SubFormat":"Symbol","SymbolRef":{
|
"Length":3,"Format":"NumericLE","SubFormat":"Symbol","SymbolRef":{
|
||||||
"Label":"reach4","Part":"Low"}},
|
"Label":"_reach4","Part":"Low"}},
|
||||||
"58":{
|
"58":{
|
||||||
"Length":3,"Format":"NumericLE","SubFormat":"Hex","SymbolRef":null}}}
|
"Length":3,"Format":"NumericLE","SubFormat":"Hex","SymbolRef":null}}}
|
||||||
|
@ -5,13 +5,14 @@ REALLYLONGLABELNAME = $8888 ;that's a long name
|
|||||||
.as
|
.as
|
||||||
.xs
|
.xs
|
||||||
nop
|
nop
|
||||||
start lda _L100D
|
X_start lda _start
|
||||||
lda nextglob
|
lda X_start1
|
||||||
lda pastglob
|
lda pastglob
|
||||||
lda _L100E
|
lda _X__nopped
|
||||||
_L100D nop
|
_start nop
|
||||||
_L100E nop
|
_X__nopped
|
||||||
nextglob
|
nop
|
||||||
|
X_start1
|
||||||
nop
|
nop
|
||||||
pastglob
|
pastglob
|
||||||
nop
|
nop
|
||||||
@ -22,12 +23,13 @@ reach1G nop
|
|||||||
lda _reach2+2
|
lda _reach2+2
|
||||||
_reach2 nop
|
_reach2 nop
|
||||||
reach3G nop
|
reach3G nop
|
||||||
_reach4 nop
|
_X_reach4
|
||||||
lda _reach4-2
|
nop
|
||||||
|
lda _X_reach4-2
|
||||||
lda $00
|
lda $00
|
||||||
beq _L102D
|
beq _L102D
|
||||||
jsr _reach4
|
jsr _X_reach4
|
||||||
jsr start
|
jsr X_start
|
||||||
_L102D lda #$22
|
_L102D lda #$22
|
||||||
lda gtest2
|
lda gtest2
|
||||||
gtest1 nop
|
gtest1 nop
|
||||||
@ -42,7 +44,7 @@ topglob nop
|
|||||||
nop
|
nop
|
||||||
_L1043 nop
|
_L1043 nop
|
||||||
lda #$44
|
lda #$44
|
||||||
_globalnm
|
globalnm
|
||||||
jsr _L104A
|
jsr _L104A
|
||||||
nop
|
nop
|
||||||
_L104A nop
|
_L104A nop
|
||||||
|
@ -2,13 +2,14 @@ REALLYLONGLABELNAME equ $8888 ;that's a long name
|
|||||||
|
|
||||||
org $1000
|
org $1000
|
||||||
nop
|
nop
|
||||||
start lda :L100D
|
_start lda :start
|
||||||
lda nextglob
|
lda X_start
|
||||||
lda pastglob
|
lda pastglob
|
||||||
lda :L100E
|
lda :__nopped
|
||||||
:L100D nop
|
:start nop
|
||||||
:L100E nop
|
:__nopped
|
||||||
nextglob nop
|
nop
|
||||||
|
X_start nop
|
||||||
pastglob nop
|
pastglob nop
|
||||||
lda nlocal
|
lda nlocal
|
||||||
nlocal lda #$11
|
nlocal lda #$11
|
||||||
@ -17,12 +18,12 @@ reach1G nop
|
|||||||
lda :reach2+2
|
lda :reach2+2
|
||||||
:reach2 nop
|
:reach2 nop
|
||||||
reach3G nop
|
reach3G nop
|
||||||
:reach4 nop
|
:_reach4 nop
|
||||||
lda :reach4-2
|
lda :_reach4-2
|
||||||
lda $00
|
lda $00
|
||||||
beq :L102D
|
beq :L102D
|
||||||
jsr :reach4
|
jsr :_reach4
|
||||||
jsr start
|
jsr _start
|
||||||
:L102D lda #$22
|
:L102D lda #$22
|
||||||
lda gtest2
|
lda gtest2
|
||||||
gtest1 nop
|
gtest1 nop
|
||||||
@ -37,8 +38,7 @@ topglob nop
|
|||||||
nop
|
nop
|
||||||
:L1043 nop
|
:L1043 nop
|
||||||
lda #$44
|
lda #$44
|
||||||
:globalnm
|
globalnm jsr :L104A
|
||||||
jsr :L104A
|
|
||||||
nop
|
nop
|
||||||
:L104A nop
|
:L104A nop
|
||||||
nop
|
nop
|
||||||
|
@ -5,14 +5,14 @@ REALLYLONGLABELNAME = $8888 ;that's a long name
|
|||||||
.a8
|
.a8
|
||||||
.i8
|
.i8
|
||||||
nop
|
nop
|
||||||
start: lda @L100D
|
_start: lda @start
|
||||||
lda nextglob
|
lda X_start
|
||||||
lda pastglob
|
lda pastglob
|
||||||
lda @L100E
|
lda @__nopped
|
||||||
@L100D: nop
|
@start: nop
|
||||||
@L100E: nop
|
@__nopped:
|
||||||
nextglob:
|
|
||||||
nop
|
nop
|
||||||
|
X_start: nop
|
||||||
pastglob:
|
pastglob:
|
||||||
nop
|
nop
|
||||||
lda nlocal
|
lda nlocal
|
||||||
@ -22,12 +22,13 @@ reach1G: nop
|
|||||||
lda @reach2+2
|
lda @reach2+2
|
||||||
@reach2: nop
|
@reach2: nop
|
||||||
reach3G: nop
|
reach3G: nop
|
||||||
@reach4: nop
|
@_reach4:
|
||||||
lda @reach4-2
|
nop
|
||||||
|
lda @_reach4-2
|
||||||
lda $00
|
lda $00
|
||||||
beq @L102D
|
beq @L102D
|
||||||
jsr @reach4
|
jsr @_reach4
|
||||||
jsr start
|
jsr _start
|
||||||
@L102D: lda #$22
|
@L102D: lda #$22
|
||||||
lda gtest2
|
lda gtest2
|
||||||
gtest1: nop
|
gtest1: nop
|
||||||
@ -42,7 +43,7 @@ topglob: nop
|
|||||||
nop
|
nop
|
||||||
@L1043: nop
|
@L1043: nop
|
||||||
lda #$44
|
lda #$44
|
||||||
@globalnm:
|
globalnm:
|
||||||
jsr @L104A
|
jsr @L104A
|
||||||
nop
|
nop
|
||||||
@L104A: nop
|
@L104A: nop
|
||||||
|
Loading…
x
Reference in New Issue
Block a user