mirror of
https://github.com/irmen/prog8.git
synced 2026-03-13 20:16:46 +00:00
optimize msb(lsw(longvar)) into @(&longvar+1)
This commit is contained in:
@@ -616,7 +616,7 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr
|
||||
return listOf(IAstModification.ReplaceNode(functionCallExpr, cast, parent))
|
||||
}
|
||||
} else if(arg is FunctionCallExpression && arg.target.nameInSource == listOf("msw")) {
|
||||
// lsb(msb(longvar)) --> @(&longvar+2) ; get the bank byte from a long variable
|
||||
// lsb(msw(longvar)) --> @(&longvar+2) ; get the bank byte from a long variable
|
||||
val longvar = arg.args[0] as? IdentifierReference
|
||||
if(longvar!=null && longvar.inferType(program).isLong) {
|
||||
val address = AddressOf(longvar, null, null, false, false, functionCallExpr.position)
|
||||
@@ -656,6 +656,15 @@ class ExpressionSimplifier(private val program: Program, private val errors: IEr
|
||||
NumericLiteral(valueDt.getOr(DataType.UBYTE).base, 0.0, arg.expression.position),
|
||||
parent))
|
||||
}
|
||||
} else if(arg is FunctionCallExpression && arg.target.nameInSource == listOf("lsw")) {
|
||||
// msb(lsw(longvar)) --> @(&longvar+1) ; get the second byte from a long variable
|
||||
val longvar = arg.args[0] as? IdentifierReference
|
||||
if(longvar!=null && longvar.inferType(program).isLong) {
|
||||
val address = AddressOf(longvar, null, null, false, false, functionCallExpr.position)
|
||||
val plus2 = BinaryExpression(address, "+", NumericLiteral(BaseDataType.UWORD, 1.0, functionCallExpr.position), functionCallExpr.position)
|
||||
val memread = DirectMemoryRead(plus2, functionCallExpr.position)
|
||||
return listOf(IAstModification.ReplaceNode(functionCallExpr, memread, parent))
|
||||
}
|
||||
} else {
|
||||
if(arg is IdentifierReference && arg.nameInSource.size==2
|
||||
&& arg.nameInSource[0]=="cx16" && arg.nameInSource[1].uppercase() in RegisterOrPair.names) {
|
||||
|
||||
Reference in New Issue
Block a user