mirror of
https://github.com/irmen/prog8.git
synced 2025-02-19 11:31:07 +00:00
1-letter symbols now also prefixed with 'p8p_'
to avoid assembly errors caused by confusing variable 'a' with register 'a' etc.
This commit is contained in:
parent
30c531b39e
commit
c0cb2438d5
@ -15,33 +15,33 @@ class AsmInstructionNamesFinder(val target: ICompilationTarget): IAstVisitor {
|
|||||||
val labels = mutableSetOf<Label>()
|
val labels = mutableSetOf<Label>()
|
||||||
val subroutines = mutableSetOf<Subroutine>()
|
val subroutines = mutableSetOf<Subroutine>()
|
||||||
|
|
||||||
private fun isPossibleInstructionName(name: String) = name.length==3 && name.all { it.isLetter() }
|
private fun isPossibleConfusingAsmName(name: String) = (name.length==3 || name.length==1) && name.all { it.isLetter() }
|
||||||
|
|
||||||
fun foundAny(): Boolean = blocks.isNotEmpty() || variables.isNotEmpty() || subroutines.isNotEmpty() || labels.isNotEmpty()
|
fun foundAny(): Boolean = blocks.isNotEmpty() || variables.isNotEmpty() || subroutines.isNotEmpty() || labels.isNotEmpty()
|
||||||
|
|
||||||
override fun visit(block: Block) {
|
override fun visit(block: Block) {
|
||||||
if(target.name!=VMTarget.NAME && !block.isInLibrary && isPossibleInstructionName(block.name)) {
|
if(target.name!=VMTarget.NAME && !block.isInLibrary && isPossibleConfusingAsmName(block.name)) {
|
||||||
blocks += block
|
blocks += block
|
||||||
}
|
}
|
||||||
super.visit(block)
|
super.visit(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visit(decl: VarDecl) {
|
override fun visit(decl: VarDecl) {
|
||||||
if(target.name!=VMTarget.NAME && !decl.definingModule.isLibrary && isPossibleInstructionName(decl.name)) {
|
if(target.name!=VMTarget.NAME && !decl.definingModule.isLibrary && isPossibleConfusingAsmName(decl.name)) {
|
||||||
variables += decl
|
variables += decl
|
||||||
}
|
}
|
||||||
super.visit(decl)
|
super.visit(decl)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visit(label: Label) {
|
override fun visit(label: Label) {
|
||||||
if(target.name!=VMTarget.NAME && !label.definingModule.isLibrary && isPossibleInstructionName(label.name)) {
|
if(target.name!=VMTarget.NAME && !label.definingModule.isLibrary && isPossibleConfusingAsmName(label.name)) {
|
||||||
labels += label
|
labels += label
|
||||||
}
|
}
|
||||||
super.visit(label)
|
super.visit(label)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visit(subroutine: Subroutine) {
|
override fun visit(subroutine: Subroutine) {
|
||||||
if(target.name!=VMTarget.NAME && !subroutine.definingModule.isLibrary && isPossibleInstructionName(subroutine.name)) {
|
if(target.name!=VMTarget.NAME && !subroutine.definingModule.isLibrary && isPossibleConfusingAsmName(subroutine.name)) {
|
||||||
subroutines += subroutine
|
subroutines += subroutine
|
||||||
}
|
}
|
||||||
super.visit(subroutine)
|
super.visit(subroutine)
|
||||||
|
@ -22,7 +22,7 @@ class AsmInstructionNamesReplacer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val newName = identifier.nameInSource.map { ident ->
|
val newName = identifier.nameInSource.map { ident ->
|
||||||
if(ident.length==3 && !identifier.definingModule.isLibrary) {
|
if((ident.length==3 || ident.length==1) && !identifier.definingModule.isLibrary) {
|
||||||
val blockTarget = blocks.firstOrNull { it.name==ident }
|
val blockTarget = blocks.firstOrNull { it.name==ident }
|
||||||
val subTarget = subroutines.firstOrNull {it.name==ident }
|
val subTarget = subroutines.firstOrNull {it.name==ident }
|
||||||
val varTarget = variables.firstOrNull { it.name==ident }
|
val varTarget = variables.firstOrNull { it.name==ident }
|
||||||
@ -84,7 +84,7 @@ class AsmInstructionNamesReplacer(
|
|||||||
override fun after(subroutine: Subroutine, parent: Node): Iterable<IAstModification> {
|
override fun after(subroutine: Subroutine, parent: Node): Iterable<IAstModification> {
|
||||||
val changedParams = mutableListOf<Pair<Int, SubroutineParameter>>()
|
val changedParams = mutableListOf<Pair<Int, SubroutineParameter>>()
|
||||||
subroutine.parameters.withIndex().forEach { (index, param) ->
|
subroutine.parameters.withIndex().forEach { (index, param) ->
|
||||||
if(param.name.length==3 && param.name.all { it.isLetter() } && !param.definingModule.isLibrary) {
|
if((param.name.length==3 || param.name.length==1) && param.name.all { it.isLetter() } && !param.definingModule.isLibrary) {
|
||||||
changedParams.add(index to SubroutineParameter("p8p_${param.name}", param.type, param.position))
|
changedParams.add(index to SubroutineParameter("p8p_${param.name}", param.type, param.position))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,14 +27,15 @@ so that more system ram is available for the program code itself.
|
|||||||
Three-letter symbols prefixing in Assembly
|
Three-letter symbols prefixing in Assembly
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
|
|
||||||
Symbols consisting of three letters such as "brk" or "tax" will confuse the assembler that
|
Symbols consisting of three letters such as "brk" or "tax", or variables named "a", "x" or "y" could
|
||||||
thinks these are cpu instructions. It will likely fail to assemble the program correctly.
|
confuse the assembler to think these are cpu instructions or registers.
|
||||||
Because of this, prog8 will prefix every 3-letter symbol with "``p8p_``" automatically during compilation.
|
It will likely fail to assemble the program correctly.
|
||||||
So "tax" will become "p8p_tax" in the resulting assembly code.
|
Because of this, prog8 will prefix every 1- and 3-letter symbol with "``p8p_``" automatically during compilation.
|
||||||
|
So "tax" will become "p8p_tax", "a" will become "p8p_a" in the resulting assembly code.
|
||||||
|
|
||||||
If you're referencing symbols from the prog8 program in hand-written assembly code, you have to take
|
If you're referencing symbols from the prog8 program in hand-written assembly code, you have to take
|
||||||
this into account. Either prefix the 3-letter symbols in the assembly with "``p8p_``" as well, or just
|
this into account. Either prefix the 1- and 3-letter symbols in the assembly with "``p8p_``" as well, or just
|
||||||
choose a shorter or longer symbol name in the first place.
|
choose a symbol name of a different length in the first place.
|
||||||
|
|
||||||
|
|
||||||
Software stack for expression evaluation
|
Software stack for expression evaluation
|
||||||
|
@ -4,6 +4,10 @@ TODO
|
|||||||
- fix array expression assignment bug from Mark in the discord. ("TODO fix temp var name")
|
- fix array expression assignment bug from Mark in the discord. ("TODO fix temp var name")
|
||||||
- fix double code gen with tryInplaceModifyWithRemovedRedundantCast() ? word birdX[j] += testbyte
|
- fix double code gen with tryInplaceModifyWithRemovedRedundantCast() ? word birdX[j] += testbyte
|
||||||
|
|
||||||
|
- prog8->asm symbol name prefixing: prefix ALL symbols with p8_ Also update manual.
|
||||||
|
EXCEPTION: library symbols such as cbm.CHROUT, cx16.r0 etc. should NOT be prefixed.
|
||||||
|
Solution: add %option no_symbol_prefix to those blocks?
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user