mirror of
https://github.com/irmen/prog8.git
synced 2024-09-07 19:54:26 +00:00
fix possible vardecl issue for prefixed params
This commit is contained in:
parent
f470576822
commit
add3491c57
@ -55,23 +55,47 @@ class AsmInstructionNamesReplacer(
|
|||||||
noModifications
|
noModifications
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val subsWithParamRefsToFix = mutableListOf<Subroutine>()
|
||||||
|
|
||||||
|
override fun applyModifications(): Int {
|
||||||
|
var count = super.applyModifications()
|
||||||
|
subsWithParamRefsToFix.forEach { subroutine ->
|
||||||
|
subroutine.statements.withIndex().reversed().forEach { (index,stmt) ->
|
||||||
|
if(stmt is VarDecl && stmt.origin==VarDeclOrigin.SUBROUTINEPARAM) {
|
||||||
|
val param = subroutine.parameters.single { it.name == stmt.name}
|
||||||
|
val decl = VarDecl.fromParameter(param)
|
||||||
|
subroutine.statements[index] = decl
|
||||||
|
decl.linkParents(subroutine)
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
override fun after(subroutine: Subroutine, parent: Node): Iterable<IAstModification> {
|
override fun after(subroutine: Subroutine, parent: Node): Iterable<IAstModification> {
|
||||||
val parameters = subroutine.parameters.map {
|
val changedParams = mutableListOf<Pair<Int, SubroutineParameter>>()
|
||||||
if(it.name.length==3 && it.name.all { it.isLetter() } && !it.definingModule.isLibrary)
|
subroutine.parameters.withIndex().forEach { (index, param) ->
|
||||||
SubroutineParameter("p8p_${it.name}", it.type, it.position) else it
|
if(param.name.length==3 && param.name.all { it.isLetter() } && !param.definingModule.isLibrary) {
|
||||||
|
changedParams.add(index to SubroutineParameter("p8p_${param.name}", param.type, param.position))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO for all decls in the subroutine, update their subroutineParameter if something changed
|
changedParams.forEach { (index, newParam) -> subroutine.parameters[index] = newParam }
|
||||||
|
|
||||||
val newName = if(subroutine in subroutines) "p8p_${subroutine.name}" else subroutine.name
|
val newName = if(subroutine in subroutines) "p8p_${subroutine.name}" else subroutine.name
|
||||||
|
|
||||||
return if(newName!=subroutine.name || parameters.map{ it.name} != subroutine.parameters.map {it.name})
|
return if(newName!=subroutine.name || changedParams.isNotEmpty()) {
|
||||||
listOf(IAstModification.ReplaceNode(subroutine,
|
val newSub = Subroutine(newName, subroutine.parameters, subroutine.returntypes,
|
||||||
Subroutine(newName, parameters.toMutableList(), subroutine.returntypes,
|
subroutine.asmParameterRegisters, subroutine.asmReturnvaluesRegisters, subroutine.asmClobbers, subroutine.asmAddress, subroutine.isAsmSubroutine,
|
||||||
subroutine.asmParameterRegisters, subroutine.asmReturnvaluesRegisters, subroutine.asmClobbers, subroutine.asmAddress, subroutine.isAsmSubroutine,
|
subroutine.inline, subroutine.statements, subroutine.position)
|
||||||
subroutine.inline, subroutine.statements, subroutine.position), parent))
|
if(changedParams.isNotEmpty())
|
||||||
else
|
subsWithParamRefsToFix += newSub
|
||||||
|
listOf(IAstModification.ReplaceNode(subroutine, newSub, parent))
|
||||||
|
} else {
|
||||||
|
if(changedParams.isNotEmpty())
|
||||||
|
subsWithParamRefsToFix += subroutine
|
||||||
noModifications
|
noModifications
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -314,9 +314,7 @@ internal class StatementReorderer(val program: Program,
|
|||||||
AddressOf(sourceIdent, assign.position),
|
AddressOf(sourceIdent, assign.position),
|
||||||
AddressOf(identifier, assign.position),
|
AddressOf(identifier, assign.position),
|
||||||
NumericLiteral.optimalInteger(numelements*eltsize, assign.position)
|
NumericLiteral.optimalInteger(numelements*eltsize, assign.position)
|
||||||
),
|
), false, assign.position
|
||||||
true,
|
|
||||||
assign.position
|
|
||||||
)
|
)
|
||||||
return listOf(IAstModification.ReplaceNode(assign, memcopy, assign.parent))
|
return listOf(IAstModification.ReplaceNode(assign, memcopy, assign.parent))
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ abstract class AstWalker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun applyModifications(): Int {
|
open fun applyModifications(): Int {
|
||||||
// check if there are double removes, keep only the last one
|
// check if there are double removes, keep only the last one
|
||||||
val removals = modifications.filter { it.first is IAstModification.Remove }
|
val removals = modifications.filter { it.first is IAstModification.Remove }
|
||||||
if(removals.isNotEmpty()) {
|
if(removals.isNotEmpty()) {
|
||||||
|
@ -3,9 +3,7 @@ TODO
|
|||||||
|
|
||||||
For next release
|
For next release
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^
|
||||||
- AsmInstructionNamesReplacer: fix the TODO about the params
|
- regression test the various projects before release
|
||||||
- create BSS section in output program and put StStaticVariables in there with bss=true. Don't forget to add init code to zero out everything that was put in bss. If array in bss->only zero ONCE! So requires self-modifying code
|
|
||||||
- regression test the various projects
|
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
@ -21,6 +19,7 @@ Future Things and Ideas
|
|||||||
^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
Compiler:
|
Compiler:
|
||||||
|
|
||||||
|
- create BSS section in output program and put StStaticVariables in there with bss=true. Don't forget to add init code to zero out everything that was put in bss. If array in bss->only zero ONCE! So requires self-modifying code
|
||||||
- add a mechanism to allocate variables into golden ram (see MachineDefinition.GOLDEN)
|
- add a mechanism to allocate variables into golden ram (see MachineDefinition.GOLDEN)
|
||||||
- ir: mechanism to determine for chunks which registers are getting input values from "outside"
|
- ir: mechanism to determine for chunks which registers are getting input values from "outside"
|
||||||
- ir: mechanism to determine for chunks which registers are passing values out? (i.e. are used again in another chunk)
|
- ir: mechanism to determine for chunks which registers are passing values out? (i.e. are used again in another chunk)
|
||||||
|
Loading…
Reference in New Issue
Block a user