1
0
mirror of https://github.com/fadden/6502bench.git synced 2025-01-08 12:30:36 +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.) // between global labels. (This is poorly documented.)
mLocalizer.LocalPrefix = "@"; mLocalizer.LocalPrefix = "@";
mLocalizer.QuirkNoOpcodeMnemonics = true; mLocalizer.QuirkNoOpcodeMnemonics = true;
mLocalizer.ReservedWords = new List<string>() { "NOT" };
mLocalizer.Analyze(); mLocalizer.Analyze();
mPcDepth = 0; mPcDepth = 0;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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