1
0
mirror of https://github.com/fadden/6502bench.git synced 2025-01-05 23:30:20 +00:00

Don't use "not" as a label in ACME output

The ACME assembler gets upset if you use "not" as a label.  We now
avoid doing so, using a generalized implementation of the opcode
mnemonic rename code.  (Issue #112.)

Renamed a label to "not" in the 20081-label-localizer test.
This commit is contained in:
Andy McFadden 2021-10-18 13:01:06 -07:00
parent 0fb0b4cca8
commit 55f0230e6f
7 changed files with 318 additions and 66 deletions

View File

@ -268,6 +268,7 @@ namespace SourceGen.AsmGen {
// between global labels. (This is poorly documented.)
mLocalizer.LocalPrefix = "@";
mLocalizer.QuirkNoOpcodeMnemonics = true;
mLocalizer.ReservedWords = new List<string>() { "NOT" };
mLocalizer.Analyze();
mPcDepth = 0;

View File

@ -147,6 +147,11 @@ namespace SourceGen.AsmGen {
/// </summary>
public bool QuirkNoOpcodeMnemonics { get; set; }
/// <summary>
/// Set this if there are reserved words that must not be used as labels.
/// </summary>
public List<string> ReservedWords { get; set; }
/// <summary>
/// Project reference.
/// </summary>
@ -238,18 +243,24 @@ namespace SourceGen.AsmGen {
Dictionary<string, string> allGlobalLabels = new Dictionary<string, string>();
bool remapUnders = (LocalPrefix == "_");
Dictionary<string, Asm65.OpDef> opNames = null;
HashSet<string> rsvdNames = new HashSet<string>();
if (QuirkNoOpcodeMnemonics) {
// Create a searchable list of opcode names using the current CPU definition.
// (All tested assemblers that failed on opcode names only did so for names
// that were part of the current definition, e.g. "TSB" was accepted as a label
// when the CPU was set to 6502.)
opNames = new Dictionary<string, Asm65.OpDef>();
Asm65.CpuDef cpuDef = mProject.CpuDef;
for (int i = 0; i < 256; i++) {
Asm65.OpDef op = cpuDef.GetOpDef(i);
// There may be multiple entries with the same name (e.g. "NOP"). That's fine.
opNames[op.Mnemonic.ToUpperInvariant()] = op;
rsvdNames.Add(op.Mnemonic.ToUpperInvariant());
}
}
// Add any words that the assembler just doesn't like.
if (ReservedWords != null) {
foreach (string str in ReservedWords) {
rsvdNames.Add(str);
}
}
@ -264,7 +275,7 @@ namespace SourceGen.AsmGen {
continue;
}
RemapGlobalSymbol(sym, allGlobalLabels, opNames, remapUnders);
RemapGlobalSymbol(sym, allGlobalLabels, rsvdNames, remapUnders);
}
// Remap any project/platform symbols that clash with opcode mnemonics or have
@ -277,7 +288,7 @@ namespace SourceGen.AsmGen {
// LabelMap[defSym.Label] = newLabel;
// allGlobalLabels.Add(newLabel, newLabel);
//}
RemapGlobalSymbol(defSym, allGlobalLabels, opNames, remapUnders);
RemapGlobalSymbol(defSym, allGlobalLabels, rsvdNames, remapUnders);
}
// Remap any address region pre-labels with inappropriate values.
@ -291,7 +302,7 @@ namespace SourceGen.AsmGen {
Symbol sym = new Symbol(change.Region.PreLabel, change.Region.PreLabelAddress,
Symbol.Source.AddrPreLabel, Symbol.Type.ExternalAddr,
Symbol.LabelAnnotation.None);
RemapGlobalSymbol(sym, allGlobalLabels, opNames, remapUnders);
RemapGlobalSymbol(sym, allGlobalLabels, rsvdNames, remapUnders);
}
//
@ -350,12 +361,13 @@ namespace SourceGen.AsmGen {
/// <param name="sym">Symbol to rename.</param>
/// <param name="allGlobalLabels">List of all global labels, used when uniquifing
/// a "promoted" local. May be updated.</param>
/// <param name="opNames">List of opcode mnemonics for configured CPU. Will be
/// null if the assembler allows labels to be the same as opcodes.</param>
/// <param name="rsvdNames">List of reserved words. If the assembler doesn't allow
/// the use of opcode mnemonics as labels, this will hold the list of mnemonics for
/// the configured CPU.</param>
/// <param name="remapUnders">True if leading underscores are not allowed (because
/// they're used to indicate local labels).</param>
private void RemapGlobalSymbol(Symbol sym, Dictionary<string, string> allGlobalLabels,
Dictionary<string, Asm65.OpDef> opNames, bool remapUnders) {
HashSet<string> rsvdNames, bool remapUnders) {
string newLabel = sym.LabelWithoutTag;
if (remapUnders && newLabel[0] == '_') {
newLabel = NO_UNDER_PFX + newLabel;
@ -365,7 +377,7 @@ namespace SourceGen.AsmGen {
newLabel = MakeUnique(newLabel, allGlobalLabels);
}
}
if (opNames != null && opNames.ContainsKey(newLabel.ToUpperInvariant())) {
if (rsvdNames != null && rsvdNames.Contains(newLabel.ToUpperInvariant())) {
// Clashed with mnemonic. Uniquify it.
newLabel = MakeUnique(newLabel, allGlobalLabels);
}

View File

@ -1,99 +1,338 @@
### 6502bench SourceGen dis65 v1.0 ###
{
"_ContentVersion":2,"FileDataLength":103,"FileDataCrc32":1381810255,"ProjectProps":{
"CpuName":"65C02","IncludeUndocumentedInstr":false,"EntryFlags":32702671,"AutoLabelStyle":"Simple","AnalysisParams":{
"AnalyzeUncategorizedData":true,"DefaultTextScanMode":"LowHighAscii","MinCharsForString":4,"SeekNearbyTargets":true,"SmartPlpHandling":true},
"PlatformSymbolFileIdentifiers":[],"ExtensionScriptFileIdentifiers":[],"ProjectSyms":{
"_ContentVersion":5,
"FileDataLength":103,
"FileDataCrc32":1381810255,
"ProjectProps":{
"CpuName":"65C02",
"IncludeUndocumentedInstr":false,
"TwoByteBrk":false,
"EntryFlags":32702671,
"AutoLabelStyle":"Simple",
"AnalysisParams":{
"AnalyzeUncategorizedData":true,
"DefaultTextScanMode":"LowHighAscii",
"MinCharsForString":4,
"SeekNearbyTargets":true,
"UseRelocData":false,
"SmartPlpHandling":true,
"SmartPlbHandling":true},
"PlatformSymbolFileIdentifiers":[],
"ExtensionScriptFileIdentifiers":[],
"ProjectSyms":{
"__ENABLE_LABEL_LOCALIZATION":{
"DataDescriptor":{
"Length":1,"Format":"NumericLE","SubFormat":"Decimal","SymbolRef":null},
"Comment":"","Label":"__ENABLE_LABEL_LOCALIZATION","Value":1,"Source":"Project","Type":"Constant"},
"Length":1,
"Format":"NumericLE",
"SubFormat":"Decimal",
"SymbolRef":null},
"Comment":"",
"HasWidth":false,
"Direction":"ReadWrite",
"MultiMask":null,
"Label":"__ENABLE_LABEL_LOCALIZATION",
"Value":1,
"Source":"Project",
"Type":"Constant",
"LabelAnno":"None"},
"__ENABLE_LABEL_NEWLINE":{
"DataDescriptor":{
"Length":1,"Format":"NumericLE","SubFormat":"Decimal","SymbolRef":null},
"Comment":"","Label":"__ENABLE_LABEL_NEWLINE","Value":1,"Source":"Project","Type":"Constant"},
"Length":1,
"Format":"NumericLE",
"SubFormat":"Decimal",
"SymbolRef":null},
"Comment":"",
"HasWidth":false,
"Direction":"ReadWrite",
"MultiMask":null,
"Label":"__ENABLE_LABEL_NEWLINE",
"Value":1,
"Source":"Project",
"Type":"Constant",
"LabelAnno":"None"},
"REALLYLONGLABELNAME":{
"DataDescriptor":{
"Length":1,"Format":"NumericLE","SubFormat":"Hex","SymbolRef":null},
"Comment":"that\u0027s a long name","Label":"REALLYLONGLABELNAME","Value":34952,"Source":"Project","Type":"ExternalAddr"}}},
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},
"Comment":"that\u0027s a long name",
"HasWidth":false,
"Direction":"ReadWrite",
"MultiMask":null,
"Label":"REALLYLONGLABELNAME",
"Value":34952,
"Source":"Project",
"Type":"ExternalAddr",
"LabelAnno":"None"}}},
"AddressMap":[{
"Offset":0,"Addr":4096}],"TypeHints":[{
"Low":0,"High":0,"Hint":"Code"}],"StatusFlagOverrides":{
"Offset":0,
"Addr":4096,
"Length":-1024,
"PreLabel":"",
"IsRelative":false}],
"TypeHints":[{
"Low":0,
"High":0,
"Hint":"Code"}],
"StatusFlagOverrides":{
},
"Comments":{
"92":"local","94":"global"},
"92":"local",
"94":"global"},
"LongComments":{
},
"Notes":{
},
"UserLabels":{
"16":{
"Label":"pastglob","Value":4112,"Source":"User","Type":"LocalOrGlobalAddr"},
"Label":"pastglob",
"Value":4112,
"Source":"User",
"Type":"LocalOrGlobalAddr",
"LabelAnno":"None"},
"15":{
"Label":"X_start","Value":4111,"Source":"User","Type":"GlobalAddr"},
"Label":"X_start",
"Value":4111,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"},
"20":{
"Label":"nlocal","Value":4116,"Source":"User","Type":"GlobalAddr"},
"Label":"nlocal",
"Value":4116,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"},
"22":{
"Label":"reach1G","Value":4118,"Source":"User","Type":"GlobalAddr"},
"Label":"reach1G",
"Value":4118,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"},
"29":{
"Label":"reach2","Value":4125,"Source":"User","Type":"LocalOrGlobalAddr"},
"Label":"reach2",
"Value":4125,
"Source":"User",
"Type":"LocalOrGlobalAddr",
"LabelAnno":"None"},
"30":{
"Label":"reach3G","Value":4126,"Source":"User","Type":"GlobalAddr"},
"Label":"reach3G",
"Value":4126,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"},
"31":{
"Label":"_reach4","Value":4127,"Source":"User","Type":"LocalOrGlobalAddr"},
"Label":"_reach4",
"Value":4127,
"Source":"User",
"Type":"LocalOrGlobalAddr",
"LabelAnno":"None"},
"1":{
"Label":"_start","Value":4097,"Source":"User","Type":"LocalOrGlobalAddr"},
"Label":"_start",
"Value":4097,
"Source":"User",
"Type":"LocalOrGlobalAddr",
"LabelAnno":"None"},
"50":{
"Label":"gtest1","Value":4146,"Source":"User","Type":"GlobalAddr"},
"Label":"gtest1",
"Value":4146,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"},
"54":{
"Label":"gtest2","Value":4150,"Source":"User","Type":"LocalOrGlobalAddr"},
"Label":"gtest2",
"Value":4150,
"Source":"User",
"Type":"LocalOrGlobalAddr",
"LabelAnno":"None"},
"55":{
"Label":"gtest3","Value":4151,"Source":"User","Type":"LocalOrGlobalAddr"},
"Label":"gtest3",
"Value":4151,
"Source":"User",
"Type":"LocalOrGlobalAddr",
"LabelAnno":"None"},
"61":{
"Label":"topglob","Value":4157,"Source":"User","Type":"GlobalAddr"},
"Label":"topglob",
"Value":4157,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"},
"70":{
"Label":"globalnm","Value":4166,"Source":"User","Type":"GlobalAddr"},
"Label":"globalnm",
"Value":4166,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"},
"76":{
"Label":"nglobal","Value":4172,"Source":"User","Type":"LocalOrGlobalAddr"},
"Label":"nglobal",
"Value":4172,
"Source":"User",
"Type":"LocalOrGlobalAddr",
"LabelAnno":"None"},
"82":{
"Label":"end","Value":4178,"Source":"User","Type":"GlobalAddr"},
"Label":"NOT",
"Value":4178,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"},
"77":{
"Label":"globlat","Value":4173,"Source":"User","Type":"GlobalAddr"},
"Label":"globlat",
"Value":4173,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"},
"83":{
"Label":"EXCESSIVELY_LONG_LABEL","Value":4179,"Source":"User","Type":"GlobalAddr"},
"Label":"EXCESSIVELY_LONG_LABEL",
"Value":4179,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"},
"14":{
"Label":"__nopped","Value":4110,"Source":"User","Type":"LocalOrGlobalAddr"},
"Label":"__nopped",
"Value":4110,
"Source":"User",
"Type":"LocalOrGlobalAddr",
"LabelAnno":"None"},
"13":{
"Label":"start","Value":4109,"Source":"User","Type":"LocalOrGlobalAddr"},
"Label":"start",
"Value":4109,
"Source":"User",
"Type":"LocalOrGlobalAddr",
"LabelAnno":"None"},
"86":{
"Label":"_uname","Value":4182,"Source":"User","Type":"LocalOrGlobalAddr"},
"Label":"_uname",
"Value":4182,
"Source":"User",
"Type":"LocalOrGlobalAddr",
"LabelAnno":"None"},
"87":{
"Label":"X_uname11","Value":4183,"Source":"User","Type":"LocalOrGlobalAddr"},
"Label":"X_uname11",
"Value":4183,
"Source":"User",
"Type":"LocalOrGlobalAddr",
"LabelAnno":"None"},
"88":{
"Label":"X_uname1","Value":4184,"Source":"User","Type":"LocalOrGlobalAddr"},
"Label":"X_uname1",
"Value":4184,
"Source":"User",
"Type":"LocalOrGlobalAddr",
"LabelAnno":"None"},
"92":{
"Label":"AND","Value":4188,"Source":"User","Type":"LocalOrGlobalAddr"},
"Label":"AND",
"Value":4188,
"Source":"User",
"Type":"LocalOrGlobalAddr",
"LabelAnno":"None"},
"94":{
"Label":"JMP","Value":4190,"Source":"User","Type":"GlobalAddr"},
"Label":"JMP",
"Value":4190,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"},
"96":{
"Label":"jmp","Value":4192,"Source":"User","Type":"GlobalAddr"},
"Label":"jmp",
"Value":4192,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"},
"98":{
"Label":"TSB","Value":4194,"Source":"User","Type":"GlobalAddr"},
"Label":"TSB",
"Value":4194,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"},
"89":{
"Label":"X_uname","Value":4185,"Source":"User","Type":"LocalOrGlobalAddr"},
"Label":"X_uname",
"Value":4185,
"Source":"User",
"Type":"LocalOrGlobalAddr",
"LabelAnno":"None"},
"100":{
"Label":"XCE","Value":4196,"Source":"User","Type":"GlobalAddr"}},
"Label":"XCE",
"Value":4196,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"}},
"OperandFormats":{
"23":{
"Length":3,"Format":"NumericLE","SubFormat":"Symbol","SymbolRef":{
"Label":"reach1G","Part":"Low"}},
"Length":3,
"Format":"NumericLE",
"SubFormat":"Symbol",
"SymbolRef":{
"Label":"reach1G",
"Part":"Low"}},
"26":{
"Length":3,"Format":"NumericLE","SubFormat":"Symbol","SymbolRef":{
"Label":"reach2","Part":"Low"}},
"Length":3,
"Format":"NumericLE",
"SubFormat":"Symbol",
"SymbolRef":{
"Label":"reach2",
"Part":"Low"}},
"32":{
"Length":3,"Format":"NumericLE","SubFormat":"Symbol","SymbolRef":{
"Label":"_reach4","Part":"Low"}},
"Length":3,
"Format":"NumericLE",
"SubFormat":"Symbol",
"SymbolRef":{
"Label":"_reach4",
"Part":"Low"}},
"58":{
"Length":3,"Format":"NumericLE","SubFormat":"Hex","SymbolRef":null}},
"Length":3,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null}},
"LvTables":{
},
"Visualizations":[],
"VisualizationAnimations":[],
"VisualizationSets":{
},
"RelocList":{
},
"DbrValues":{
}}

View File

@ -49,9 +49,9 @@ _L104A nop
nop
nglobal nop
globlat jsr nglobal
bra end
bra NOT
end nop
NOT nop
EXCESSIVELY_LONG_LABEL
lda REALLYLONGLABELNAME
_X_uname

View File

@ -48,9 +48,9 @@ globalnm
nop
nglobal nop
globlat jsr nglobal
bra end
bra NOT1
end nop
NOT1 nop
EXCESSIVELY_LONG_LABEL
lda REALLYLONGLABELNAME
@_uname nop

View File

@ -48,9 +48,9 @@ globalnm:
nop
nglobal: nop
globlat: jsr nglobal
bra end
bra NOT
end: nop
NOT: nop
EXCESSIVELY_LONG_LABEL:
lda REALLYLONGLABELNAME
@_uname: nop

View File

@ -44,9 +44,9 @@ globalnm jsr :L104A
nop
nglobal nop
globlat jsr nglobal
bra end
bra NOT
end nop
NOT nop
EXCESSIVELY_LONG_LABEL
lda REALLYLONGLABELNAME
:_uname nop