mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
fix codegen for rol/ror on pointer indexed
This commit is contained in:
parent
3054a1d32d
commit
d56eb397f9
@ -657,7 +657,13 @@ internal class BuiltinFunctionsAsmGen(private val program: Program,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun translateRolRorArrayArgs(arrayvar: IdentifierReference, indexer: ArrayIndex, operation: String, dt: Char) {
|
private fun translateRolRorArrayArgs(arrayvar: IdentifierReference, indexer: ArrayIndex, operation: String, dt: Char) {
|
||||||
asmgen.assignExpressionToVariable(AddressOf(arrayvar, arrayvar.position), "prog8_lib.${operation}_array_u${dt}._arg_target", DataType.UWORD, null)
|
if(arrayvar.targetVarDecl(program)!!.datatype==DataType.UWORD) {
|
||||||
|
if(dt!='b')
|
||||||
|
throw AssemblyError("non-array var indexing requires bytes dt")
|
||||||
|
asmgen.assignExpressionToVariable(arrayvar, "prog8_lib.${operation}_array_u${dt}._arg_target", DataType.UWORD, null)
|
||||||
|
} else {
|
||||||
|
asmgen.assignExpressionToVariable(AddressOf(arrayvar, arrayvar.position), "prog8_lib.${operation}_array_u${dt}._arg_target", DataType.UWORD, null)
|
||||||
|
}
|
||||||
asmgen.assignExpressionToVariable(indexer.indexExpr, "prog8_lib.${operation}_array_u${dt}._arg_index", DataType.UBYTE, null)
|
asmgen.assignExpressionToVariable(indexer.indexExpr, "prog8_lib.${operation}_array_u${dt}._arg_index", DataType.UBYTE, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,29 +35,17 @@ internal class AstOnetimeTransforms(private val program: Program, private val op
|
|||||||
private fun replacePointerVarIndexWithMemreadOrMemwrite(arrayIndexedExpression: ArrayIndexedExpression, parent: Node): Iterable<IAstModification> {
|
private fun replacePointerVarIndexWithMemreadOrMemwrite(arrayIndexedExpression: ArrayIndexedExpression, parent: Node): Iterable<IAstModification> {
|
||||||
val arrayVar = arrayIndexedExpression.arrayvar.targetVarDecl(program)
|
val arrayVar = arrayIndexedExpression.arrayvar.targetVarDecl(program)
|
||||||
if(arrayVar!=null && arrayVar.datatype == DataType.UWORD) {
|
if(arrayVar!=null && arrayVar.datatype == DataType.UWORD) {
|
||||||
// rewrite pointervar[index] into @(pointervar+index)
|
|
||||||
val indexer = arrayIndexedExpression.indexer
|
|
||||||
val add: Expression =
|
|
||||||
if(indexer.indexExpr.constValue(program)?.number==0.0)
|
|
||||||
arrayIndexedExpression.arrayvar.copy()
|
|
||||||
else
|
|
||||||
BinaryExpression(arrayIndexedExpression.arrayvar.copy(), "+", indexer.indexExpr, arrayIndexedExpression.position)
|
|
||||||
if(parent is AssignTarget) {
|
if(parent is AssignTarget) {
|
||||||
// we're part of the target of an assignment, we have to actually change the assign target itself
|
// rewrite assignment target pointervar[index] into @(pointervar+index)
|
||||||
|
val indexer = arrayIndexedExpression.indexer
|
||||||
|
val add: Expression =
|
||||||
|
if(indexer.indexExpr.constValue(program)?.number==0.0)
|
||||||
|
arrayIndexedExpression.arrayvar.copy()
|
||||||
|
else
|
||||||
|
BinaryExpression(arrayIndexedExpression.arrayvar.copy(), "+", indexer.indexExpr, arrayIndexedExpression.position)
|
||||||
val memwrite = DirectMemoryWrite(add, arrayIndexedExpression.position)
|
val memwrite = DirectMemoryWrite(add, arrayIndexedExpression.position)
|
||||||
val newtarget = AssignTarget(null, null, memwrite, arrayIndexedExpression.position)
|
val newtarget = AssignTarget(null, null, memwrite, arrayIndexedExpression.position)
|
||||||
return listOf(IAstModification.ReplaceNode(parent, newtarget, parent.parent))
|
return listOf(IAstModification.ReplaceNode(parent, newtarget, parent.parent))
|
||||||
} else {
|
|
||||||
val fcall = parent as? IFunctionCall
|
|
||||||
if(fcall!=null) {
|
|
||||||
// TODO currently, 6502 codegen is wrong when using pointer indexed args to an in-place modifying function.
|
|
||||||
if(options.compTarget.name!=VMTarget.NAME
|
|
||||||
&& fcall.target.nameInSource.size==1
|
|
||||||
&& fcall.target.nameInSource[0] in InplaceModifyingBuiltinFunctions) {
|
|
||||||
val memread = DirectMemoryRead(add, arrayIndexedExpression.position)
|
|
||||||
return listOf(IAstModification.ReplaceNode(arrayIndexedExpression, memread, parent))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@ TODO
|
|||||||
|
|
||||||
For next release
|
For next release
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^
|
||||||
- optimize pointervar indexing codegen: fix 6502 codegen for params to in-place modifying functions (rol, ror, ...)
|
- vm: fix optimized pointervar indexing codegen when it is an assignment target (i.e. writing to ptr[ix])
|
||||||
- optimize pointervar indexing codegen: writing (all sorts of things)
|
- 6502: fix optimized pointervar indexing codegen when it is an assignment target (i.e. writing to ptr[ix])
|
||||||
- pipe operator: (targets other than 'Virtual'): allow non-unary function calls in the pipe that specify the other argument(s) in the calls. Already working for VM target.
|
- pipe operator: (targets other than 'Virtual'): allow non-unary function calls in the pipe that specify the other argument(s) in the calls. Already working for VM target.
|
||||||
- add McCarthy evaluation to shortcircuit and/or expressions. First do ifs by splitting them up? Then do expressions that compute a value?
|
- add McCarthy evaluation to shortcircuit and/or expressions. First do ifs by splitting them up? Then do expressions that compute a value?
|
||||||
- Inliner: also inline function call expressions, and remove it from the StatementOptimizer
|
- Inliner: also inline function call expressions, and remove it from the StatementOptimizer
|
||||||
|
Loading…
Reference in New Issue
Block a user